Issue #10: Test code style check DO NOT MERGE #6
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: C++ Code Style and Static Analysis | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, ready_for_review] | |
| jobs: | |
| cpp-checks: | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/kpi-rover/kpi-rover-bbb-check:latest | |
| steps: | |
| - name: Checkout Code with Submodules | |
| uses: actions/checkout@v3 | |
| with: | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Configure CMake | |
| run: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build/check | |
| - name: Verify compile_commands.json exists | |
| run: ls build/check/compile_commands.json | |
| - name: Run Clang-Format | |
| id: clang-format | |
| continue-on-error: true | |
| run: find src/kpi_rover_ecu/ -name '*.cpp' -o -name '*.h' | xargs --no-run-if-empty clang-format --dry-run --Werror | |
| - name: Separator | |
| run: echo "===============================================================" | |
| - name: Run Clang-Tidy | |
| id: clang-tidy | |
| run: find src/kpi_rover_ecu/ -name '*.cpp' -o -name '*.h' | xargs --no-run-if-empty clang-tidy -p=build/check --warnings-as-errors='*' | |
| - name: Report Status | |
| if: always() | |
| env: | |
| FORMAT_STATUS: ${{ steps.clang-format.outcome }} | |
| TIDY_STATUS: ${{ steps.clang-tidy.outcome }} | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const formatStatus = process.env.FORMAT_STATUS === 'success'; | |
| const tidyStatus = process.env.TIDY_STATUS === 'success'; | |
| const conclusion = (formatStatus && tidyStatus) ? 'success' : 'failure'; | |
| let summary = ''; | |
| summary += formatStatus ? '✅ Clang-Format check passed\n' : '❌ Clang-Format check failed\n'; | |
| summary += tidyStatus ? '✅ Clang-Tidy check passed\n' : '❌ Clang-Tidy check failed\n'; | |
| github.rest.checks.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| name: 'Code Style Check', | |
| head_sha: context.payload.pull_request.head.sha, | |
| status: 'completed', | |
| conclusion: conclusion, | |
| output: { | |
| title: 'C++ Code Style Results', | |
| summary: summary | |
| } | |
| }); |