fix(ci): scope revert-on-failure to the failing push's own commits

revert-on-failure re-fetched master and reverted before..HEAD, but HEAD
was the live tip of master, not the head of the failing push. When the
updater bot pushes one addon per commit in quick succession, a single
addon's build failure would sweep in every successful commit pushed
while the revert job was still running and revert them too.

Revert before..github.sha instead, and retry the push with a rebase in
case master moves again before we push.
This commit is contained in:
alexbelgium
2026-07-22 07:45:08 +02:00
parent 2ef067ec61
commit 40e4675e88

View File

@@ -407,20 +407,25 @@ jobs:
fetch-depth: 0 fetch-depth: 0
- name: Revert commits from this failed push - name: Revert commits from this failed push
env:
BEFORE: ${{ github.event.before }}
HEAD_SHA: ${{ github.sha }}
run: | run: |
set -euo pipefail set -euo pipefail
git config --global user.name "GitHub Actions" git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com" git config --global user.email "actions@github.com"
git fetch origin git fetch origin master
git checkout master
git pull --ff-only origin master
before="${{ github.event.before }}" # Revert exactly the commits THIS push introduced (before..HEAD_SHA).
if [ -n "$before" ] && [ "$before" != "0000000000000000000000000000000000000000" ]; then # Do not diff against the live master tip: concurrent pushes (e.g. the
mapfile -t commits < <(git rev-list "${before}..HEAD") # updater bot committing one addon per push) can land on master while
# this job is running, and a moving HEAD would sweep their unrelated,
# successful commits into the revert too.
if [ -n "$BEFORE" ] && [ "$BEFORE" != "0000000000000000000000000000000000000000" ]; then
mapfile -t commits < <(git rev-list "${BEFORE}..${HEAD_SHA}")
else else
commits=("${{ github.sha }}") commits=("$HEAD_SHA")
fi fi
if [ "${#commits[@]}" -eq 0 ]; then if [ "${#commits[@]}" -eq 0 ]; then
@@ -428,8 +433,21 @@ jobs:
exit 0 exit 0
fi fi
git checkout -B master origin/master
for commit in "${commits[@]}"; do for commit in "${commits[@]}"; do
git revert --no-edit "$commit" git revert --no-edit "$commit"
done done
git push origin HEAD:master # Master may have moved again since we fetched (e.g. another
# concurrent updater push), so retry the push with a rebase.
for attempt in 1 2 3 4 5; do
if git push origin HEAD:master; then
exit 0
fi
echo "Push rejected, rebasing onto latest master (attempt ${attempt})"
git fetch origin master
git rebase origin/master
done
echo "Failed to push reverts after retries" >&2
exit 1