From f09cb2a5feeb3c2d303a6257c2fd886b9a65a0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20von=20Haller?= Date: Tue, 15 Apr 2025 15:44:40 +0200 Subject: [PATCH 1/3] Update ubuntu for clang-format --- .github/workflows/format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 6e92c7bb97..6f1db2cae6 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -5,7 +5,7 @@ on: [pull_request] jobs: clang-format: # We need at least 20.04 to install clang-format-11. - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 with: From b19417e2e29505b8c0af92eb3b13cb39f6fb1a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20von=20Haller?= Date: Tue, 15 Apr 2025 15:47:12 +0200 Subject: [PATCH 2/3] Update format.yml --- .github/workflows/format.yml | 46 +++++++----------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 6f1db2cae6..9d19009838 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -1,41 +1,11 @@ -name: Clang format +--- +name: Formatting -on: [pull_request] +'on': [pull_request_target] jobs: - clang-format: - # We need at least 20.04 to install clang-format-11. - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - # To get the merge base, we need the full history. - fetch-depth: 0 - - name: Install prerequisites - env: - DEBIAN_FRONTEND: noninteractive - run: | - sudo apt update -y - sudo apt install -y clang-format-11 - sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100 - sudo update-alternatives --install /usr/bin/git-clang-format git-clang-format /usr/bin/git-clang-format-11 100 - - name: Run clang-format on changed files - run: | - set -x - git fetch origin ${{ github.event.pull_request.base.ref }} - git fetch origin pull/${{ github.event.pull_request.number }}/head:${{ github.event.pull_request.head.ref }} - BASE_COMMIT=$(git merge-base HEAD ${{ github.event.pull_request.base.sha }}) - COMMIT_FILES=$(git diff --diff-filter=d --name-only "$BASE_COMMIT" -- '*.cxx' '*.h' ':!*LinkDef*') - if [ "$COMMIT_FILES" == "" ]; then - exit 0 ;# nothing to check - fi - - RESULT_OUTPUT=$(git-clang-format --commit ${BASE_COMMIT} --diff ${COMMIT_FILES}) - if [ "$RESULT_OUTPUT" == "no modified files to format" ] || [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ]; then - exit 0 ;# all good - else - git-clang-format --commit $BASE_COMMIT --diff - echo "$RESULT_OUTPUT" - exit 1 - fi + formatting: + name: PR formatting + uses: alisw/ali-bot/.github/workflows/c++-code-formatting.yml@master + secrets: + alibuild_github_token: ${{ secrets.ALIBUILD_GITHUB_TOKEN }} From 3391472e81c261a922056be5f0d3c1d4f63fac07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20von=20Haller?= Date: Tue, 15 Apr 2025 15:50:03 +0200 Subject: [PATCH 3/3] Update format.yml --- .github/workflows/format.yml | 47 ++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 9d19009838..2d13710723 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -1,11 +1,42 @@ ---- -name: Formatting +name: Clang format -'on': [pull_request_target] +on: [pull_request] jobs: - formatting: - name: PR formatting - uses: alisw/ali-bot/.github/workflows/c++-code-formatting.yml@master - secrets: - alibuild_github_token: ${{ secrets.ALIBUILD_GITHUB_TOKEN }} + clang-format: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + # To get the merge base, we need the full history. + fetch-depth: 0 + - name: Install prerequisites + env: + DEBIAN_FRONTEND: noninteractive + run: | + sudo apt update + sudo apt install -y clang-format-18 + sudo update-alternatives --install /usr/bin/clang-format \ + clang-format /usr/bin/clang-format-18 100 + sudo update-alternatives --install /usr/bin/git-clang-format \ + git-clang-format /usr/bin/git-clang-format-18 100 + - name: Run clang-format on changed files + run: | + set -x + git fetch origin ${{ github.event.pull_request.base.ref }} + git fetch origin pull/${{ github.event.pull_request.number }}/head:${{ github.event.pull_request.head.ref }} + BASE_COMMIT=$(git merge-base HEAD ${{ github.event.pull_request.base.sha }}) + COMMIT_FILES=$(git diff --diff-filter=d --name-only "$BASE_COMMIT" -- '*.cxx' '*.h' ':!*LinkDef*') + if [ "$COMMIT_FILES" == "" ]; then + exit 0 ;# nothing to check + fi + + RESULT_OUTPUT=$(git-clang-format --commit ${BASE_COMMIT} --diff ${COMMIT_FILES}) + if [ "$RESULT_OUTPUT" == "no modified files to format" ] || [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ]; then + exit 0 ;# all good + else + git-clang-format --commit $BASE_COMMIT --diff + echo "$RESULT_OUTPUT" + exit 1 + fi