Reorganize and refactor workflows and actions (#129) #10
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 | ||
|
Check failure on line 1 in .github/workflows/clang-tidy-check.yaml
|
||
| 'run-name': "${{ github.actor }} running clang-tidy check" | ||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| on: | ||
| pull_request: | ||
| branches: [ main, develop ] | ||
| issue_comment: | ||
| types: | ||
| - created | ||
| workflow_dispatch: | ||
| jobs: | ||
| pre-check: | ||
| runs-on: ubuntu-latest | ||
| if: > | ||
| github.event_name == 'workflow_dispatch' || | ||
| github.event_name == 'pull_request' || | ||
| (github.event_name == 'issue_comment' && github.event.issue.pull_request) | ||
| outputs: | ||
| is_act: ${{ steps.detect_act.outputs.is_act }} | ||
| should_run: ${{ steps.check_comment.outputs.match_result == 'match' }} | ||
| tidy_checks: ${{ steps.check_comment.outputs.tidy_checks }} | ||
| ref_name: ${{ steps.check_comment.outputs.ref_name }} | ||
| repo_name: ${{ steps.check_comment.outputs.repo_name }} | ||
| steps: | ||
| - name: Detect act environment | ||
| id: detect_act | ||
| uses: Framework-R-D/phlex/.github/actions/detect-act-env@main | ||
| - id: check_comment | ||
| if: github.event_name == 'issue_comment' | ||
| name: Check comment | ||
| run: | | ||
| match_result=$(echo "$COMMENT_BODY" | grep -qE '^@phlexbot[[:space:]]+tidy-check\b' && echo match || echo non_match) | ||
| # Extract any tokens after 'tidy-check' | ||
| checks_line=$(echo "$COMMENT_BODY" | sed -nE 's/^@phlexbot[[:space:]]+tidy-check[[:space:]]+(.*)/\1/p' | tr -d '\r') | ||
| tidy_checks="" | ||
| if [ -n "$checks_line" ]; then | ||
| # Normalize separators: comma or whitespace -> single comma-separated list | ||
| tidy_checks=$(echo "$checks_line" | tr ',' ' ' | xargs -n1 | paste -sd, -) | ||
| fi | ||
| echo "match_result=$match_result" >> $GITHUB_OUTPUT | ||
| echo "tidy_checks=$tidy_checks" >> $GITHUB_OUTPUT | ||
| ISSUE_NUMBER=${{ github.event.issue.number }} | ||
| REPO="${{ github.repository }}" | ||
| gh api "repos/$REPO/pulls/$ISSUE_NUMBER" > pr.json | ||
| echo "ref_name=$(jq -r .head.ref pr.json)" >> $GITHUB_OUTPUT | ||
| echo "repo_name=$(jq -r .head.repo.full_name pr.json)" >> $GITHUB_OUTPUT | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| COMMENT_BODY: ${{ github.event.comment.body }} | ||
| detect-changes: | ||
| needs: pre-check | ||
| if: > | ||
| github.event_name == 'pull_request' && | ||
| 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@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | ||
| with: | ||
| fetch-depth: 0 | ||
| path: phlex-src | ||
| - name: Detect clang-tidy relevant changes | ||
| id: filter | ||
| uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main | ||
| with: | ||
| repo-path: phlex-src | ||
| base-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} | ||
| head-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | ||
| 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: > | ||
| github.event_name == 'workflow_dispatch' || | ||
| needs.pre-check.outputs.is_act == 'true' || | ||
| (github.event_name == 'pull_request' && needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes == 'true') || | ||
| (github.event_name == 'issue_comment' && needs.pre-check.outputs.should_run == 'true' && (github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'OWNER')) | ||
| runs-on: ubuntu-24.04 | ||
| container: | ||
| image: ghcr.io/framework-r-d/phlex-ci:latest | ||
| steps: | ||
| - name: Checkout code (PR) | ||
| if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' | ||
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | ||
| with: | ||
| path: phlex-src | ||
| - name: Checkout code (comment) | ||
| if: github.event_name == 'issue_comment' | ||
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | ||
| with: | ||
| path: phlex-src | ||
| ref: ${{ needs.pre-check.outputs.ref_name }} | ||
| repository: ${{ needs.pre-check.outputs.repo_name }} | ||
| - 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 | ||
| env: | ||
| PHLEX_TIDY_CHECKS: ${{ needs.pre-check.outputs.tidy_checks }} | ||
| 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 '@phlexbot 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@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.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@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.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@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.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: [tidy-pre-check, detect-clang-tidy-changes] | ||
| if: > | ||
| github.event_name == 'pull_request' && | ||
| needs.tidy-pre-check.outputs.is_act != 'true' && | ||
| needs.detect-clang-tidy-changes.result == 'success' && | ||
| needs.detect-clang-tidy-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." | ||