docs(collator): include "id" placeholder in start command example #236
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: Nathan Commit Gate | |
| on: | |
| pull_request: | |
| types: [synchronize] | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| actions: write | |
| jobs: | |
| dispatch-nathan: | |
| # Do not allow fork PRs to auto-dispatch the secret-bearing workflow. | |
| if: ${{ github.event.pull_request != null && github.event.pull_request.head.repo.fork == false }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Validate dispatcher permissions | |
| id: perm | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| ACTOR: ${{ github.actor }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| permission="$(gh api -H "Accept: application/vnd.github+json" \ | |
| "repos/${REPO}/collaborators/${ACTOR}/permission" \ | |
| --jq '.permission // ""' 2>/dev/null || true)" | |
| case "${permission}" in | |
| admin|maintain|write) | |
| echo "allowed=true" >> "$GITHUB_OUTPUT" | |
| echo "✅ ${ACTOR} has ${permission} permission." | |
| ;; | |
| *) | |
| echo "allowed=false" >> "$GITHUB_OUTPUT" | |
| echo "⏭️ ${ACTOR} does not have sufficient permission (permission='${permission:-none}'); skipping dispatch." | |
| ;; | |
| esac | |
| - name: Check latest commit message (+Nathan) | |
| id: gate | |
| if: ${{ steps.perm.outputs.allowed == 'true' }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| commits_json="$(gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/commits" | jq -s 'add')" | |
| sha="$(printf '%s' "$commits_json" | jq -r '.[-1].sha // ""')" | |
| msg="$(printf '%s' "$commits_json" | jq -r '.[-1].commit.message // ""')" | |
| shopt -s nocasematch | |
| if [[ "$msg" == *"+nathan"* ]]; then | |
| echo "triggered=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "triggered=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| shopt -u nocasematch | |
| first_line="$(printf '%s\n' "$msg" | head -n1 | tr -d '\r')" | |
| echo "Latest PR commit: ${sha:-unknown} — ${first_line:-<no message>}" | |
| - name: Dispatch Nathan workflow | |
| if: ${{ steps.perm.outputs.allowed == 'true' && steps.gate.outputs.triggered == 'true' }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| HEAD_REF: ${{ github.event.pull_request.head.ref }} | |
| DISPATCH_REF: ${{ github.event.repository.default_branch }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if [[ -z "${HEAD_REF:-}" ]]; then | |
| echo "Missing PR head ref; cannot dispatch." | |
| exit 1 | |
| fi | |
| if [[ -z "${DISPATCH_REF:-}" ]]; then | |
| echo "Missing repository default branch; cannot dispatch." | |
| exit 1 | |
| fi | |
| echo "Dispatching trigger-n8n-workflow.yml for PR #${PR_NUMBER} (workflow ref=${DISPATCH_REF}, PR ref=${HEAD_REF})" | |
| dispatch_output="" | |
| if dispatch_output="$( | |
| gh api -X POST "repos/${REPO}/actions/workflows/trigger-n8n-workflow.yml/dispatches" \ | |
| -f ref="${DISPATCH_REF}" \ | |
| -f inputs[pr_number]="${PR_NUMBER}" 2>&1 | |
| )"; then | |
| exit 0 | |
| fi | |
| rc=$? | |
| echo "$dispatch_output" | |
| if [[ "$dispatch_output" == *"Failed to run workflow dispatch"* && "$dispatch_output" == *"\"status\":500"* ]]; then | |
| echo "Transient GitHub 500 while dispatching workflow; retrying once..." | |
| sleep 2 | |
| if dispatch_output="$( | |
| gh api -X POST "repos/${REPO}/actions/workflows/trigger-n8n-workflow.yml/dispatches" \ | |
| -f ref="${DISPATCH_REF}" \ | |
| -f inputs[pr_number]="${PR_NUMBER}" 2>&1 | |
| )"; then | |
| exit 0 | |
| fi | |
| echo "$dispatch_output" | |
| fi | |
| exit $rc |