Skip to content

Commit d1846d3

Browse files
committed
Ensure that worktree is uploaded on failure, fix insane range-diff invocation
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent c5267b9 commit d1846d3

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

.github/workflows/rebase-shears.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jobs:
6969
git fetch upstream --no-tags
7070
7171
- name: Run rebase (single branch)
72+
id: rebase-single
7273
if: env.BRANCH != 'all'
7374
shell: bash
7475
run: |
@@ -89,14 +90,12 @@ jobs:
8990
GH_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
9091

9192
- name: Run rebase (all branches)
93+
id: rebase-all
9294
if: env.BRANCH == 'all'
9395
shell: bash
9496
run: |
9597
for BRANCH in seen next main maint; do
96-
echo ""
97-
echo "========================================"
98-
echo "Processing shears/$BRANCH"
99-
echo "========================================"
98+
echo "::group::Processing shears/$BRANCH"
10099
101100
case "$BRANCH" in
102101
main) UPSTREAM="upstream/master" ;;
@@ -107,27 +106,35 @@ jobs:
107106
108107
if test 0 = "$(git rev-list --count "origin/shears/$BRANCH..$UPSTREAM")"; then
109108
echo "Nothing to do: $UPSTREAM has no new commits"
109+
echo "::endgroup::"
110110
continue
111111
fi
112112
113113
./ci/rebase-branch.sh "origin/shears/$BRANCH" "$UPSTREAM" ./ci || {
114+
echo "::endgroup::"
114115
echo "Rebase failed for shears/$BRANCH"
115116
exit 1
116117
}
118+
echo "::endgroup::"
117119
done
118-
119-
echo ""
120-
echo "All branches processed successfully!"
121120
env:
122121
GH_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
123122

123+
- name: Create recovery archive on failure
124+
if: failure() && (steps.rebase-single.outputs.worktree || steps.rebase-all.outputs.worktree)
125+
shell: bash
126+
run: |
127+
worktree="${{ steps.rebase-single.outputs.worktree || steps.rebase-all.outputs.worktree }}"
128+
cd "$worktree"
129+
git bundle create recovery.bundle HEAD REBASE_HEAD refs/rewritten/* 2>/dev/null || true
130+
tar -czf recovery-archive.tar.gz .
131+
124132
- name: Upload recovery archive on failure
125-
if: failure()
133+
if: failure() && (steps.rebase-single.outputs.worktree || steps.rebase-all.outputs.worktree)
126134
uses: actions/upload-artifact@v4
127135
with:
128136
name: recovery-archive
129-
path: "**/recovery-archive.tar.gz"
130-
if-no-files-found: ignore
137+
path: "${{ steps.rebase-single.outputs.worktree || steps.rebase-all.outputs.worktree }}/recovery-archive.tar.gz"
131138

132139
- name: Push results
133140
if: env.PUSH == 'true'

ci/rebase-branch.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ WORKTREE_DIR=$(mktemp -d)
394394
REPORT_FILE="$WORKTREE_DIR/conflict-report.md"
395395
trap 'git worktree remove --force "$WORKTREE_DIR"' EXIT
396396

397+
# Output worktree path early so recovery steps can find it on failure
398+
if test -n "$GITHUB_OUTPUT"; then
399+
echo "worktree=$WORKTREE_DIR" >>"$GITHUB_OUTPUT"
400+
fi
401+
397402
# Extract local branch name from origin/shears/foo -> shears/foo
398403
LOCAL_BRANCH=${SHEARS_BRANCH#origin/}
399404

@@ -468,8 +473,9 @@ PARENT_COUNT=$(git rev-list --parents -1 "$MARKER_IN_RESULT" | wc -w)
468473
test "$PARENT_COUNT" -eq 3 || # commit itself + 2 parents
469474
die "Marker should have 2 parents, found $((PARENT_COUNT - 1))"
470475

471-
# Generate range-diff
472-
RANGE_DIFF=$(git range-diff "$OLD_UPSTREAM..$OLD_MARKER^2" "$NEW_UPSTREAM..$MARKER_IN_RESULT^2" || echo "Unable to generate range-diff")
476+
# Generate range-diff (always use markers as base, never upstream branches)
477+
# MARKER_IN_RESULT^2 is the old tip (saved as second parent of new marker)
478+
RANGE_DIFF=$(git range-diff "$OLD_MARKER..$MARKER_IN_RESULT^2" "$MARKER_IN_RESULT..HEAD" || echo "Unable to generate range-diff")
473479

474480
# Annotate range-diff with upstream OIDs for skipped commits
475481
if test -s "$SKIPPED_MAP_FILE"; then
@@ -500,9 +506,8 @@ echo "Rebase completed: $(git rev-parse --short HEAD)"
500506
cat "$REPORT_FILE"
501507
echo "To push: cd $WORKTREE_DIR && git push --force origin HEAD:${SHEARS_BRANCH##*/}"
502508

503-
# For GitHub Actions: output variables
509+
# For GitHub Actions: output variables (worktree already output early)
504510
if test -n "$GITHUB_OUTPUT"; then
505-
echo "worktree=$WORKTREE_DIR" >>"$GITHUB_OUTPUT"
506511
echo "report=$REPORT_FILE" >>"$GITHUB_OUTPUT"
507512
echo "head=$(git rev-parse HEAD)" >>"$GITHUB_OUTPUT"
508513
fi

0 commit comments

Comments
 (0)