mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-08-24 22:03:32 +02:00
Merge pull request #2888 from alexbelgium/fix/revert-on-failure-scope
fix(ci): scope revert-on-failure to the failing push's own commits
This commit is contained in:
55
.github/workflows/onpush_builder.yaml
vendored
55
.github/workflows/onpush_builder.yaml
vendored
@@ -55,6 +55,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
outputs:
|
||||||
|
sanitizeCommitted: ${{ steps.sanitize_commit.outputs.committed }}
|
||||||
|
sanitizeCommitSha: ${{ steps.sanitize_commit.outputs.commit_long_sha }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
with:
|
with:
|
||||||
@@ -90,6 +93,7 @@ jobs:
|
|||||||
uses: ymwymw/check-mixed-line-endings@v2
|
uses: ymwymw/check-mixed-line-endings@v2
|
||||||
|
|
||||||
- name: Commit sanitize changes
|
- name: Commit sanitize changes
|
||||||
|
id: sanitize_commit
|
||||||
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
||||||
uses: EndBug/add-and-commit@v10
|
uses: EndBug/add-and-commit@v10
|
||||||
with:
|
with:
|
||||||
@@ -407,20 +411,36 @@ 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 }}
|
||||||
|
SANITIZE_COMMITTED: ${{ needs.prebuild-sanitize.outputs.sanitizeCommitted }}
|
||||||
|
SANITIZE_SHA: ${{ needs.prebuild-sanitize.outputs.sanitizeCommitSha }}
|
||||||
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
|
||||||
|
|
||||||
|
# The prebuild-sanitize job may have pushed its own [nobuild] commit
|
||||||
|
# on top of HEAD_SHA earlier in this same run. It's still this push's
|
||||||
|
# own fallout (not a neighboring push's), so revert it explicitly by
|
||||||
|
# SHA rather than widening the range to "whatever is on master now."
|
||||||
|
# It must be reverted first, since it sits on top of HEAD_SHA.
|
||||||
|
if [ "$SANITIZE_COMMITTED" = "true" ] && [ -n "$SANITIZE_SHA" ]; then
|
||||||
|
commits=("$SANITIZE_SHA" "${commits[@]}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${#commits[@]}" -eq 0 ]; then
|
if [ "${#commits[@]}" -eq 0 ]; then
|
||||||
@@ -428,8 +448,27 @@ 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
|
||||||
|
if ! git rebase origin/master; then
|
||||||
|
git rebase --abort
|
||||||
|
echo "Rebase hit a real conflict against latest master; aborting" \
|
||||||
|
"rather than pushing a partial/broken revert. This needs a" \
|
||||||
|
"human to look at it." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Failed to push reverts after retries" >&2
|
||||||
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user