Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 27 additions & 1 deletion .github/workflows/upstream-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,38 @@ jobs:
[ -n "$id" ] || { echo "no gate run appeared for $SHA on $BRANCH" >&2; exit 1; }
gh run watch "$id" --repo "$GITHUB_REPOSITORY" --exit-status --interval 30

# GitHub holds the pull_request run of a PR this workflow opened until someone with write access
# approves it, and the held run blocks the main ruleset even though the gate job above already
# passed on the same commit. The bot approves its own held run and waits for it. If GitHub refuses
# that approval, the merge fails as before and the PR stays open for a human.
merge:
needs: [sync, gate]
runs-on: ubuntu-latest
permissions:
actions: write
contents: write
pull-requests: write
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ needs.sync.outputs.pr }}
SHA: ${{ needs.sync.outputs.sha }}
BRANCH: ${{ needs.sync.outputs.branch }}
steps:
- run: gh pr merge "$PR" --repo "$GITHUB_REPOSITORY" --squash --delete-branch --match-head-commit "$SHA"
- id: land
run: |
held=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow gate.yml --event pull_request \
--branch "$BRANCH" --json databaseId,headSha,conclusion \
--jq "[.[] | select(.headSha == \"$SHA\" and .conclusion == \"action_required\")][].databaseId")
for id in $held; do
if ! gh api -X POST "repos/$GITHUB_REPOSITORY/actions/runs/$id/approve" >/dev/null; then
echo "could not approve held run $id; approve it on the PR, then merge" >&2
continue
fi
echo "approved held run $id"
for _ in $(seq 1 30); do
[ "$(gh run view "$id" --repo "$GITHUB_REPOSITORY" --json status --jq .status)" != completed ] && break
sleep 10
done
gh run watch "$id" --repo "$GITHUB_REPOSITORY" --exit-status --interval 30
done
gh pr merge "$PR" --repo "$GITHUB_REPOSITORY" --squash --delete-branch --match-head-commit "$SHA"
13 changes: 10 additions & 3 deletions PORTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,16 @@ only after that run passes. A dispatch, unlike a reusable call, reports the chec
`smoke`, and `statechart` on the sync commit. The `main` ruleset requires exactly those three, and a
personal repository cannot exempt the GitHub Actions bot from a ruleset, so a reusable call's
`gate / gate` names would leave every bot merge blocked. The ruleset also requires a pull request
for every change to `main` and forbids force-pushes and deletion. A sync that fails the build,
`check-port.sh`, or `gate.yml` stays open for a human, and later runs stop at the open-PR guard
until someone resolves it.
for every change to `main` and forbids force-pushes and deletion.

GitHub holds the `pull_request` run of a PR that `github.token` opened until a user with write access
approves it, and that held run blocks the ruleset even when the dispatched checks have passed on the
same commit. This stalled sync #60. Before it merges, the `merge` job therefore approves the held
`gate.yml` run at the sync commit and waits for it to pass. Whether GitHub accepts that approval from
the workflow's own token is not documented. If it refuses, the job says so, the merge fails as before,
and the PR waits for a human to approve the run. A sync that fails the build, `check-port.sh`,
`gate.yml`, or that merge stays open for a human, and later runs stop at the open-PR guard until
someone resolves it.

Never substitute the `backnotprop/pstack` mirror for upstream.

Expand Down
57 changes: 57 additions & 0 deletions omp-port/test-upstream-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ for id in plan build; do
bun -e "$EXTRACT" -- "$WF" sync "$id" "$WORK/$id.sh" >"$WORK/$id.shell" ||
{ echo "FAIL extracting sync.$id from $WF" >&2; exit 1; }
done
bun -e "$EXTRACT" -- "$WF" merge land "$WORK/land.sh" >"$WORK/land.shell" ||
{ echo "FAIL extracting merge.land from $WF" >&2; exit 1; }

mkdir -p "$WORK/bin" "$WORK/port"
cat >"$WORK/bin/gh" <<'EOF'
Expand All @@ -57,6 +59,19 @@ while [ $# -gt 0 ]; do
shift
done
case $sub in
"run list")
jq -r "$filter" "$FIX/runs.json"
;;
"api -X")
[ ! -e "$FIX/approve-fails" ] || { echo "HTTP 403: Resource not accessible by integration" >&2; exit 1; }
;;
"run view")
echo in_progress
;;
"run watch")
[ ! -e "$FIX/watch-fails" ] || { echo "run 41 failed" >&2; exit 1; }
;;
"pr merge") ;;
"pr list")
jq -c --arg s "$state" --arg h "$head" \
'[.[] | select($s == "all" or (.state | ascii_downcase) == $s) | select($h == "" or .headRefName == $h)]' \
Expand Down Expand Up @@ -263,5 +278,47 @@ expect "exit 0" exited 0
expect "lists drift" [ -s "$C/stdout" ]
expect "the target is the first commit listed" [ "$(cut -c1-7 "$C/target" 2>/dev/null)" = "$(head -n1 "$C/stdout" | cut -f1)" ]

held_runs() {
jq -n --arg s "$1" '[{databaseId: 41, headSha: $s, conclusion: "action_required"},
{databaseId: 42, headSha: $s, conclusion: "success"},
{databaseId: 40, headSha: "0000000000000000000000000000000000000000", conclusion: "action_required"}]' >"$C/runs.json"
}
land() { run_step land PR=https://github.com/negoro26/pstack-omp/pull/99 SHA="$BUILT" BRANCH=sync/upstream-x GITHUB_REPOSITORY=negoro26/pstack-omp; }
called() { grep -q "$1" "$C/gh.log"; }
never_called() { ! called "$1"; }

new_case land-approves-held-run
held_runs "$BUILT"
land
expect "exit 0" exited 0
expect "approves the held run at the built commit" called "runs/41/approve"
expect "waits for it" called "run watch 41"
expect "lists only the gate's pull_request runs on the sync branch" called "run list --repo negoro26/pstack-omp --workflow gate.yml --event pull_request --branch sync/upstream-x"
expect "leaves an older commit's run alone" never_called "runs/40/"
expect "leaves a run that already finished alone" never_called "runs/42/"
expect "merges after the approval" [ "$(grep -n 'pr merge' "$C/gh.log" | cut -d: -f1)" -gt "$(grep -n 'approve' "$C/gh.log" | cut -d: -f1)" ]

new_case land-failed-held-run-blocks-merge
held_runs "$BUILT"
touch "$C/watch-fails"
land
expect "nonzero exit" failed
expect "no merge" never_called "pr merge"

new_case land-approval-refused
held_runs "$BUILT"
touch "$C/approve-fails"
land
expect "says the run needs a human" logged "could not approve held run 41"
expect "does not watch a run it could not approve" never_called "run watch"
expect "still tries the merge, which GitHub refuses while the run is held" called "pr merge"

new_case land-no-held-run
echo '[]' >"$C/runs.json"
land
expect "exit 0" exited 0
expect "approves nothing" never_called "approve"
expect "merges" called "pr merge"

[ "$fail" -eq 0 ] && echo "PASS upstream-sync workflow steps and check"
exit "$fail"