Skip to content

Commit 8fffbeb

Browse files
mv verify script to scripts/ dir
1 parent 0b98cfd commit 8fffbeb

2 files changed

Lines changed: 40 additions & 31 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
declare -r expected_sha="${1:?missing expected_sha}"
5+
declare -r gh_pr_number="${2:?missing gh_pr_number}"
6+
declare -r gh_repository="${3:?missing gh_repository}"
7+
declare -r gh_current_run_id="${4:?missing gh_current_run_id}"
8+
9+
# 1. Fetch current PR HEAD SHA to ensure no new commit was pushed while this ran
10+
CURRENT_SHA=$(gh pr view "${gh_pr_number}" \
11+
--repo "${gh_repository}" \
12+
--json headRefOid --jq '.headRefOid')
13+
14+
if [ "${CURRENT_SHA}" != "${expected_sha}" ]; then
15+
echo "A new commit (${CURRENT_SHA}) was pushed after this run started (${expected_sha}). Aborting auto-merge."
16+
exit 1
17+
fi
18+
19+
# 2. Allowlist filter: select any check whose state is NOT in [SUCCESS, SKIPPED, NEUTRAL],
20+
# filtering out the current workflow run by checking if its link contains gh_current_run_id.
21+
NON_PASSING_CHECKS=$(gh pr checks "${gh_pr_number}" \
22+
--repo "${gh_repository}" \
23+
--json workflow,name,state,link |
24+
jq --compact --arg current_run_id "${gh_current_run_id}" \
25+
'.[] | select(
26+
(.link | contains($current_run_id) | not)
27+
and
28+
(.state | test("^(SUCCESS|SKIPPED|NEUTRAL)$") | not)
29+
)')
30+
31+
if [ -n "${NON_PASSING_CHECKS}" ]; then
32+
echo "Cannot auto-merge. The following checks are not passing:"
33+
echo "${NON_PASSING_CHECKS}" | jq -r '"workflow: \(.workflow), name: \(.name), state: \(.state)""'
34+
exit 1
35+
fi

.github/workflows/pr-quality-check.yaml

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -143,37 +143,11 @@ jobs:
143143
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144144
EXPECTED_SHA: ${{ github.event.pull_request.head.sha }}
145145
run: |
146-
declare -r gh_pr_number='${{ github.event.pull_request.number }}'
147-
declare -r gh_repository='${{ github.repository }}'
148-
declare -r gh_current_run_id='${{ github.run_id }}'
149-
150-
# 1. Fetch current PR HEAD SHA to ensure no new commit was pushed while this ran
151-
CURRENT_SHA=$(gh pr view "${gh_pr_number}" \
152-
--repo "${gh_repository}" \
153-
--json headRefOid --jq '.headRefOid')
154-
155-
if [ "${CURRENT_SHA}" != "${EXPECTED_SHA}" ]; then
156-
echo "A new commit (${CURRENT_SHA}) was pushed after this run started (${EXPECTED_SHA}). Aborting auto-merge."
157-
exit 1
158-
fi
159-
160-
# 2. Allowlist filter: select any check whose state is NOT in [SUCCESS, SKIPPED, NEUTRAL],
161-
# filtering out the current workflow run by checking if its link contains gh_current_run_id.
162-
NON_PASSING_CHECKS=$(gh pr checks "${gh_pr_number}" \
163-
--repo "${gh_repository}" \
164-
--json workflow,name,state,link |
165-
jq --compact --arg current_run_id "${gh_current_run_id}" \
166-
'.[] | select(
167-
(.link | contains($current_run_id) | not)
168-
and
169-
(.state | test("^(SUCCESS|SKIPPED|NEUTRAL)$") | not)
170-
)')
171-
172-
if [ -n "${NON_PASSING_CHECKS}" ]; then
173-
echo "Cannot auto-merge. The following checks are not passing:"
174-
echo "${NON_PASSING_CHECKS}" | jq -r '"workflow: \(.workflow), name: \(.name), state: \(.state)""'
175-
exit 1
176-
fi
146+
${{ github.workspace }}/.github/scripts/verify-all-pr-workflow-checks-passed.sh \
147+
'${{ github.event.pull_request.head.sha }}' \
148+
'${{ github.event.pull_request.number }}' \
149+
'${{ github.repository }}' \
150+
'${{ github.run_id }}'
177151
178152
- name: Enable auto-merge via squash
179153
env:

0 commit comments

Comments
 (0)