Copilot checking C++ code with clang-tidy #1093
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-Tidy Check | |
| 'run-name': "${{ github.actor }} checking C++ code with clang-tidy" | |
| 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: > | |
| needs.pre-check.result == 'success' && | |
| 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 | |
| cmake | |
| - name: Report detection outcome | |
| run: | | |
| if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then | |
| echo "::notice::No clang-tidy relevant changes detected; job will be skipped." | |
| else | |
| echo "::group::Clang-tidy relevant files" | |
| printf '%s\n' "${{ steps.filter.outputs.matched_files }}" | |
| echo "::endgroup::" | |
| fi | |
| clang-tidy-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-24.04 | |
| container: | |
| image: ghcr.io/framework-r-d/phlex-ci:latest | |
| 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: Setup build environment | |
| uses: Framework-R-D/phlex/.github/actions/setup-build-env@main | |
| - name: Configure CMake (Debug) | |
| uses: Framework-R-D/phlex/.github/actions/configure-cmake@main | |
| with: | |
| build-type: Debug | |
| extra-options: "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_SCAN_FOR_MODULES=OFF" | |
| - name: Run clang-tidy using CMake target | |
| shell: bash | |
| run: | | |
| . /entrypoint.sh | |
| cd "$GITHUB_WORKSPACE/phlex-build" | |
| echo "➡️ Running clang-tidy checks..." | |
| cmake --build . --target clang-tidy-check -- --export-fixes clang-tidy-fixes.yaml > clang-tidy.log 2>&1 || true | |
| if [ -s clang-tidy-fixes.yaml ]; then | |
| echo "::error::Clang-tidy found issues in the code" | |
| echo "Error count by check (full details in clang-tidy-log artifact):" | |
| sed -nEe '\&^/& s&^.*\[([^][:space:]]+)\]$&\1&p' clang-tidy.log | sort | uniq -c | sort -n -k 1 -r | |
| echo "Comment '@${{ github.event.repository.name }}bot tidy-fix [<check>...]' on the PR to attempt auto-fix" | |
| exit 1 | |
| else | |
| echo "✅ clang-tidy check passed" | |
| fi | |
| - name: Upload clang-tidy report | |
| if: failure() | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | |
| with: | |
| name: clang-tidy-report | |
| path: phlex-build/clang-tidy-fixes.yaml | |
| retention-days: 7 | |
| - name: Upload clang-tidy log | |
| if: failure() | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | |
| with: | |
| name: clang-tidy-log | |
| path: phlex-build/clang-tidy.log | |
| retention-days: 7 | |
| clang-tidy-pr-comments: | |
| needs: clang-tidy-check | |
| if: failure() && github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - name: Download clang-tidy report | |
| uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 | |
| with: | |
| name: clang-tidy-report | |
| path: phlex-build | |
| - name: Post clang-tidy comments | |
| uses: platisd/clang-tidy-pr-comments@28cfb84edafa771c044bde7e4a2a3fae57463818 # v1.8.0 | |
| with: | |
| clang_tidy_fixes: phlex-build/clang-tidy-fixes.yaml | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| clang-tidy-check-skipped: | |
| needs: [pre-check, detect-changes] | |
| if: > | |
| needs.pre-check.result == 'success' && | |
| 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 clang-tidy changes detected | |
| run: echo "::notice::No clang-tidy relevant changes detected; check skipped." |