-
Notifications
You must be signed in to change notification settings - Fork 1
380 lines (317 loc) · 11.9 KB
/
js.yml
File metadata and controls
380 lines (317 loc) · 11.9 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
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
name: JavaScript CI/CD
on:
push:
branches:
- main
paths:
- 'js/**'
- 'scripts/**'
- '.github/workflows/js.yml'
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'js/**'
- 'scripts/**'
- '.github/workflows/js.yml'
workflow_dispatch:
inputs:
release_mode:
description: 'Manual release mode'
required: true
type: choice
default: 'instant'
options:
- instant
- changeset-pr
bump_type:
description: 'Manual release type'
required: true
type: choice
options:
- patch
- minor
- major
description:
description: 'Manual release description (optional)'
required: false
type: string
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
# Changeset check - only runs on PRs
changeset-check:
name: Check for Changesets
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install dependencies
working-directory: ./js
run: npm install
- name: Check for changesets
run: |
# Skip changeset check for automated version PRs
if [[ "${{ github.head_ref }}" == "changeset-release/"* ]]; then
echo "Skipping changeset check for automated release PR"
exit 0
fi
# Run changeset validation script
node scripts/validate-changeset.mjs
# Test JavaScript
test-js:
name: Test JavaScript
runs-on: ubuntu-latest
needs: [changeset-check]
if: always() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.changeset-check.result == 'success')
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Install clink
run: dotnet tool install --global clink
- name: Verify clink installation
run: clink --version
- name: Install dependencies
working-directory: ./js
run: npm install
- name: Create test data directories
run: |
mkdir -p ./js/data
mkdir -p ./data/auth-data/users
mkdir -p ./data/menu-items
mkdir -p ./js/backend/monolith/data/auth-data
mkdir -p ./js/tests
- name: Run tests
working-directory: ./js
run: npm test
# Release JavaScript - only runs on main after tests pass
release-js:
name: Release JavaScript
runs-on: ubuntu-latest
needs: [test-js]
if: always() && github.ref == 'refs/heads/main' && github.event_name == 'push' && needs.test-js.result == 'success'
permissions:
contents: write
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
working-directory: ./js
run: npm install
- name: Check for changesets
id: check_changesets
run: |
# Count changeset files (excluding README.md and config.json)
CHANGESET_COUNT=$(find js/.changeset -name "*.md" ! -name "README.md" | wc -l)
echo "Found $CHANGESET_COUNT changeset file(s)"
echo "has_changesets=$([[ $CHANGESET_COUNT -gt 0 ]] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
- name: Version packages and commit to main
if: steps.check_changesets.outputs.has_changesets == 'true'
id: version
run: |
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Get current version before bump
OLD_VERSION=$(node -p "require('./js/package.json').version")
echo "Current version: $OLD_VERSION"
# Run changeset version to bump versions and update CHANGELOG
cd js && npm run changeset:version && cd ..
# Get new version after bump
NEW_VERSION=$(node -p "require('./js/package.json').version")
echo "New version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
# Check if there are changes to commit
if [[ -n $(git status --porcelain) ]]; then
echo "Changes detected, committing..."
# Stage all changes (package.json, package-lock.json, CHANGELOG.md, deleted changesets)
git add -A
# Commit with version number as message
git commit -m "$NEW_VERSION" \
-m "" \
-m "🤖 Generated with [Claude Code](https://claude.com/claude-code)"
# Push directly to main
git push origin main
echo "✅ Version bump committed and pushed to main"
echo "version_committed=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit"
echo "version_committed=false" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
if: steps.version.outputs.version_committed == 'true'
id: publish
run: |
# Pull the latest changes we just pushed
git pull origin main
# Publish to npm
cd js && npm run changeset:publish
echo "published=true" >> $GITHUB_OUTPUT
# Get published version
PUBLISHED_VERSION=$(node -p "require('./js/package.json').version")
echo "published_version=$PUBLISHED_VERSION" >> $GITHUB_OUTPUT
echo "✅ Published @link-foundation/links-client@$PUBLISHED_VERSION to npm"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: steps.publish.outputs.published == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.publish.outputs.published_version }}"
TAG="v$VERSION"
echo "Creating GitHub release for $TAG..."
# Extract changelog entry for this version
# Read from CHANGELOG.md between this version header and the next version header
if [ -f js/CHANGELOG.md ]; then
RELEASE_NOTES=$(awk "/## $VERSION/{flag=1; next} /## [0-9]/{flag=0} flag" js/CHANGELOG.md)
fi
if [ -z "$RELEASE_NOTES" ]; then
RELEASE_NOTES="Release $VERSION"
fi
# Create release
gh release create "$TAG" \
--title "$VERSION" \
--notes "$RELEASE_NOTES" \
--repo ${{ github.repository }}
echo "✅ Created GitHub release: $TAG"
# Manual Instant Release - triggered via workflow_dispatch with instant mode
instant-release:
name: Instant Release
if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'instant'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
working-directory: ./js
run: npm install
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Bump version
id: version
run: |
cd js
# Get current version
OLD_VERSION=$(node -p "require('./package.json').version")
echo "Current version: $OLD_VERSION"
# Bump version based on bump_type
npm version ${{ github.event.inputs.bump_type }} --no-git-tag-version
# Get new version
NEW_VERSION=$(node -p "require('./package.json').version")
echo "New version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
cd ..
# Commit changes
git add -A
git commit -m "$NEW_VERSION" \
-m "" \
-m "${{ github.event.inputs.description || 'Manual release' }}" \
-m "" \
-m "🤖 Generated with [Claude Code](https://claude.com/claude-code)"
git push origin main
echo "version_committed=true" >> $GITHUB_OUTPUT
- name: Publish to npm
if: steps.version.outputs.version_committed == 'true'
id: publish
run: |
cd js && npm publish --access public
echo "published=true" >> $GITHUB_OUTPUT
echo "published_version=${{ steps.version.outputs.new_version }}" >> $GITHUB_OUTPUT
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: steps.publish.outputs.published == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.version.outputs.new_version }}"
TAG="v$VERSION"
gh release create "$TAG" \
--title "$VERSION" \
--notes "${{ github.event.inputs.description || 'Manual release' }}" \
--repo ${{ github.repository }}
# Manual Changeset PR - creates a pull request with the changeset for review
changeset-pr:
name: Create Changeset PR
if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'changeset-pr'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install dependencies
working-directory: ./js
run: npm install
- name: Create changeset file
run: |
CHANGESET_ID=$(date +%s | md5sum | head -c 8)
CHANGESET_FILE="js/.changeset/${CHANGESET_ID}.md"
cat > "$CHANGESET_FILE" << EOF
---
'@link-foundation/links-client': ${{ github.event.inputs.bump_type }}
---
${{ github.event.inputs.description || 'Manual release' }}
EOF
echo "Created changeset: $CHANGESET_FILE"
cat "$CHANGESET_FILE"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: add changeset for manual ${{ github.event.inputs.bump_type }} release'
branch: changeset-manual-release-${{ github.run_id }}
delete-branch: true
title: 'chore: manual ${{ github.event.inputs.bump_type }} release'
body: |
## Manual Release Request
This PR was created by a manual workflow trigger to prepare a **${{ github.event.inputs.bump_type }}** release.
### Release Details
- **Type:** ${{ github.event.inputs.bump_type }}
- **Description:** ${{ github.event.inputs.description || 'Manual release' }}
- **Triggered by:** @${{ github.actor }}
### Next Steps
1. Review the changeset in this PR
2. Merge this PR to main
3. The automated release workflow will create a version PR
4. Merge the version PR to publish to npm and create a GitHub release