Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
github.event.workflow_run.pull_requests[0].number != null
runs-on: ubuntu-latest
steps:
- name: Verify required CI workflows are successful
- name: Verify all relevant CI workflows are successful
id: check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
Expand All @@ -29,31 +30,49 @@ jobs:
runs_json="$(gh api \
"repos/${GITHUB_REPOSITORY}/actions/runs?event=pull_request&head_sha=${HEAD_SHA}&per_page=100")"

required_workflows=("Go CI" "Docs CI")
for workflow_name in "${required_workflows[@]}"; do
status="$(echo "${runs_json}" | jq -r --arg wf "${workflow_name}" \
'.workflow_runs[] | select(.name == $wf) | .status' | head -n1)"
conclusion="$(echo "${runs_json}" | jq -r --arg wf "${workflow_name}" \
'.workflow_runs[] | select(.name == $wf) | .conclusion' | head -n1)"
# Each workflow is treated as required only if it actually ran for this
# SHA. Path filters on Docs CI / Go CI mean a Go-only or docs-only PR
# legitimately runs just one of them; the other should not block merge.
candidate_workflows=("Go CI" "Docs CI")
ran_at_least_one=false

if [ -z "${status}" ]; then
echo "Workflow '${workflow_name}' has not run yet for ${HEAD_SHA}. Skipping."
exit 0
fi
for workflow_name in "${candidate_workflows[@]}"; do
conclusion="$(echo "${runs_json}" | jq -r --arg wf "${workflow_name}" \
'[.workflow_runs[] | select(.name == $wf)] | (.[0].conclusion // "missing")')"

if [ "${conclusion}" != "success" ]; then
echo "Workflow '${workflow_name}' conclusion='${conclusion}'. Skipping."
exit 0
fi
case "${conclusion}" in
missing|skipped)
echo "Workflow '${workflow_name}' did not run for ${HEAD_SHA} (likely path filter). Treating as N/A."
Comment on lines +40 to +45

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat in-progress workflow as blocker, not N/A

In .github/workflows/dependabot-auto-merge.yml, the verifier maps null conclusions to "missing" via (.[0].conclusion // "missing"), and then treats missing as non-blocking. For PRs that touch both code and docs, it is common for one workflow (e.g., Go CI) to finish first and trigger this job while the other (Docs CI) is still running with conclusion=null; this logic will incorrectly classify that running workflow as N/A and allow proceed=true, enabling auto-merge before all relevant CI has actually completed.

Useful? React with 👍 / 👎.

;;
success)
echo "Workflow '${workflow_name}' succeeded."
ran_at_least_one=true
;;
*)
echo "Workflow '${workflow_name}' conclusion='${conclusion}'. Not auto-merging."
echo "proceed=false" >> "${GITHUB_OUTPUT}"
exit 0
;;
esac
done

if [ "${ran_at_least_one}" != "true" ]; then
echo "No required workflow ran successfully for ${HEAD_SHA}. Refusing to auto-merge."
echo "proceed=false" >> "${GITHUB_OUTPUT}"
exit 0
fi

echo "proceed=true" >> "${GITHUB_OUTPUT}"

- name: Auto-approve pull request
if: steps.check.outputs.proceed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
run: gh pr review --repo "${GITHUB_REPOSITORY}" "${PR_NUMBER}" --approve --body "Auto-approved after successful Go CI and Docs CI."
run: gh pr review --repo "${GITHUB_REPOSITORY}" "${PR_NUMBER}" --approve --body "Auto-approved after successful CI."

- name: Enable auto-merge
if: steps.check.outputs.proceed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
Expand Down
Loading