From d5e2aa0b579f74a73ce0d1430d67f4099a803158 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Wed, 23 Jun 2021 21:16:48 +0200 Subject: [PATCH 01/12] add clang-format job --- .github/workflows/code_analysis.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/code_analysis.yml diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml new file mode 100644 index 0000000000000..7adf996e83898 --- /dev/null +++ b/.github/workflows/code_analysis.yml @@ -0,0 +1,18 @@ +name: clang-tools code analysis + +on: + # push: + # branches: [ $default-branch ] + pull_request: + branches: [ $default-branch ] + +jobs: + clang-format: + runs-on: ubuntu-latest + env: + TRAVIS_BRANCH: ${{ github.base_ref }} + TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }} + steps: + - uses: actions/checkout@v2 + - name: run clang-format script + run: .ci/format_script.sh From 303f586e79b2dc20bfcc0380b32d5a0cd3328496 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Wed, 23 Jun 2021 21:23:15 +0200 Subject: [PATCH 02/12] trigger on pull_request without branch specified --- .github/workflows/code_analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 7adf996e83898..359dde110a43f 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -1,10 +1,10 @@ name: clang-tools code analysis -on: +on: pull_request # push: # branches: [ $default-branch ] - pull_request: - branches: [ $default-branch ] + # pull_request: + # branches: [ $default-branch ] jobs: clang-format: From 3f604f618c77d57216c9d13322a66910081e607f Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Wed, 23 Jun 2021 21:44:50 +0200 Subject: [PATCH 03/12] fetch all history and tags so we can compare for clang-format --- .github/workflows/code_analysis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 359dde110a43f..966c87962b4e7 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -14,5 +14,7 @@ jobs: TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }} steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: run clang-format script run: .ci/format_script.sh From 8bcd2c1a3332e7e5364435f0014bbe16c3c01196 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Wed, 23 Jun 2021 21:51:25 +0200 Subject: [PATCH 04/12] try to separately pull in master --- .github/workflows/code_analysis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 966c87962b4e7..d7b93067fda69 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -14,7 +14,7 @@ jobs: TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }} steps: - uses: actions/checkout@v2 - with: - fetch-depth: 0 + - name: also pull base branch + run: git pull origin $TRAVIS_BRANCH - name: run clang-format script run: .ci/format_script.sh From 036272ebb3f86d90675b077411f186d0c0f6f127 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Wed, 23 Jun 2021 21:54:56 +0200 Subject: [PATCH 05/12] change to fetch --- .github/workflows/code_analysis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index d7b93067fda69..d7662bad61362 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -14,7 +14,7 @@ jobs: TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }} steps: - uses: actions/checkout@v2 - - name: also pull base branch - run: git pull origin $TRAVIS_BRANCH + - name: fetch base branch + run: git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin $TRAVIS_BRANCH - name: run clang-format script run: .ci/format_script.sh From 8221f2f27fac25f8c4ea979c5c16a7e8f00148c0 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Thu, 24 Jun 2021 13:29:52 +0200 Subject: [PATCH 06/12] pass in BASE_COMMIT using a github actions variable --- .ci/format_script.sh | 2 +- .github/workflows/code_analysis.yml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.ci/format_script.sh b/.ci/format_script.sh index 6bb51fa51291c..cca8627b89d46 100755 --- a/.ci/format_script.sh +++ b/.ci/format_script.sh @@ -2,7 +2,7 @@ set -ex -BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH) +# BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH) echo "Running clang-format against branch $TRAVIS_BRANCH, with hash $BASE_COMMIT" COMMIT_FILES=$(git diff --name-only $BASE_COMMIT | grep -i -v LinkDef) RESULT_OUTPUT="$(git-clang-format --commit $BASE_COMMIT --diff --binary `which clang-format` $COMMIT_FILES)" diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index d7662bad61362..acadc419df7ab 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -12,9 +12,8 @@ jobs: env: TRAVIS_BRANCH: ${{ github.base_ref }} TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }} + BASE_COMMIT: ${{ github.event.pull_request.head.sha }} steps: - uses: actions/checkout@v2 - - name: fetch base branch - run: git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin $TRAVIS_BRANCH - name: run clang-format script run: .ci/format_script.sh From c0f2291c02411231d5bfdb3513e0f51cce6e8c38 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Thu, 24 Jun 2021 13:32:42 +0200 Subject: [PATCH 07/12] actually point to base SHA instead of head SHA --- .github/workflows/code_analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index acadc419df7ab..47e875fe44dae 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -12,7 +12,7 @@ jobs: env: TRAVIS_BRANCH: ${{ github.base_ref }} TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }} - BASE_COMMIT: ${{ github.event.pull_request.head.sha }} + BASE_COMMIT: ${{ github.event.pull_request.base.sha }} steps: - uses: actions/checkout@v2 - name: run clang-format script From 170826ec168fb9b856abe9c18822797cc8056d04 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Thu, 24 Jun 2021 13:42:35 +0200 Subject: [PATCH 08/12] fetch base ref Uses example in as of yet unmerged PR https://github.com/actions/checkout/pull/213 --- .github/workflows/code_analysis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 47e875fe44dae..9fb2671981cd5 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -15,5 +15,7 @@ jobs: BASE_COMMIT: ${{ github.event.pull_request.base.sha }} steps: - uses: actions/checkout@v2 + - name: Fetch base_ref HEAD + run: git fetch --depth=1 origin +refs/heads/${{github.base_ref}}:refs/remotes/origin/${{github.base_ref}} - name: run clang-format script run: .ci/format_script.sh From bd2d0729f1c9d3e785fa6e893318fe953d6ebbad Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Thu, 24 Jun 2021 13:51:51 +0200 Subject: [PATCH 09/12] install clang tools to also get git-clang-format --- .github/workflows/code_analysis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 9fb2671981cd5..18a96006824aa 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -17,5 +17,7 @@ jobs: - uses: actions/checkout@v2 - name: Fetch base_ref HEAD run: git fetch --depth=1 origin +refs/heads/${{github.base_ref}}:refs/remotes/origin/${{github.base_ref}} + - name: install clang-tools + run: sudo apt-get install -y clang-tools - name: run clang-format script run: .ci/format_script.sh From 88fd75139401ec7804b66ae990e44db3eb1f3420 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Thu, 24 Jun 2021 13:56:13 +0200 Subject: [PATCH 10/12] install clang-format instead I thought clang-tools would include clang-format, but apparently not. --- .github/workflows/code_analysis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 18a96006824aa..4b36e6597d9c4 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v2 - name: Fetch base_ref HEAD run: git fetch --depth=1 origin +refs/heads/${{github.base_ref}}:refs/remotes/origin/${{github.base_ref}} - - name: install clang-tools - run: sudo apt-get install -y clang-tools + - name: install clang-format + run: sudo apt-get install -y clang-format - name: run clang-format script run: .ci/format_script.sh From d424b5d60220b8356568e1a4c8237df7ce82e433 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Thu, 24 Jun 2021 14:01:07 +0200 Subject: [PATCH 11/12] revert format_script.sh change Now that we correctly fetch the base_ref, we can put the format_script back into Travis-compatible state. --- .ci/format_script.sh | 2 +- .github/workflows/code_analysis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci/format_script.sh b/.ci/format_script.sh index cca8627b89d46..6bb51fa51291c 100755 --- a/.ci/format_script.sh +++ b/.ci/format_script.sh @@ -2,7 +2,7 @@ set -ex -# BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH) +BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH) echo "Running clang-format against branch $TRAVIS_BRANCH, with hash $BASE_COMMIT" COMMIT_FILES=$(git diff --name-only $BASE_COMMIT | grep -i -v LinkDef) RESULT_OUTPUT="$(git-clang-format --commit $BASE_COMMIT --diff --binary `which clang-format` $COMMIT_FILES)" diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 4b36e6597d9c4..03a4907b26194 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -12,7 +12,7 @@ jobs: env: TRAVIS_BRANCH: ${{ github.base_ref }} TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }} - BASE_COMMIT: ${{ github.event.pull_request.base.sha }} + # BASE_COMMIT: ${{ github.event.pull_request.base.sha }} steps: - uses: actions/checkout@v2 - name: Fetch base_ref HEAD From f4dcfe1dbcae777776855e051e3c850cf8d70b6f Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Thu, 24 Jun 2021 14:06:13 +0200 Subject: [PATCH 12/12] pass BASE_COMMIT to format_script.sh It is not possible to use the base branch name in the GitHub Actions workflow to get the base SHA hash, because the branch name is not known there. To keep the format_script.sh universal, we just pass the SHA hash in from both the Travis and the GH Actions configurations instead. --- .ci/format_script.sh | 1 - .github/workflows/code_analysis.yml | 2 +- .travis.yml | 6 +++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.ci/format_script.sh b/.ci/format_script.sh index 6bb51fa51291c..67503dd8710de 100755 --- a/.ci/format_script.sh +++ b/.ci/format_script.sh @@ -2,7 +2,6 @@ set -ex -BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH) echo "Running clang-format against branch $TRAVIS_BRANCH, with hash $BASE_COMMIT" COMMIT_FILES=$(git diff --name-only $BASE_COMMIT | grep -i -v LinkDef) RESULT_OUTPUT="$(git-clang-format --commit $BASE_COMMIT --diff --binary `which clang-format` $COMMIT_FILES)" diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 03a4907b26194..4b36e6597d9c4 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -12,7 +12,7 @@ jobs: env: TRAVIS_BRANCH: ${{ github.base_ref }} TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }} - # BASE_COMMIT: ${{ github.event.pull_request.base.sha }} + BASE_COMMIT: ${{ github.event.pull_request.base.sha }} steps: - uses: actions/checkout@v2 - name: Fetch base_ref HEAD diff --git a/.travis.yml b/.travis.yml index 8041119e0bef9..180f5304daec9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,11 @@ matrix: include: - env: TOOL=clang-format script: &format_script - - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then .ci/format_script.sh; fi + - | + if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then + export BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH) + .ci/format_script.sh + fi - env: TOOL=clang-tidy-analyzer before_script: ©_headers