Skip to content

Commit 0c06432

Browse files
Copilotkasperpeulen
andcommitted
Update workflow to run automatically on branch pushes and verify results
Co-authored-by: kasperpeulen <1035299+kasperpeulen@users.noreply.github.com>
1 parent 5aba505 commit 0c06432

File tree

1 file changed

+82
-9
lines changed

1 file changed

+82
-9
lines changed

.github/workflows/reset-upstream-main.yml

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: 🔄 Reset upstream-main Branch
22

33
on:
4+
push:
5+
branches:
6+
- copilot/reset-upstream-main-branch
47
workflow_dispatch:
58
inputs:
69
target_commit:
@@ -14,10 +17,17 @@ on:
1417
permissions:
1518
contents: write
1619

20+
env:
21+
DEFAULT_TARGET_COMMIT: 'bac7bd445d5d4c7c602399a842518f40ec591f2d'
22+
1723
jobs:
1824
reset-branch:
1925
name: Reset upstream-main to target commit
2026
runs-on: ubuntu-22.04
27+
# Only run on push events, or on workflow_dispatch with confirmation
28+
if: |
29+
github.event_name == 'push' ||
30+
(github.event_name == 'workflow_dispatch' && github.event.inputs.confirm == 'confirm')
2131
2232
steps:
2333
- name: ⬇️ Checkout repo
@@ -26,17 +36,20 @@ jobs:
2636
fetch-depth: 0 # Fetch all history for all branches
2737
token: ${{ secrets.GITHUB_TOKEN }}
2838

29-
- name: 🔐 Validate confirmation
39+
- name: 🎯 Set target commit
40+
id: set-target
3041
run: |
31-
if [ "${{ github.event.inputs.confirm }}" != "confirm" ]; then
32-
echo "❌ Confirmation not provided. Please type 'confirm' to proceed."
33-
exit 1
42+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
43+
TARGET_COMMIT="${{ github.event.inputs.target_commit }}"
44+
else
45+
TARGET_COMMIT="${{ env.DEFAULT_TARGET_COMMIT }}"
3446
fi
35-
echo "✅ Confirmation received"
47+
echo "target_commit=$TARGET_COMMIT" >> $GITHUB_OUTPUT
48+
echo "Using target commit: $TARGET_COMMIT"
3649
3750
- name: 🔍 Verify target commit exists
3851
run: |
39-
TARGET_COMMIT="${{ github.event.inputs.target_commit }}"
52+
TARGET_COMMIT="${{ steps.set-target.outputs.target_commit }}"
4053
if ! git cat-file -e "$TARGET_COMMIT^{commit}"; then
4154
echo "❌ Target commit $TARGET_COMMIT does not exist"
4255
exit 1
@@ -46,13 +59,13 @@ jobs:
4659
4760
- name: 📊 Show commits to be removed
4861
run: |
49-
TARGET_COMMIT="${{ github.event.inputs.target_commit }}"
62+
TARGET_COMMIT="${{ steps.set-target.outputs.target_commit }}"
5063
echo "The following commits will be REMOVED from upstream-main:"
5164
git log --oneline "$TARGET_COMMIT..origin/upstream-main" || echo "No commits to remove (branch already at or before target)"
5265
5366
- name: 🔄 Reset upstream-main branch
5467
run: |
55-
TARGET_COMMIT="${{ github.event.inputs.target_commit }}"
68+
TARGET_COMMIT="${{ steps.set-target.outputs.target_commit }}"
5669
5770
# Configure git
5871
git config user.name "github-actions[bot]"
@@ -76,7 +89,7 @@ jobs:
7689
7790
- name: ✅ Verify reset
7891
run: |
79-
TARGET_COMMIT="${{ github.event.inputs.target_commit }}"
92+
TARGET_COMMIT="${{ steps.set-target.outputs.target_commit }}"
8093
8194
# Verify the remote branch
8295
REMOTE_SHA=$(git ls-remote origin upstream-main | awk '{print $1}')
@@ -91,3 +104,63 @@ jobs:
91104
echo ""
92105
echo "Latest commits on upstream-main:"
93106
git log --oneline upstream-main -5
107+
108+
verify-result:
109+
name: Verify upstream-main reset result
110+
runs-on: ubuntu-22.04
111+
needs: reset-branch
112+
if: always()
113+
114+
steps:
115+
- name: ⬇️ Checkout repo
116+
uses: actions/checkout@v4
117+
with:
118+
fetch-depth: 0
119+
120+
- name: 🔍 Check reset result
121+
run: |
122+
TARGET_COMMIT="${{ env.DEFAULT_TARGET_COMMIT }}"
123+
124+
# Fetch the latest state
125+
git fetch origin upstream-main
126+
127+
# Get the current commit on upstream-main
128+
CURRENT_SHA=$(git ls-remote origin upstream-main | awk '{print $1}')
129+
130+
echo "Target commit: $TARGET_COMMIT"
131+
echo "Current upstream-main: $CURRENT_SHA"
132+
echo ""
133+
134+
if [ "$CURRENT_SHA" = "$TARGET_COMMIT" ]; then
135+
echo "✅ VERIFICATION SUCCESS"
136+
echo "The upstream-main branch is correctly reset to $TARGET_COMMIT"
137+
echo ""
138+
echo "Commits on upstream-main:"
139+
git log --oneline "$CURRENT_SHA" -5
140+
exit 0
141+
else
142+
echo "❌ VERIFICATION FAILED"
143+
echo "The upstream-main branch is at $CURRENT_SHA but should be at $TARGET_COMMIT"
144+
echo ""
145+
echo "Difference:"
146+
git log --oneline "$TARGET_COMMIT..$CURRENT_SHA" 2>/dev/null || echo "Target is ahead of current"
147+
exit 1
148+
fi
149+
150+
- name: 📋 Job summary
151+
if: always()
152+
run: |
153+
TARGET_COMMIT="${{ env.DEFAULT_TARGET_COMMIT }}"
154+
CURRENT_SHA=$(git ls-remote origin upstream-main | awk '{print $1}')
155+
156+
echo "## Reset Verification Results" >> $GITHUB_STEP_SUMMARY
157+
echo "" >> $GITHUB_STEP_SUMMARY
158+
echo "- **Target commit**: \`$TARGET_COMMIT\`" >> $GITHUB_STEP_SUMMARY
159+
echo "- **Current commit**: \`$CURRENT_SHA\`" >> $GITHUB_STEP_SUMMARY
160+
echo "" >> $GITHUB_STEP_SUMMARY
161+
162+
if [ "$CURRENT_SHA" = "$TARGET_COMMIT" ]; then
163+
echo "✅ **Status**: Reset successful" >> $GITHUB_STEP_SUMMARY
164+
else
165+
echo "❌ **Status**: Reset failed or incomplete" >> $GITHUB_STEP_SUMMARY
166+
fi

0 commit comments

Comments
 (0)