diff --git a/.github/REUSABLE_WORKFLOWS.md b/.github/REUSABLE_WORKFLOWS.md index 7ba85e92..aa478ecc 100644 --- a/.github/REUSABLE_WORKFLOWS.md +++ b/.github/REUSABLE_WORKFLOWS.md @@ -82,13 +82,25 @@ You can achieve this by passing the appropriate value to the `skip-relevance-che skip-relevance-check: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'issue_comment' }} ``` -Additionally, to ensure the reusable workflow can access the correct code in an extra-repository context, always pass the `ref` and `repo`: +Additionally, to ensure the reusable workflow can access the correct code in an extra-repository context, always pass the `ref` and `repo`. The correct value depends on whether the workflow is a **check** (read-only) or **fix** (push-capable) workflow: -```yaml - with: - ref: ${{ github.event.pull_request.head.sha || github.sha }} - repo: ${{ github.repository }} -``` +- **Check workflows** (e.g., `cmake-format-check.yaml`): a commit SHA is safe and precise. + + ```yaml + with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} + repo: ${{ github.repository }} + ``` + +- **Fix workflows** (e.g., `cmake-format-fix.yaml`): a branch name is **required** because the + workflow pushes commits with `git push origin HEAD:`. A commit SHA will cause the push to + fail. + + ```yaml + with: + ref: ${{ github.event.pull_request.head.ref || github.ref_name }} + repo: ${{ github.repository }} + ``` --- @@ -162,7 +174,7 @@ jobs: fix-cmake: uses: Framework-R-D/phlex/.github/workflows/cmake-format-fix.yaml@ with: - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.event.pull_request.head.ref }} repo: ${{ github.repository }} skip-comment: "true" # Set to true when calling from a parent workflow secrets: @@ -172,7 +184,7 @@ jobs: #### All Inputs - `checkout-path` (string, optional): Path to check out code to. -- `ref` (string, **required**): The branch, ref, or SHA to check out. +- `ref` (string, **required**): The branch name to check out and push fixes to (must be a branch, not a commit SHA). - `repo` (string, **required**): The repository to check out from. - `skip-comment` (string, optional, default: `"false"`): Skip posting individual PR comments (use when called from a parent workflow that will post a combined comment). @@ -223,7 +235,7 @@ jobs: fix-python: uses: Framework-R-D/phlex/.github/workflows/python-fix.yaml@ with: - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.event.pull_request.head.ref }} repo: ${{ github.repository }} skip-comment: "true" secrets: @@ -233,7 +245,7 @@ jobs: #### All Inputs - `checkout-path` (string, optional): Path to check out code to. -- `ref` (string, **required**): The branch, ref, or SHA to check out. +- `ref` (string, **required**): The branch name to check out and push fixes to (must be a branch, not a commit SHA). - `repo` (string, **required**): The repository to check out from. - `skip-comment` (string, optional, default: `"false"`): Skip posting individual PR comments. @@ -284,7 +296,7 @@ jobs: fix-markdown: uses: Framework-R-D/phlex/.github/workflows/markdown-fix.yaml@ with: - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.event.pull_request.head.ref }} repo: ${{ github.repository }} skip-comment: "true" secrets: @@ -294,7 +306,7 @@ jobs: #### All Inputs - `checkout-path` (string, optional): Path to check out code to. -- `ref` (string, **required**): The branch, ref, or SHA to check out. +- `ref` (string, **required**): The branch name to check out and push fixes to (must be a branch, not a commit SHA). - `repo` (string, **required**): The repository to check out from. - `skip-comment` (string, optional, default: `"false"`): Skip posting individual PR comments. @@ -369,7 +381,7 @@ jobs: fix-jsonnet: uses: Framework-R-D/phlex/.github/workflows/jsonnet-format-fix.yaml@ with: - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.event.pull_request.head.ref }} repo: ${{ github.repository }} skip-comment: "true" secrets: @@ -379,7 +391,7 @@ jobs: #### All Inputs - `checkout-path` (string, optional): Path to check out code to. -- `ref` (string, **required**): The branch, ref, or SHA to checkout. +- `ref` (string, **required**): The branch name to checkout and push fixes to (must be a branch, not a commit SHA). - `repo` (string, **required**): The repository to checkout from. - `skip-comment` (string, optional, default: `"false"`): Skip posting individual PR comments. @@ -448,7 +460,7 @@ jobs: fix-clang-format: uses: Framework-R-D/phlex/.github/workflows/clang-format-fix.yaml@ with: - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.event.pull_request.head.ref }} repo: ${{ github.repository }} skip-comment: "true" secrets: @@ -458,7 +470,7 @@ jobs: #### All Inputs - `checkout-path` (string, optional): Path to check out code to. -- `ref` (string, **required**): The branch, ref, or SHA to check out. +- `ref` (string, **required**): The branch name to check out and push fixes to (must be a branch, not a commit SHA). - `repo` (string, **required**): The repository to check out from. - `skip-comment` (string, optional, default: `"false"`): Skip posting individual PR comments. @@ -488,7 +500,7 @@ jobs: fix-header-guards: uses: Framework-R-D/phlex/.github/workflows/header-guards-fix.yaml@ with: - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.event.pull_request.head.ref }} repo: ${{ github.repository }} skip-comment: "true" secrets: @@ -498,7 +510,7 @@ jobs: #### All Inputs - `checkout-path` (string, optional): Path to check out code to. -- `ref` (string, **required**): The branch, ref, or SHA to check out. +- `ref` (string, **required**): The branch name to check out and push fixes to (must be a branch, not a commit SHA). - `repo` (string, **required**): The repository to check out from. - `skip-comment` (string, optional, default: `"false"`): Skip posting individual PR comments. @@ -528,7 +540,7 @@ jobs: fix-yaml: uses: Framework-R-D/phlex/.github/workflows/yaml-fix.yaml@ with: - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.event.pull_request.head.ref }} repo: ${{ github.repository }} skip-comment: "true" secrets: @@ -538,7 +550,7 @@ jobs: #### All Inputs - `checkout-path` (string, optional): Path to check out code to. -- `ref` (string, **required**): The branch, ref, or SHA to check out. +- `ref` (string, **required**): The branch name to check out and push fixes to (must be a branch, not a commit SHA). - `repo` (string, **required**): The repository to check out from. - `skip-comment` (string, optional, default: `"false"`): Skip posting individual PR comments. diff --git a/.github/workflows/clang-format-fix.yaml b/.github/workflows/clang-format-fix.yaml index 5f34f238..00f65562 100644 --- a/.github/workflows/clang-format-fix.yaml +++ b/.github/workflows/clang-format-fix.yaml @@ -8,7 +8,7 @@ run-name: "${{ github.actor }} fixing C++ code format" workflow_dispatch: inputs: ref: - description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch." + 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 workflow_call: @@ -18,7 +18,7 @@ run-name: "${{ github.actor }} fixing C++ code format" required: false type: string ref: - description: "The branch, ref, or SHA to checkout" + description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)" required: true type: string repo: @@ -56,7 +56,7 @@ jobs: outputs: ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || (github.event_name == 'workflow_dispatch' && - (github.event.inputs.ref || github.ref)) || steps.get_pr.outputs.ref }} + (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 }} diff --git a/.github/workflows/clang-tidy-fix.yaml b/.github/workflows/clang-tidy-fix.yaml index 065429e8..061bd956 100644 --- a/.github/workflows/clang-tidy-fix.yaml +++ b/.github/workflows/clang-tidy-fix.yaml @@ -8,7 +8,7 @@ name: Clang-Tidy Fix workflow_dispatch: inputs: ref: - description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch." + 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 tidy-checks: @@ -35,7 +35,7 @@ jobs: # This covers repo owners, invited collaborators, and all org members. outputs: ref: - ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.ref || github.ref)) || + ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.ref || github.ref_name)) || steps.get_pr.outputs.ref }} repo: ${{ steps.get_pr.outputs.repo || github.repository }} tidy_checks: diff --git a/.github/workflows/cmake-format-fix.yaml b/.github/workflows/cmake-format-fix.yaml index 133be94c..c28b4cfc 100644 --- a/.github/workflows/cmake-format-fix.yaml +++ b/.github/workflows/cmake-format-fix.yaml @@ -8,7 +8,7 @@ run-name: "${{ github.actor }} fixing CMake format" workflow_dispatch: inputs: ref: - description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch." + 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 workflow_call: @@ -18,7 +18,7 @@ run-name: "${{ github.actor }} fixing CMake format" required: false type: string ref: - description: "The branch, ref, or SHA to checkout" + description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)" required: true type: string repo: @@ -56,7 +56,7 @@ jobs: outputs: ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || (github.event_name == 'workflow_dispatch' && - (github.event.inputs.ref || github.ref)) || steps.get_pr.outputs.ref }} + (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 }} diff --git a/.github/workflows/format-all.yaml b/.github/workflows/format-all.yaml index c13605d6..364d7c2d 100644 --- a/.github/workflows/format-all.yaml +++ b/.github/workflows/format-all.yaml @@ -105,16 +105,28 @@ jobs: uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 with: script: | - await github.rest.reactions.deleteForIssueComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: context.payload.comment.id, - reaction_id: (await github.rest.reactions.listForIssueComment({ + try { + const { data: reactions } = await github.rest.reactions.listForIssueComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: context.payload.comment.id - })).data.find(r => r.content === 'eyes' && r.user.type === 'Bot')?.id - }).catch(() => {}); + }); + + const eyesReaction = reactions.find( + (r) => r.content === 'eyes' && r.user && r.user.login === 'github-actions[bot]' + ); + + if (eyesReaction && eyesReaction.id) { + 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 uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 @@ -143,7 +155,7 @@ jobs: if [ "$pushed" == "true" ]; then messages+=("✅ $name fixes pushed (commit $sha_short)") elif [ -n "$patch_name" ]; then - messages+=("⚠️ $name fixes available as patch artifact \"$patch_name\". Download the artifact from this workflow run, then run: \`git apply $patch_name\` from the repository root.") + messages+=("⚠️ $name fixes available as a patch file (\`$patch_name\`) in the \"fix-patch\" artifact. Download the artifact from this workflow run, then run: \`git apply $patch_name\` from the repository root.") fi fi } diff --git a/.github/workflows/header-guards-fix.yaml b/.github/workflows/header-guards-fix.yaml index 85dfefee..b8f99bf7 100644 --- a/.github/workflows/header-guards-fix.yaml +++ b/.github/workflows/header-guards-fix.yaml @@ -12,7 +12,7 @@ run-name: "${{ github.actor }} fixing header guards" required: false type: string ref: - description: "The branch, ref, or SHA to checkout" + description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)" required: true type: string repo: @@ -27,7 +27,7 @@ run-name: "${{ github.actor }} fixing header guards" workflow_dispatch: inputs: ref: - description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch." + 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 @@ -56,7 +56,7 @@ jobs: outputs: ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || (github.event_name == 'workflow_dispatch' && - (github.event.inputs.ref || github.ref)) || steps.get_pr.outputs.ref }} + (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 }} diff --git a/.github/workflows/jsonnet-format-fix.yaml b/.github/workflows/jsonnet-format-fix.yaml index 4380d93a..6e3bf44e 100644 --- a/.github/workflows/jsonnet-format-fix.yaml +++ b/.github/workflows/jsonnet-format-fix.yaml @@ -8,7 +8,7 @@ run-name: "${{ github.actor }} fixing Jsonnet format" workflow_dispatch: inputs: ref: - description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch." + 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 workflow_call: @@ -18,7 +18,7 @@ run-name: "${{ github.actor }} fixing Jsonnet format" required: false type: string ref: - description: "The branch, ref, or SHA to checkout" + description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)" required: true type: string repo: @@ -56,7 +56,7 @@ jobs: outputs: ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || (github.event_name == 'workflow_dispatch' && - (github.event.inputs.ref || github.ref)) || steps.get_pr.outputs.ref }} + (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 }} diff --git a/.github/workflows/markdown-fix.yaml b/.github/workflows/markdown-fix.yaml index ecf3a92d..a1120b7b 100644 --- a/.github/workflows/markdown-fix.yaml +++ b/.github/workflows/markdown-fix.yaml @@ -12,7 +12,7 @@ run-name: "${{ github.actor }} fixing Markdown format" required: false type: string ref: - description: "The branch, ref, or SHA to checkout" + description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)" required: true type: string repo: @@ -27,7 +27,7 @@ run-name: "${{ github.actor }} fixing Markdown format" workflow_dispatch: inputs: ref: - description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch." + 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 @@ -56,7 +56,7 @@ jobs: outputs: ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || (github.event_name == 'workflow_dispatch' && - (github.event.inputs.ref || github.ref)) || steps.get_pr.outputs.ref }} + (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 }} diff --git a/.github/workflows/python-fix.yaml b/.github/workflows/python-fix.yaml index f4333fc7..ec98a6a5 100644 --- a/.github/workflows/python-fix.yaml +++ b/.github/workflows/python-fix.yaml @@ -8,7 +8,7 @@ run-name: "${{ github.actor }} fixing Python code" workflow_dispatch: inputs: ref: - description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch." + 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 workflow_call: @@ -18,7 +18,7 @@ run-name: "${{ github.actor }} fixing Python code" required: false type: string ref: - description: "The branch, ref, or SHA to checkout" + description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)" required: true type: string repo: @@ -56,7 +56,7 @@ jobs: outputs: ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || (github.event_name == 'workflow_dispatch' && - (github.event.inputs.ref || github.ref)) || steps.get_pr.outputs.ref }} + (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 }} diff --git a/.github/workflows/yaml-fix.yaml b/.github/workflows/yaml-fix.yaml index f0b846f8..5376ef93 100644 --- a/.github/workflows/yaml-fix.yaml +++ b/.github/workflows/yaml-fix.yaml @@ -8,7 +8,7 @@ name: YAML Fix workflow_dispatch: inputs: ref: - description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch." + 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 workflow_call: @@ -18,7 +18,7 @@ name: YAML Fix required: false type: string ref: - description: "The branch, ref, or SHA to checkout" + description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)" required: true type: string repo: @@ -56,7 +56,7 @@ jobs: outputs: ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || (github.event_name == 'workflow_dispatch' && - (github.event.inputs.ref || github.ref)) || steps.get_pr.outputs.ref }} + (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 }}