Fix format-all sub-workflows silently skipped when called via workflow_call #62
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: Header Guards Fix | |
| run-name: "${{ github.actor }} fixing header guards" | |
| "on": | |
| issue_comment: | |
| types: | |
| - created | |
| workflow_call: | |
| inputs: | |
| checkout-path: | |
| description: "Path to check out code to" | |
| required: false | |
| type: string | |
| ref: | |
| description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)" | |
| required: true | |
| type: string | |
| repo: | |
| description: "The repository to checkout from" | |
| required: true | |
| type: string | |
| skip-comment: | |
| description: "Skip posting PR comments" | |
| required: false | |
| type: string | |
| default: "false" | |
| outputs: | |
| changes: | |
| description: "Whether any fixes were applied" | |
| value: ${{ jobs.apply_fixes.outputs.changes }} | |
| pushed: | |
| description: "Whether the fixes were pushed to the remote branch" | |
| value: ${{ jobs.apply_fixes.outputs.pushed }} | |
| commit_sha: | |
| description: "The full commit SHA of the applied fixes" | |
| value: ${{ jobs.apply_fixes.outputs.commit_sha }} | |
| commit_sha_short: | |
| description: "The short commit SHA of the applied fixes" | |
| value: ${{ jobs.apply_fixes.outputs.commit_sha_short }} | |
| patch_name: | |
| description: "Name of the patch file if fixes could not be pushed" | |
| value: ${{ jobs.apply_fixes.outputs.patch_name }} | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA). Defaults to the repository's default branch." | |
| required: false | |
| type: string | |
| permissions: | |
| pull-requests: write | |
| contents: write | |
| env: | |
| local_checkout_path: | |
| ${{ (github.event_name == 'workflow_call' && inputs.checkout-path) || format('{0}-src', | |
| github.event.repository.name) }} | |
| jobs: | |
| pre-check: | |
| runs-on: ubuntu-latest | |
| name: Parse command | |
| if: > | |
| github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call' || ( | |
| github.event_name == 'issue_comment' && | |
| github.event.issue.pull_request && | |
| contains(fromJSON('["OWNER", "COLLABORATOR", "MEMBER"]'), github.event.comment.author_association) && | |
| startsWith(github.event.comment.body, format('@{0}bot header-guards-fix', github.event.repository.name)) | |
| ) | |
| # Authorization: Only OWNER, COLLABORATOR, or MEMBER can trigger via comments. | |
| # This covers repo owners, invited collaborators, and all org members. | |
| outputs: | |
| ref: | |
| ${{ (github.event_name == 'workflow_call' && inputs.ref) || (github.event_name == 'workflow_dispatch' && | |
| (github.event.inputs.ref || github.ref_name)) || steps.get_pr.outputs.ref }} | |
| repo: | |
| ${{ (github.event_name == 'workflow_call' && inputs.repo) || (github.event_name == 'workflow_dispatch' && | |
| github.repository) || steps.get_pr.outputs.repo }} | |
| steps: | |
| - name: Get PR Info | |
| if: github.event_name == 'issue_comment' | |
| id: get_pr | |
| uses: Framework-R-D/phlex/.github/actions/get-pr-info@main | |
| apply_fixes: | |
| runs-on: ubuntu-latest | |
| name: Apply fixes | |
| needs: pre-check | |
| if: needs.pre-check.result == 'success' | |
| outputs: | |
| changes: ${{ steps.handle_commit.outputs.changes }} | |
| pushed: ${{ steps.handle_commit.outputs.pushed }} | |
| commit_sha: ${{ steps.handle_commit.outputs.commit_sha }} | |
| commit_sha_short: ${{ steps.handle_commit.outputs.commit_sha_short }} | |
| patch_name: ${{ steps.handle_commit.outputs.patch_name }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| path: ${{ env.local_checkout_path }} | |
| ref: ${{ needs.pre-check.outputs.ref }} | |
| repository: ${{ needs.pre-check.outputs.repo }} | |
| token: ${{ secrets.WORKFLOW_PAT }} | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: "3.12" | |
| - name: Fix header guards | |
| working-directory: ${{ env.local_checkout_path }} | |
| run: | | |
| echo "Fixing header guards..." | |
| python3 scripts/fix_header_guards.py --root . phlex plugins form || true | |
| - name: Handle fix commit | |
| id: handle_commit | |
| uses: Framework-R-D/phlex/.github/actions/handle-fix-commit@main | |
| with: | |
| tool: header-guards | |
| working-directory: ${{ env.local_checkout_path }} | |
| token: ${{ secrets.WORKFLOW_PAT }} | |
| pr-info-ref: ${{ needs.pre-check.outputs.ref }} | |
| pr-info-repo: ${{ needs.pre-check.outputs.repo }} | |
| skip-comment: ${{ github.event_name == 'workflow_call' && inputs.skip-comment || 'false' }} | |
| - name: Remove eyes reaction | |
| if: github.event_name == 'issue_comment' | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| script: | | |
| try { | |
| const { data: reactions } = await github.rest.reactions.listForIssueComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: context.payload.comment.id | |
| }); | |
| const eyesReaction = reactions.find( | |
| (r) => r.content === 'eyes' && r.user && r.user.login === 'github-actions[bot]' | |
| ); | |
| if (eyesReaction) { | |
| await github.rest.reactions.deleteForIssueComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: context.payload.comment.id, | |
| reaction_id: eyesReaction.id | |
| }); | |
| } | |
| } catch (_) { | |
| // Reaction cleanup is best-effort; do not fail the workflow. | |
| } | |
| - name: Add completion reaction | |
| if: github.event_name == 'issue_comment' | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| script: | | |
| await github.rest.reactions.createForIssueComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: context.payload.comment.id, | |
| content: 'rocket' | |
| }); |