Copilot checking C++ code format #1052
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Clang-Format Check | |
| run-name: "${{ github.actor }} checking C++ code format" | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| on: | |
| pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch." | |
| required: false | |
| type: string | |
| jobs: | |
| pre-check: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_act: ${{ steps.detect_act.outputs.is_act }} | |
| ref: ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.ref || github.ref)) || github.sha }} | |
| repo: ${{ github.repository }} | |
| base_sha: ${{ github.event.pull_request.base.sha || github.event.before }} | |
| steps: | |
| - name: Detect act environment | |
| id: detect_act | |
| uses: Framework-R-D/phlex/.github/actions/detect-act-env@main | |
| detect-changes: | |
| needs: pre-check | |
| if: > | |
| github.event_name != 'workflow_dispatch' && | |
| needs.pre-check.outputs.is_act != 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: read | |
| outputs: | |
| has_changes: ${{ steps.filter.outputs.matched }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| path: phlex-src | |
| ref: ${{ needs.pre-check.outputs.ref }} | |
| repository: ${{ needs.pre-check.outputs.repo }} | |
| - name: Detect relevant changes | |
| id: filter | |
| uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main | |
| with: | |
| repo-path: phlex-src | |
| base-ref: ${{ needs.pre-check.outputs.base_sha }} | |
| head-ref: ${{ needs.pre-check.outputs.ref }} | |
| file-type: cpp | |
| - name: Report detection outcome | |
| run: | | |
| if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then | |
| echo "::notice::No clang-format related changes detected; job will be skipped." | |
| else | |
| echo "::group::Clang-format relevant files" | |
| printf '%s\n' "${{ steps.filter.outputs.matched_files }}" | |
| echo "::endgroup::" | |
| fi | |
| clang-format-check: | |
| needs: [pre-check, detect-changes] | |
| if: > | |
| needs.detect-changes.result == 'skipped' || | |
| ( | |
| needs.detect-changes.result == 'success' && | |
| needs.detect-changes.outputs.has_changes == 'true' | |
| ) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ needs.pre-check.outputs.ref }} | |
| path: phlex-src | |
| repository: ${{ needs.pre-check.outputs.repo }} | |
| - name: Announce clang-format check | |
| run: echo "➡️ Running clang-format check..." | |
| - name: Run clang-format lint | |
| id: lint | |
| uses: DoozyX/clang-format-lint-action@bcb4eb2cb0d707ee4f3e5cc3b456eb075f12cf73 # v0.20 | |
| with: | |
| source: "./phlex-src" | |
| clangFormatVersion: 20 | |
| extensions: cpp,hpp,cpp.in,hpp.in | |
| continue-on-error: true | |
| - name: Evaluate clang-format result | |
| if: always() && steps.lint.outcome != 'skipped' | |
| run: | | |
| if [ "${{ steps.lint.outcome }}" = 'success' ]; then | |
| echo "✅ clang-format check passed." | |
| else | |
| echo "::error::clang-format check failed. Please review the output above for details." | |
| echo "::error::Comment '@${{ github.event.repository.name }}bot format' on the PR to attempt auto-fix." | |
| exit 1 | |
| fi | |
| clang-format-check-skipped: | |
| needs: [pre-check, detect-changes] | |
| if: > | |
| github.event_name != 'workflow_dispatch' && | |
| needs.pre-check.outputs.is_act != 'true' && | |
| needs.detect-changes.result == 'success' && | |
| needs.detect-changes.outputs.has_changes != 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: No relevant C++ changes detected | |
| run: echo "::notice::No clang-format relevant changes detected; check skipped." |