From a2c14446b0a87db79e2ee313d54d0bff6bbf9311 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Feb 2026 12:10:51 +0000 Subject: [PATCH] ci: merge clang-format into pr-test workflow with explicit ordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Combine clang-format.yaml into pr-test.yml so that formatting is enforced before tests run. Job dependency chain: format → changes → test. - format job always runs first (clang-format, auto-commits fixes) - changes job runs after format (if: always(), so tests aren't blocked by format failures) - test job runs after both, only when cpp/test files are changed Also aligns trigger to the pr-test branch filter (dev, main, release/**) and sets permissions per-job (contents: write for format, pull-requests: read for changes). https://claude.ai/code/session_011YTedovZwqggmR5K6yoZ8Q --- .github/workflows/clang-format.yaml | 58 ---------------------------- .github/workflows/pr-test.yml | 60 +++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/clang-format.yaml diff --git a/.github/workflows/clang-format.yaml b/.github/workflows/clang-format.yaml deleted file mode 100644 index 9cc7b76..0000000 --- a/.github/workflows/clang-format.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: clang-format - -on: - pull_request: - types: [opened, synchronize, reopened] - -permissions: - contents: write - -jobs: - format: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - token: ${{ secrets.GITHUB_TOKEN }} - fetch-depth: 0 - - - name: Install clang-format - run: | - sudo apt-get update - sudo apt-get install -y clang-format - - - name: Get changed files - id: changed-files - run: | - # Get the list of changed C/C++ files in the PR - git fetch origin ${{ github.base_ref }} - CHANGED_FILES=$(git diff --name-only --diff-filter=ACM origin/${{ github.base_ref }}...HEAD | grep -E '\.(cpp|hpp|h|c|cc|cxx)$' || true) - echo "files<> $GITHUB_OUTPUT - echo "$CHANGED_FILES" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - name: Run clang-format - if: steps.changed-files.outputs.files != '' - run: | - FILES="${{ steps.changed-files.outputs.files }}" - if [ -n "$FILES" ]; then - echo "Formatting files:" - echo "$FILES" - echo "$FILES" | xargs -r clang-format -i --style=file --fallback-style=LLVM - fi - - - name: Commit formatted changes - run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - - if git diff --quiet; then - echo "No formatting changes needed" - else - git add -A - git commit -m "refactor: Apply clang-format to PR files [skip ci]" - git push - fi diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index e7d5b5e..4e088f9 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -1,7 +1,8 @@ -name: PR Test +name: PR Checks on: pull_request: + types: [opened, synchronize, reopened] branches: - dev - main @@ -11,7 +12,60 @@ env: BUILD_TYPE: test jobs: + format: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + - name: Install clang-format + run: | + sudo apt-get update + sudo apt-get install -y clang-format + + - name: Get changed files + id: changed-files + run: | + # Get the list of changed C/C++ files in the PR + git fetch origin ${{ github.base_ref }} + CHANGED_FILES=$(git diff --name-only --diff-filter=ACM origin/${{ github.base_ref }}...HEAD | grep -E '\.(cpp|hpp|h|c|cc|cxx)$' || true) + echo "files<> $GITHUB_OUTPUT + echo "$CHANGED_FILES" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Run clang-format + if: steps.changed-files.outputs.files != '' + run: | + FILES="${{ steps.changed-files.outputs.files }}" + if [ -n "$FILES" ]; then + echo "Formatting files:" + echo "$FILES" + echo "$FILES" | xargs -r clang-format -i --style=file --fallback-style=LLVM + fi + + - name: Commit formatted changes + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + if git diff --quiet; then + echo "No formatting changes needed" + else + git add -A + git commit -m "refactor: Apply clang-format to PR files [skip ci]" + git push + fi + changes: + needs: format + if: always() runs-on: ubuntu-latest permissions: pull-requests: read @@ -38,8 +92,8 @@ jobs: - '.github/workflows/pr-test.yml' test: - needs: changes - if: needs.changes.outputs.cpp == 'true' + needs: [format, changes] + if: always() && needs.changes.outputs.cpp == 'true' strategy: fail-fast: false matrix: