-
Notifications
You must be signed in to change notification settings - Fork 0
457 lines (402 loc) · 15.2 KB
/
release.yml
File metadata and controls
457 lines (402 loc) · 15.2 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
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
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
release_mode:
description: 'Release mode'
required: true
default: 'changeset'
type: choice
options:
- changeset
- instant
- changeset-pr
bump_type:
description: 'Version bump type (for instant mode or changeset-pr)'
required: false
default: 'patch'
type: choice
options:
- patch
- minor
- major
description:
description: 'Change description (for changeset-pr mode)'
required: false
type: string
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
JAVA_VERSION: '21'
JAVA_DISTRIBUTION: 'temurin'
jobs:
# =============================================================================
# Detect Changes - determines which jobs should run
# =============================================================================
detect-changes:
name: Detect Changes
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch'
outputs:
java-changed: ${{ steps.changes.outputs.java-changed }}
pom-changed: ${{ steps.changes.outputs.pom-changed }}
mjs-changed: ${{ steps.changes.outputs.mjs-changed }}
docs-changed: ${{ steps.changes.outputs.docs-changed }}
workflow-changed: ${{ steps.changes.outputs.workflow-changed }}
any-code-changed: ${{ steps.changes.outputs.any-code-changed }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Detect changes
id: changes
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: bun scripts/detect-code-changes.mjs
# =============================================================================
# Lint and Format Check
# Runs independently of changeset-check - it's a fast check that should always run
# See: https://github.com/link-foundation/js-ai-driven-development-pipeline-template/pull/18
# =============================================================================
lint:
name: Lint & Format
runs-on: ubuntu-latest
needs: [detect-changes]
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' ||
needs.detect-changes.outputs.java-changed == 'true' ||
needs.detect-changes.outputs.pom-changed == 'true' ||
needs.detect-changes.outputs.mjs-changed == 'true' ||
needs.detect-changes.outputs.docs-changed == 'true' ||
needs.detect-changes.outputs.workflow-changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
cache: maven
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Check code formatting (Spotless)
run: mvn spotless:check -B
- name: Run SpotBugs static analysis
run: mvn spotbugs:check -B
- name: Check file sizes
run: bun scripts/check-file-size.mjs
# =============================================================================
# Build and Test
# =============================================================================
test:
name: Test (Java ${{ matrix.java }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: [detect-changes, changeset-check]
# Run if: push event, workflow_dispatch, OR changeset-check succeeded, OR changeset-check was skipped (docs-only PR)
if: always() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.changeset-check.result == 'success' || needs.changeset-check.result == 'skipped')
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
java: ['21']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
cache: maven
- name: Run tests with coverage
run: mvn test jacoco:report -B
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.java == '21'
uses: codecov/codecov-action@v4
with:
file: target/site/jacoco/jacoco.xml
flags: unittests
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# =============================================================================
# Build Package
# =============================================================================
build:
name: Build Package
runs-on: ubuntu-latest
needs: [lint, test]
# Run only if lint and test succeeded (handles skipped lint gracefully)
if: always() && (needs.lint.result == 'success' || needs.lint.result == 'skipped') && needs.test.result == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
cache: maven
- name: Build with Maven
run: mvn package -DskipTests -B
- name: Verify JAR contents
run: |
echo "=== JAR contents ==="
jar tf target/*.jar | head -50
echo "..."
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
target/*.jar
target/site/jacoco/
retention-days: 7
# =============================================================================
# Changeset Validation (PRs only, skipped for docs-only changes)
# Docs-only PRs (./docs folder, markdown files) don't require changesets
# =============================================================================
changeset-check:
name: Changeset Check
runs-on: ubuntu-latest
needs: [detect-changes]
if: github.event_name == 'pull_request' && needs.detect-changes.outputs.any-code-changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Validate changeset
run: bun scripts/validate-changeset.mjs
env:
GITHUB_BASE_REF: ${{ github.base_ref }}
# =============================================================================
# Auto Release (on push to main with changesets)
# =============================================================================
auto-release:
name: Auto Release
runs-on: ubuntu-latest
needs: [build]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
cache: maven
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Check for changesets
id: changesets
run: |
CHANGESET_COUNT=$(find .changeset -name "*.md" ! -name "README.md" 2>/dev/null | wc -l)
echo "count=$CHANGESET_COUNT" >> $GITHUB_OUTPUT
if [ "$CHANGESET_COUNT" -gt 0 ]; then
echo "has_changesets=true" >> $GITHUB_OUTPUT
echo "Found $CHANGESET_COUNT changeset(s)"
else
echo "has_changesets=false" >> $GITHUB_OUTPUT
echo "No changesets found"
fi
- name: Merge changesets (if multiple)
if: steps.changesets.outputs.has_changesets == 'true' && steps.changesets.outputs.count > 1
run: bun scripts/merge-changesets.mjs
- name: Run version and commit script
if: steps.changesets.outputs.has_changesets == 'true'
id: release
run: bun scripts/version-and-commit.mjs --mode changeset
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build release artifacts
if: steps.release.outputs.released == 'true'
run: mvn package source:jar javadoc:jar -DskipTests -B
- name: Create GitHub Release
if: steps.release.outputs.released == 'true'
run: |
bun scripts/create-github-release.mjs \
--release-version "${{ steps.release.outputs.new_version }}" \
--repository "${{ github.repository }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload release artifacts
if: steps.release.outputs.released == 'true'
run: |
TAG="v${{ steps.release.outputs.new_version }}"
gh release upload "$TAG" target/*.jar --clobber || true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# =============================================================================
# Manual Release - Changeset Mode (workflow dispatch)
# =============================================================================
manual-release-changeset:
name: Manual Release (Changeset)
runs-on: ubuntu-latest
needs: [build]
if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'changeset'
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
cache: maven
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Merge changesets (if multiple)
run: bun scripts/merge-changesets.mjs
- name: Run version and commit script
id: release
run: bun scripts/version-and-commit.mjs --mode changeset
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build release artifacts
if: steps.release.outputs.released == 'true'
run: mvn package source:jar javadoc:jar -DskipTests -B
- name: Create GitHub Release
if: steps.release.outputs.released == 'true'
run: |
bun scripts/create-github-release.mjs \
--release-version "${{ steps.release.outputs.new_version }}" \
--repository "${{ github.repository }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload release artifacts
if: steps.release.outputs.released == 'true'
run: |
TAG="v${{ steps.release.outputs.new_version }}"
gh release upload "$TAG" target/*.jar --clobber || true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# =============================================================================
# Manual Release - Instant Mode (workflow dispatch)
# =============================================================================
manual-release-instant:
name: Manual Release (Instant)
runs-on: ubuntu-latest
needs: [build]
if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'instant'
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
cache: maven
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Run version and commit script
id: release
run: bun scripts/version-and-commit.mjs --mode instant --bump-type ${{ inputs.bump_type }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build release artifacts
if: steps.release.outputs.released == 'true'
run: mvn package source:jar javadoc:jar -DskipTests -B
- name: Create GitHub Release
if: steps.release.outputs.released == 'true'
run: |
bun scripts/create-github-release.mjs \
--release-version "${{ steps.release.outputs.new_version }}" \
--repository "${{ github.repository }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload release artifacts
if: steps.release.outputs.released == 'true'
run: |
TAG="v${{ steps.release.outputs.new_version }}"
gh release upload "$TAG" target/*.jar --clobber || true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# =============================================================================
# Manual Changeset PR (workflow dispatch)
# =============================================================================
changeset-pr:
name: Create Changeset PR
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'changeset-pr'
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Create changeset file
run: |
DESCRIPTION="${{ inputs.description }}"
if [ -z "$DESCRIPTION" ]; then
DESCRIPTION="Manual release"
fi
bun scripts/create-manual-changeset.mjs \
--bump-type "${{ inputs.bump_type }}" \
--description "$DESCRIPTION"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: add changeset for ${{ inputs.bump_type }} release"
branch: changeset-manual-release-${{ github.run_id }}
delete-branch: true
title: "chore: ${{ inputs.bump_type }} release changeset"
body: |
## Summary
This PR adds a changeset for a **${{ inputs.bump_type }}** release.
${{ inputs.description }}
---
*This PR was automatically created by the changeset-pr workflow.*
labels: |
release
automated