Skip to content

Commit 7ad09b0

Browse files
authored
Update auto-merge-to-main.yml
1 parent d6b229b commit 7ad09b0

1 file changed

Lines changed: 44 additions & 126 deletions

File tree

Lines changed: 44 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
name: "🚀 Auto-merge Development Main"
1+
name: Auto-merge Development to Main
22

33
on:
44
workflow_run:
55
workflows:
66
- "Cross-Platform Sanity Check"
7-
- "🔍 Package Discovery Demo - Omnipkg Intelligence"
8-
- "🌌 LIVE - Quantum Python Auto-Switch Test"
9-
- "🧪 Flask Port Finder & Auto-Healing Test"
10-
- "🔥 Live NumPy/SciPy Hot-Swapping"
11-
- "🔥 LIVE - Python Library Hot-Swap"
12-
- "💥 Nuclear Test: TensorFlow Dependency Hot-Swap"
13-
- "⬆️ LIVE - Package Upgrade Test"
14-
- "🔄 LIVE - Omnipkg Self-Upgrade Test"
15-
- "🌍 Omnipkg Multi-Language Intelligence Demo"
16-
- "🌠 LIVE - Omnipkg Quantum Multiverse Warp (FINAL)"
7+
- "Package Discovery Demo - Omnipkg Intelligence"
8+
- "LIVE - Quantum Python Auto-Switch Test"
9+
- "Flask Port Finder & Auto-Healing Test"
10+
- "Live NumPy/SciPy Hot-Swapping"
11+
- "LIVE - Python Library Hot-Swap"
12+
- "Nuclear Test: TensorFlow Dependency Hot-Swap"
13+
- "LIVE - Package Upgrade Test"
14+
- "LIVE - Omnipkg Self-Upgrade Test"
15+
- "Omnipkg Multi-Language Intelligence Demo"
16+
- "LIVE - Omnipkg Quantum Multiverse Warp (FINAL)"
1717
- "Package Manager Comparison Test"
18-
- "🍎 macOS - Omnipkg Demo Test (CI - No Redis)"
19-
- "🚀 Windows - Omnipkg Demo Test (CI - No Redis)"
18+
- "macOS - Omnipkg Demo Test (CI - No Redis)"
19+
- "Windows - Omnipkg Demo Test (CI - No Redis)"
2020
- "Omnipkg True First-Run Test (Windows)"
21-
- "🔄 UV Self-Downgrades Auto-Revert"
21+
- "UV Self-Downgrades Auto-Revert"
2222
- "Simple UV Multi-Version Test"
2323
- "Old Rich Test"
2424
- "Simple Python Adoption Test"
25-
- "🎪 Demo Matrix Test (All Demos)"
25+
- "Demo Matrix Test (All Demos)"
2626
types:
2727
- completed
2828
branches:
@@ -31,178 +31,96 @@ on:
3131
permissions:
3232
contents: write
3333
actions: read
34-
issues: write
3534

36-
# Prevents two merges from happening at the same time
3735
concurrency:
3836
group: auto-merge-main
3937
cancel-in-progress: false
4038

4139
jobs:
42-
check-and-merge:
40+
auto-merge:
4341
runs-on: ubuntu-latest
4442
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'development'
4543

4644
steps:
47-
- uses: actions/checkout@v3
45+
- name: Checkout
46+
uses: actions/checkout@v3
4847
with:
4948
fetch-depth: 0
5049
token: ${{ secrets.GITHUB_TOKEN }}
5150

52-
- name: Configure git
51+
- name: Configure Git
5352
run: |
5453
git config user.name "github-actions[bot]"
5554
git config user.email "github-actions[bot]@users.noreply.github.com"
5655
57-
- name: Analyze Workflow Status
58-
id: check_all
56+
- name: Check All Workflows Passed
57+
id: check
5958
run: |
6059
COMMIT_SHA="${{ github.event.workflow_run.head_sha }}"
61-
SHORT_SHA=$(echo $COMMIT_SHA | cut -c1-7)
62-
echo "📊 Analyzing commit: $SHORT_SHA"
6360
64-
# Get all workflow runs for this specific commit
6561
gh run list \
6662
--branch development \
6763
--commit $COMMIT_SHA \
68-
--json conclusion,status,name \
69-
--limit 200 > runs.json
70-
71-
# Calculate stats
72-
TOTAL=$(jq '. | length' runs.json)
73-
SUCCESS=$(jq '[.[] | select(.conclusion == "success")] | length' runs.json)
74-
SKIPPED=$(jq '[.[] | select(.conclusion == "skipped" or .conclusion == "neutral")] | length' runs.json)
75-
IN_PROGRESS=$(jq '[.[] | select(.status == "in_progress" or .status == "queued" or .status == "waiting")] | length' runs.json)
76-
FAILED=$(jq '[.[] | select(.conclusion == "failure" or .conclusion == "timed_out" or .conclusion == "cancelled")] | length' runs.json)
64+
--json conclusion,status \
65+
--limit 100 > runs.json
7766
78-
EFFECTIVE_PASS=$((SUCCESS + SKIPPED))
67+
TOTAL=$(jq 'length' runs.json)
68+
SUCCESS=$(jq '[.[] | select(.conclusion == "success" or .conclusion == "skipped")] | length' runs.json)
69+
IN_PROGRESS=$(jq '[.[] | select(.status == "in_progress" or .status == "queued")] | length' runs.json)
70+
FAILED=$(jq '[.[] | select(.conclusion == "failure")] | length' runs.json)
7971
80-
echo "📊 Stats for commit $SHORT_SHA:"
81-
echo " Total workflows: $TOTAL"
82-
echo " ✅ Success: $SUCCESS"
83-
echo " ⏭️ Skipped: $SKIPPED"
84-
echo " ⏳ In Progress: $IN_PROGRESS"
85-
echo " ❌ Failed: $FAILED"
86-
echo ""
72+
echo "Total: $TOTAL, Success: $SUCCESS, In Progress: $IN_PROGRESS, Failed: $FAILED"
8773
88-
# 1. If anything is still running, wait for the last workflow to trigger merge
8974
if [ "$IN_PROGRESS" -gt 0 ]; then
90-
echo "Workflows still running. Waiting for completion..."
75+
echo "Workflows still running, skipping merge"
9176
echo "should_merge=false" >> $GITHUB_OUTPUT
9277
exit 0
9378
fi
9479
95-
# 2. If anything failed, block merge
9680
if [ "$FAILED" -gt 0 ]; then
97-
echo "❌ Some workflows failed. Not merging."
98-
echo "Failed workflows:"
99-
jq -r '.[] | select(.conclusion == "failure" or .conclusion == "timed_out" or .conclusion == "cancelled") | " - \(.name): \(.conclusion)"' runs.json
81+
echo "Some workflows failed, skipping merge"
10082
echo "should_merge=false" >> $GITHUB_OUTPUT
10183
exit 0
10284
fi
10385
104-
# 3. Safety check: Ensure we ran enough tests (at least 5)
105-
if [ "$EFFECTIVE_PASS" -lt 5 ]; then
106-
echo "⚠️ Too few workflows completed ($EFFECTIVE_PASS/5). Possible CI issue."
86+
if [ "$SUCCESS" -lt 5 ]; then
87+
echo "Not enough workflows passed, skipping merge"
10788
echo "should_merge=false" >> $GITHUB_OUTPUT
10889
exit 0
10990
fi
11091
111-
echo "All $EFFECTIVE_PASS workflows passed! Ready to merge."
92+
echo "All workflows passed"
11293
echo "should_merge=true" >> $GITHUB_OUTPUT
11394
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
114-
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
11595
env:
11696
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11797

118-
- name: Check if already merged
119-
if: steps.check_all.outputs.should_merge == 'true'
98+
- name: Check Not Already Merged
99+
if: steps.check.outputs.should_merge == 'true'
120100
id: check_merged
121101
run: |
122-
COMMIT_SHA="${{ steps.check_all.outputs.commit_sha }}"
123-
SHORT_SHA="${{ steps.check_all.outputs.short_sha }}"
124-
102+
COMMIT_SHA="${{ steps.check.outputs.commit_sha }}"
125103
git fetch origin main
126104
127-
# Check if this commit (or its ancestors) are already in main
128105
if git merge-base --is-ancestor $COMMIT_SHA origin/main; then
129-
echo "Commit $SHORT_SHA is already in main. Nothing to do."
106+
echo "Commit already in main"
130107
echo "already_merged=true" >> $GITHUB_OUTPUT
131108
else
132-
echo "📝 Commit $SHORT_SHA not yet in main. Proceeding with merge."
109+
echo "Commit not yet merged"
133110
echo "already_merged=false" >> $GITHUB_OUTPUT
134111
fi
135112
136-
- name: Merge development into main
137-
if: steps.check_all.outputs.should_merge == 'true' && steps.check_merged.outputs.already_merged == 'false'
113+
- name: Merge to Main
114+
if: steps.check.outputs.should_merge == 'true' && steps.check_merged.outputs.already_merged == 'false'
138115
run: |
139-
COMMIT_SHA="${{ steps.check_all.outputs.commit_sha }}"
140-
SHORT_SHA="${{ steps.check_all.outputs.short_sha }}"
141-
142-
echo "🔄 Merging development (up to $SHORT_SHA) into main..."
116+
COMMIT_SHA="${{ steps.check.outputs.commit_sha }}"
117+
SHORT_SHA=$(echo $COMMIT_SHA | cut -c1-7)
143118
144-
# Switch to main and update
145119
git checkout main
146120
git pull origin main
147-
148-
# Fetch latest development
149121
git fetch origin development
150122
151-
# Merge the commit (this brings all ancestor commits too!)
152-
WORKFLOW_COUNT=$(jq '. | length' runs.json)
153-
154-
if git merge $COMMIT_SHA --no-ff -m "Auto-merge: development → main ($SHORT_SHA)
155-
156-
All CI checks passed for commit $SHORT_SHA.
157-
158-
✅ Workflows completed: $WORKFLOW_COUNT
159-
📦 Merged by: GitHub Actions
160-
🔗 Triggered by: ${{ github.event.workflow_run.name }}"; then
161-
162-
echo "✅ Merge successful!"
163-
164-
# Push to main
165-
git push origin main
166-
167-
echo "🚀 Successfully merged to main!"
168-
169-
else
170-
echo "❌ Merge conflict detected!"
171-
git merge --abort
172-
173-
# Create issue for manual resolution
174-
gh issue create \
175-
--title "🚨 Auto-merge Failed: Conflict in $SHORT_SHA" \
176-
--body "## Merge Conflict Detected
177-
178-
Commit [$SHORT_SHA](https://github.com/${{ github.repository }}/commit/$COMMIT_SHA) passed all CI tests but has merge conflicts with main.
179-
180-
**Manual intervention required:**
181-
182-
\`\`\`bash
183-
git checkout main
184-
git pull origin main
185-
git merge $COMMIT_SHA
186-
# Resolve conflicts
187-
git commit
188-
git push origin main
189-
\`\`\`
190-
191-
**Or rebase development on main:**
192-
193-
\`\`\`bash
194-
git checkout development
195-
git pull origin development
196-
git rebase origin/main
197-
# Resolve conflicts
198-
git push --force-with-lease origin development
199-
\`\`\`
200-
201-
Once resolved, this workflow will retry automatically." \
202-
--label "auto-merge-conflict" \
203-
--label "needs-manual-merge"
204-
205-
exit 1
206-
fi
123+
git merge $COMMIT_SHA --no-ff -m "Auto-merge development to main ($SHORT_SHA)" -m "All CI checks passed"
124+
git push origin main
207125
env:
208126
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)