forked from qwibitai/nanoclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (184 loc) · 6.76 KB
/
fork-sync-skills.yml
File metadata and controls
214 lines (184 loc) · 6.76 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Sync upstream & merge-forward skill branches
on:
# Triggered by upstream repo via repository_dispatch
repository_dispatch:
types: [upstream-main-updated]
# Fallback: run on a schedule in case dispatch isn't configured
schedule:
- cron: '0 */6 * * *' # every 6 hours
# Also run when fork's main is pushed directly
push:
branches: [main]
workflow_dispatch:
permissions:
contents: write
issues: write
concurrency:
group: fork-sync
cancel-in-progress: true
jobs:
sync-and-merge:
if: github.repository != 'qwibitai/nanoclaw'
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync with upstream main
id: sync
run: |
# Add upstream remote
git remote add upstream https://github.com/qwibitai/nanoclaw.git
git fetch upstream main
# Check if upstream has new commits
if git merge-base --is-ancestor upstream/main HEAD; then
echo "Already up to date with upstream main."
echo "synced=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Merge upstream main into fork's main
if ! git merge upstream/main --no-edit; then
echo "::error::Failed to merge upstream/main into fork main — conflicts detected"
git merge --abort
echo "synced=false" >> "$GITHUB_OUTPUT"
echo "sync_failed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# Validate build
npm ci
if ! npm run build; then
echo "::error::Build failed after merging upstream/main"
git reset --hard "origin/main"
echo "synced=false" >> "$GITHUB_OUTPUT"
echo "sync_failed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if ! npm test 2>/dev/null; then
echo "::error::Tests failed after merging upstream/main"
git reset --hard "origin/main"
echo "synced=false" >> "$GITHUB_OUTPUT"
echo "sync_failed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
git push origin main
echo "synced=true" >> "$GITHUB_OUTPUT"
- name: Merge main into skill branches
id: merge
run: |
# Re-fetch to pick up any changes pushed since job start
git fetch origin
FAILED=""
SUCCEEDED=""
# List all remote skill branches
SKILL_BRANCHES=$(git branch -r --list 'origin/skill/*' | sed 's|origin/||' | xargs)
if [ -z "$SKILL_BRANCHES" ]; then
echo "No skill branches found."
exit 0
fi
for BRANCH in $SKILL_BRANCHES; do
SKILL_NAME=$(echo "$BRANCH" | sed 's|skill/||')
echo ""
echo "=== Processing $BRANCH ==="
git checkout -B "$BRANCH" "origin/$BRANCH"
if ! git merge main --no-edit; then
echo "::warning::Merge conflict in $BRANCH"
git merge --abort
FAILED="$FAILED $SKILL_NAME"
continue
fi
# Check if there's anything new to push
if git diff --quiet "origin/$BRANCH"; then
echo "$BRANCH is already up to date with main."
SUCCEEDED="$SUCCEEDED $SKILL_NAME"
continue
fi
npm ci
if ! npm run build; then
echo "::warning::Build failed for $BRANCH"
git reset --hard "origin/$BRANCH"
FAILED="$FAILED $SKILL_NAME"
continue
fi
if ! npm test 2>/dev/null; then
echo "::warning::Tests failed for $BRANCH"
git reset --hard "origin/$BRANCH"
FAILED="$FAILED $SKILL_NAME"
continue
fi
git push origin "$BRANCH"
SUCCEEDED="$SUCCEEDED $SKILL_NAME"
echo "$BRANCH merged and pushed successfully."
done
echo ""
echo "=== Results ==="
echo "Succeeded: $SUCCEEDED"
echo "Failed: $FAILED"
echo "failed=$FAILED" >> "$GITHUB_OUTPUT"
echo "succeeded=$SUCCEEDED" >> "$GITHUB_OUTPUT"
- name: Open issue for upstream sync failure
if: steps.sync.outputs.sync_failed == 'true'
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Upstream sync failed — merge conflict or build failure`,
body: [
'The automated sync with `qwibitai/nanoclaw` main failed.',
'',
'This usually means upstream made changes that conflict with this fork\'s channel code.',
'',
'To resolve manually:',
'```bash',
'git fetch upstream main',
'git merge upstream/main',
'# resolve conflicts',
'npm run build && npm test',
'git push',
'```',
].join('\n'),
labels: ['upstream-sync']
});
- name: Open issue for failed skill merges
if: steps.merge.outputs.failed != ''
uses: actions/github-script@v7
with:
script: |
const failed = '${{ steps.merge.outputs.failed }}'.trim().split(/\s+/);
const body = [
`The merge-forward workflow failed to merge \`main\` into the following skill branches:`,
'',
...failed.map(s => `- \`skill/${s}\`: merge conflict, build failure, or test failure`),
'',
'Please resolve manually:',
'```bash',
...failed.map(s => [
`git checkout skill/${s}`,
`git merge main`,
`# resolve conflicts, then: git push`,
''
]).flat(),
'```',
].join('\n');
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Merge-forward failed for ${failed.length} skill branch(es)`,
body,
labels: ['skill-maintenance']
});