forked from kooshi/llama-swappo
-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (130 loc) · 5.54 KB
/
sync-upstream.yml
File metadata and controls
150 lines (130 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Sync Upstream
on:
schedule:
# Run daily at 2 AM UTC - adjust as needed
- cron: '0 2 * * *'
workflow_dispatch: # Allows manual triggering
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Add upstream remote
run: |
git remote add upstream https://github.com/mostlygeek/llama-swap.git || true
git fetch upstream
- name: Update upstream-main branch
run: |
git checkout -B upstream-main upstream/main
git push origin upstream-main --force
- name: Attempt rebase onto upstream
id: rebase
run: |
git checkout main
git pull origin main
# Check if there are any new upstream changes
UPSTREAM_COMMIT=$(git rev-parse upstream-main)
CURRENT_BASE=$(git merge-base main upstream-main)
if [ "$UPSTREAM_COMMIT" = "$CURRENT_BASE" ]; then
echo "rebase_result=no_changes" >> $GITHUB_OUTPUT
echo "No new changes from upstream"
else
# Try to rebase main onto upstream-main
if git rebase upstream-main; then
git push origin main --force-with-lease
echo "rebase_result=success" >> $GITHUB_OUTPUT
echo "Successfully rebased onto upstream changes"
else
# Rebase failed due to conflicts
git rebase --abort
echo "rebase_result=conflict" >> $GITHUB_OUTPUT
echo "Rebase conflicts detected"
fi
fi
- name: Create issue on conflict
if: steps.rebase.outputs.rebase_result == 'conflict'
uses: actions/github-script@v7
with:
script: |
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['upstream-sync-conflict'],
state: 'open'
});
if (issues.length === 0) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🚨 Upstream Sync Conflict Detected',
body: |
## Rebase Conflict Detected
The automated upstream sync has detected rebase conflicts that require manual resolution.
**What happened:**
- Upstream changes were fetched successfully
- The `upstream-main` branch has been updated
- Attempting to rebase `main` onto `upstream-main` resulted in conflicts
**Next steps:**
1. Pull the latest changes: `git pull origin main`
2. Start the rebase: `git rebase upstream-main`
3. Resolve the conflicts manually in each conflicted file
4. Stage the resolved files: `git add .`
5. Continue the rebase: `git rebase --continue`
6. Push the rebased branch: `git push origin main --force-with-lease`
7. Close this issue
**Branches:**
- `main`: Your current branch with custom changes
- `upstream-main`: Latest changes from upstream llama-swap
This issue will auto-close when the next successful sync completes.
labels: ['upstream-sync-conflict', 'needs-attention']
});
}
- name: Close conflict issues on success
if: steps.rebase.outputs.rebase_result == 'success'
uses: actions/github-script@v7
with:
script: |
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['upstream-sync-conflict'],
state: 'open'
});
for (const issue of issues) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: '✅ Upstream sync successful! Conflicts have been resolved. Closing this issue.'
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
}
- name: Summary
run: |
echo "## Sync Summary" >> $GITHUB_STEP_SUMMARY
echo "- Upstream remote: ✅ Updated" >> $GITHUB_STEP_SUMMARY
echo "- upstream-main branch: ✅ Updated" >> $GITHUB_STEP_SUMMARY
case "${{ steps.rebase.outputs.rebase_result }}" in
"success")
echo "- Rebase to main: ✅ Success" >> $GITHUB_STEP_SUMMARY
;;
"no_changes")
echo "- Rebase to main: ℹ️ No new changes" >> $GITHUB_STEP_SUMMARY
;;
"conflict")
echo "- Rebase to main: ⚠️ Conflicts detected - manual intervention required" >> $GITHUB_STEP_SUMMARY
;;
esac