-
Notifications
You must be signed in to change notification settings - Fork 6
529 lines (458 loc) · 19.2 KB
/
release.yml
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
name: Release
on:
push:
branches:
- dev
- main
permissions:
contents: write
jobs:
# Check for package changes
check-package-changes:
runs-on: ubuntu-latest
outputs:
lasereyes_changed: ${{ steps.check.outputs.lasereyes_changed }}
lasereyes_core_changed: ${{ steps.check.outputs.lasereyes_core_changed }}
lasereyes_react_changed: ${{ steps.check.outputs.lasereyes_react_changed }}
lasereyes_vue_changed: ${{ steps.check.outputs.lasereyes_vue_changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch all branches
run: git fetch --all
- name: Determine diff comparison strategy
id: diff-strategy
run: |
if [ "${{ github.ref }}" == "refs/heads/dev" ]; then
echo "diff_target=HEAD^1" >> $GITHUB_ENV
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "diff_target=HEAD^1" >> $GITHUB_ENV
fi
- name: Check if packages changed
id: check
run: |
diff_target=${{ env.diff_target }}
if git diff --name-only --diff-filter=AM $diff_target HEAD -- packages/lasereyes/ | grep -q '^packages/lasereyes/'; then
echo "lasereyes_changed=true" >> $GITHUB_ENV
echo "lasereyes_changed=true" >> $GITHUB_OUTPUT
else
echo "lasereyes_changed=false" >> $GITHUB_ENV
echo "lasereyes_changed=false" >> $GITHUB_OUTPUT
fi
if git diff --name-only --diff-filter=AM $diff_target HEAD -- packages/lasereyes-core/ | grep -q '^packages/lasereyes-core/'; then
echo "lasereyes_core_changed=true" >> $GITHUB_ENV
echo "lasereyes_core_changed=true" >> $GITHUB_OUTPUT
else
echo "lasereyes_core_changed=false" >> $GITHUB_ENV
echo "lasereyes_core_changed=false" >> $GITHUB_OUTPUT
fi
if git diff --name-only --diff-filter=AM $diff_target HEAD -- packages/lasereyes-react/ | grep -q '^packages/lasereyes-react/'; then
echo "lasereyes_react_changed=true" >> $GITHUB_ENV
echo "lasereyes_react_changed=true" >> $GITHUB_OUTPUT
else
echo "lasereyes_react_changed=false" >> $GITHUB_ENV
echo "lasereyes_react_changed=false" >> $GITHUB_OUTPUT
fi
if git diff --name-only --diff-filter=AM $diff_target HEAD -- packages/lasereyes-vue/ | grep -q '^packages/lasereyes-vue/'; then
echo "lasereyes_vue_changed=true" >> $GITHUB_ENV
echo "lasereyes_vue_changed=true" >> $GITHUB_OUTPUT
else
echo "lasereyes_vue_changed=false" >> $GITHUB_ENV
echo "lasereyes_vue_changed=false" >> $GITHUB_OUTPUT
fi
# Bump RC version in dev branch only if necessary, and skip if it's on the main branch
bump-rc-in-dev:
runs-on: ubuntu-latest
needs: check-package-changes
if: github.ref == 'refs/heads/dev' &&
(needs.check-package-changes.outputs.lasereyes_changed == 'true' ||
needs.check-package-changes.outputs.lasereyes_core_changed == 'true' ||
needs.check-package-changes.outputs.lasereyes_react_changed == 'true' ||
needs.check-package-changes.outputs.lasereyes_vue_changed == 'true')
environment: prod
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Setup pnpm
run: |
corepack enable
corepack prepare [email protected] --activate
- name: Install dependencies
run: pnpm install
- name: Create .npmrc file
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Bump versions sequentially if packages changed
run: |
# Bump lasereyes if any package has changed
if [[ "${{ needs.check-package-changes.outputs.lasereyes_changed }}" == "true" || \
"${{ needs.check-package-changes.outputs.lasereyes_core_changed }}" == "true" || \
"${{ needs.check-package-changes.outputs.lasereyes_react_changed }}" == "true" ]]; then
cd packages/lasereyes
pnpm version prerelease --preid=rc
cd ../..
fi
# Bump lasereyes-core if changed
if [[ "${{ needs.check-package-changes.outputs.lasereyes_core_changed }}" == "true" ]]; then
cd packages/lasereyes-core
pnpm version prerelease --preid=rc
cd ../..
fi
# Bump lasereyes-react if changed
if [[ "${{ needs.check-package-changes.outputs.lasereyes_react_changed }}" == "true" ]]; then
cd packages/lasereyes-react
pnpm version prerelease --preid=rc
cd ../..
fi
# Bump lasereyes-vue if changed
if [[ "${{ needs.check-package-changes.outputs.lasereyes_vue_changed }}" == "true" ]]; then
cd packages/lasereyes-vue
pnpm version prerelease --preid=rc
cd ../..
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Configure git user
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Commit RC version bumps for all packages
run: |
git add .
git commit -m "RC version bump for all changed packages"
git push origin dev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
promote-to-stable-in-main:
runs-on: ubuntu-latest
needs: check-package-changes
if: github.ref == 'refs/heads/main'
environment: prod
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Setup pnpm
run: |
corepack enable
corepack prepare [email protected] --activate
- name: Install dependencies
id: install_dependencies
run: pnpm install --no-frozen-lockfile
continue-on-error: true
- name: Build all packages
id: build_packages
run: pnpm build --filter="@omnisat*"
continue-on-error: true
# Set a flag if either critical step fails
- name: Check for failure in critical steps
if: steps.install_dependencies.outcome == 'failure' || steps.build_packages.outcome == 'failure'
run: echo "critical_failure=true" >> $GITHUB_ENV
- name: Create .npmrc file
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Skip the remaining steps if critical steps failed
- name: Promote lasereyes-core version
if: env.critical_failure != 'true' && needs.check-package-changes.outputs.lasereyes_core_changed == 'true'
run: |
cd packages/lasereyes-core
pnpm version patch
pnpm publish --access public --no-git-checks
cd ../..
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Promote lasereyes-react version
if: env.critical_failure != 'true' && needs.check-package-changes.outputs.lasereyes_react_changed == 'true'
run: |
cd packages/lasereyes-react
pnpm version patch
pnpm publish --access public --no-git-checks
cd ../..
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Promote lasereyes-vue version
if: env.critical_failure != 'true' && needs.check-package-changes.outputs.lasereyes_vue_changed == 'true'
run: |
cd packages/lasereyes-vue
pnpm version patch
pnpm publish --access public --no-git-checks
cd ../..
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Update dependencies in lasereyes package.json only if no critical failure
- name: Update dependencies in lasereyes package.json
if: env.critical_failure != 'true' && (needs.check-package-changes.outputs.lasereyes_core_changed == 'true' || needs.check-package-changes.outputs.lasereyes_react_changed == 'true')
run: |
CORE_VERSION=$(cd packages/lasereyes-core && node -p "require('./package.json').version")
REACT_VERSION=$(cd packages/lasereyes-react && node -p "require('./package.json').version")
echo "New lasereyes-core version: $CORE_VERSION"
echo "New lasereyes-react version: $REACT_VERSION"
cd packages/lasereyes
node -e "let pkg=require('./package.json'); pkg.dependencies['@omnisat/lasereyes-core']='$CORE_VERSION'; pkg.dependencies['@omnisat/lasereyes-react']='$REACT_VERSION'; require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2));"
cd ../..
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Promote lasereyes version
if: env.critical_failure != 'true' && (needs.check-package-changes.outputs.lasereyes_changed == 'true' || needs.check-package-changes.outputs.lasereyes_core_changed == 'true' || needs.check-package-changes.outputs.lasereyes_react_changed == 'true')
run: |
cd packages/lasereyes
pnpm version patch
pnpm publish --access public --no-git-checks
cd ../..
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Revert dependencies in lasereyes package.json for local development
if: needs.check-package-changes.outputs.lasereyes_core_changed == 'true' || needs.check-package-changes.outputs.lasereyes_react_changed == 'true'
continue-on-error: true
run: |
cd packages/lasereyes
node -e "let pkg=require('./package.json'); pkg.dependencies['@omnisat/lasereyes-core']='workspace:*'; pkg.dependencies['@omnisat/lasereyes-react']='workspace:*'; require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2));"
cd ../..
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit stable version bump for all changed packages
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git fetch --prune # Clean up stale references
git add .
git commit -m "Stable version bump for all changed packages"
git checkout main || git checkout -b main origin/main # Ensure main branch is checked out
git branch --set-upstream-to=origin/main main # Set upstream to avoid ambiguity
git push origin main:refs/heads/main # Push explicitly to main branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Revert merge if critical steps failed
if: env.critical_failure == 'true'
run: |
PREV_MAIN_COMMIT=$(git rev-parse main^1)
git reset --hard $PREV_MAIN_COMMIT
git push origin main --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Reopen PR from dev to main if critical steps failed
if: env.critical_failure == 'true'
run: |
PR_NUMBER=$(gh pr list --state closed --base main --head dev --limit 1 --json number --jq '.[0].number')
if [ -n "$PR_NUMBER" ]; then
gh pr reopen $PR_NUMBER
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Merge main into dev to sync branches
merge-main-into-dev:
runs-on: ubuntu-latest
needs:
- promote-to-stable-in-main
- generate-release-notes-main
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Setup pnpm
run: |
corepack enable
corepack prepare [email protected] --activate
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
- name: Configure git user
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Checkout dev branch
run: |
git checkout dev
git fetch origin
git merge -s recursive -X theirs origin/main || echo "Handled merge conflicts with 'theirs' strategy"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push merge to dev
run: |
git push origin dev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
bump-next-rc-in-dev:
runs-on: ubuntu-latest
needs:
- merge-main-into-dev
- check-package-changes
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: dev
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Setup pnpm
run: |
corepack enable
corepack prepare [email protected] --activate
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
# Debugging Step: Log the outputs to check if they're correctly set
- name: Log outputs from check-package-changes
run: |
echo "Lasereyes changed: ${{ needs.check-package-changes.outputs.lasereyes_changed }}"
echo "Lasereyes-core changed: ${{ needs.check-package-changes.outputs.lasereyes_core_changed }}"
echo "Lasereyes-react changed: ${{ needs.check-package-changes.outputs.lasereyes_react_changed }}"
echo "Lasereyes-react changed: ${{ needs.check-package-changes.outputs.lasereyes_vue_changed }}"
- name: Bump lasereyes version if any package changed
if: needs.check-package-changes.outputs.lasereyes_changed == 'true' ||
needs.check-package-changes.outputs.lasereyes_core_changed == 'true' ||
needs.check-package-changes.outputs.lasereyes_react_changed == 'true'
run: |
cd packages/lasereyes
pnpm version prerelease --preid=rc
- name: Bump lasereyes-core version if changed
if: needs.check-package-changes.outputs.lasereyes_core_changed == 'true'
run: |
cd packages/lasereyes-core
pnpm version prerelease --preid=rc
- name: Bump lasereyes-react version if changed
if: needs.check-package-changes.outputs.lasereyes_react_changed == 'true'
run: |
cd packages/lasereyes-react
pnpm version prerelease --preid=rc
- name: Bump lasereyes-vue version if changed
if: needs.check-package-changes.outputs.lasereyes_vue_changed == 'true'
run: |
cd packages/lasereyes-vue
pnpm version prerelease --preid=rc
- name: Configure git user
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Commit RC version bumps for all packages
if: needs.check-package-changes.outputs.lasereyes_changed == 'true' ||
needs.check-package-changes.outputs.lasereyes_core_changed == 'true' ||
needs.check-package-changes.outputs.lasereyes_react_changed == 'true' ||
needs.check-package-changes.outputs.lasereyes_vue_changed == 'true'
run: |
git add .
git commit -m "Next RC version bump for all changed packages"
git push origin dev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
generate-release-notes-dev:
runs-on: ubuntu-latest
needs: bump-rc-in-dev
if: github.ref == 'refs/heads/dev'
continue-on-error: true
environment: prod
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install openai==0.28 requests
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- name: Generate git diff
run: |
PREV_COMMIT=$(git rev-parse HEAD^1)
git diff $PREV_COMMIT HEAD > changes.diff
- name: Extract new version
id: extract-version
run: |
NEW_VERSION=$(node -p "require('./packages/lasereyes/package.json').version")
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Generate release notes with GPT
run: |
set -e
python3 scripts/generate_release_notes.py ${{ env.NEW_VERSION }}
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
# Generate and commit release notes for the main branch
generate-release-notes-main:
runs-on: ubuntu-latest
needs: promote-to-stable-in-main
if: github.ref == 'refs/heads/main'
continue-on-error: true
environment: prod
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install openai==0.28 requests
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- name: Generate git diff
run: |
PREV_COMMIT=$(git rev-parse HEAD^1)
git diff $PREV_COMMIT HEAD > changes.diff
- name: Extract new version
id: extract-version
run: |
NEW_VERSION=$(node -p "require('./packages/lasereyes/package.json').version")
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Generate release notes with GPT
run: |
set -e
python3 scripts/generate_release_notes.py ${{ env.NEW_VERSION }}
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- name: Configure git user
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Commit and push release notes
run: |
echo -e "\n$(cat detailed_release_notes.md)\n$(cat RELEASE_NOTES.md)" > RELEASE_NOTES.md
git add RELEASE_NOTES.md
git commit -m "Updated RELEASE_NOTES.md with new release"
git pull origin main --rebase
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
uses: actions/create-release@v1
with:
tag_name: '${{ env.NEW_VERSION }}'
release_name: 'Release ${{ env.NEW_VERSION }}'
body_path: RELEASE_NOTES.md
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}