-
Notifications
You must be signed in to change notification settings - Fork 1
563 lines (500 loc) · 21.9 KB
/
release.yml
File metadata and controls
563 lines (500 loc) · 21.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
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
name: 'Release'
on:
workflow_dispatch:
push:
branches:
- 'preview/**'
- 'release/**'
paths:
- 'src/**'
permissions:
actions: read
pages: write
id-token: write
contents: write
concurrency:
group: release-${{ github.head_ref || github.ref }}
cancel-in-progress: false
env:
dotnet-sdk-version: '10.x'
build-configuration: 'Release'
build-platform: 'Any CPU'
git-version: '6.0.x'
test-result-directory: 'test-results'
nuget-packages-directory: 'nuget-packages'
jobs:
workflow-variables:
name: 'Set workflow variables'
runs-on: ubuntu-latest
outputs:
is-release: ${{ startsWith(github.ref_name, 'release') }}
is-preview: ${{ startsWith(github.ref_name, 'preview') }}
steps:
- name: 'Set workflow variables'
id: github
run: |
echo "is-release:${{ startsWith(github.ref_name, 'release') }}"
echo "is-preview:${{ startsWith(github.ref_name, 'preview') }}"
validate-release:
name: 'Validate release'
needs: [workflow-variables]
runs-on: ubuntu-latest
steps:
- name: 'Validate release branch'
if: ${{ needs.workflow-variables.outputs.is-release != 'true' && needs.workflow-variables.outputs.is-preview != 'true' }}
run: |
echo "This workflow can only be run on 'release/**' or 'preview/**' branches."
exit 1
versioning:
name: 'Extract version from branch'
runs-on: ubuntu-latest
needs: [workflow-variables, validate-release]
outputs:
friendly-version: ${{ steps.format-version.outputs.friendly-version }}
assembly-version: ${{ steps.format-version.outputs.assembly-version }}
assembly-informational-version: ${{ steps.format-version.outputs.assembly-informational-version }}
file-version: ${{ steps.format-version.outputs.file-version }}
release-version: ${{ steps.format-version.outputs.release-version }}
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
- name: 'Setup .NET ${{ env.dotnet-sdk-version }}'
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.dotnet-sdk-version }}
- name: 'Extract version from branch name'
id: extract-version
uses: './.github/actions/versioning/extract-version'
with:
branch-name: ${{ github.ref_name }}
- name: 'Create build number'
shell: bash
id: create-build-number
run: |
git fetch --unshallow --filter=tree:0
build_number=$(git rev-list --count origin/${{ github.ref_name }} ^origin/main)
echo "build-number=$build_number" >> $GITHUB_OUTPUT
- name: 'Create pre-release tag'
shell: bash
id: create-pre-release-tag
env:
build-number: ${{ steps.create-build-number.outputs.build-number }}
run: |
if [[ '${{ needs.workflow-variables.outputs.is-release }}' == 'true' ]]; then
echo "pre-release-tag=" >> $GITHUB_OUTPUT
elif [[ '${{ needs.workflow-variables.outputs.is-preview }}' == 'true' ]]; then
pre_release_tag='preview'
echo "pre-release-tag=$pre_release_tag" >> $GITHUB_OUTPUT
else
pre_release_tag=$(echo ${{ github.ref_name }} | tr '/' '-' | tr '.' '-'| tr '_' '-')
echo "pre-release-tag=$pre_release_tag" >> $GITHUB_OUTPUT
fi
- name: 'Format version'
id: format-version
uses: ./.github/actions/versioning/format-version
with:
version: ${{ steps.extract-version.outputs.version }}
patch: ${{ github.run_number }}
build-number: ${{ steps.create-build-number.outputs.build-number }}
sha: ${{ github.sha }}
pre-release-tag: ${{ steps.create-pre-release-tag.outputs.pre-release-tag }}
build:
name: 'Compile source code'
needs: [workflow-variables, versioning, validate-release]
runs-on: ubuntu-latest
env:
assembly-version: ${{ needs.versioning.outputs.assembly-version }}
assembly-informational-version: ${{ needs.versioning.outputs.assembly-informational-version }}
file-version: ${{ needs.versioning.outputs.file-version }}
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
- name: 'Compile source code'
uses: ./.github/actions/source/compile
with:
project-path: '**/PolylineAlgorithm.csproj'
assembly-version: ${{ env.assembly-version }}
assembly-informational-version: ${{ env.assembly-informational-version }}
file-version: ${{ env.file-version }}
treat-warnings-as-error: ${{ needs.workflow-variables.outputs.is-release }}
test:
name: 'Run tests'
needs: [build, validate-release]
runs-on: ubuntu-latest
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
- name: 'Setup .NET'
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.dotnet-sdk-version }}
- name: 'Run tests'
uses: ./.github/actions/testing/test
with:
project-path: './tests/PolylineAlgorithm.Tests/PolylineAlgorithm.Tests.csproj'
test-results-directory: '${{ runner.temp }}/${{ env.test-result-directory }}/'
code-coverage-settings-file: '${{ github.workspace}}/code-coverage-settings.xml'
- name: 'Generate test report'
uses: ./.github/actions/testing/test-report
id: test-report
with:
test-result-folder: '${{ runner.temp }}/${{ env.test-result-directory }}/'
- name: Write test report summary
run: cat ${{ steps.test-report.outputs.test-report-file }} >> $GITHUB_STEP_SUMMARY
- name: 'Generate code coverage'
uses: ./.github/actions/testing/code-coverage
id: code-coverage-report
with:
test-result-folder: '${{ runner.temp }}/${{ env.test-result-directory }}/'
- name: Write code coverage report summary
run: cat ${{ steps.code-coverage-report.outputs.code-coverage-report-file }} >> $GITHUB_STEP_SUMMARY
update-api-unshipped:
name: 'Update PublicAPI.Unshipped.txt'
needs: [workflow-variables, validate-release]
# Run even when build fails — the build may fail solely because a dropped preview API is still
# listed in Unshipped.txt (RS0017). This job fixes exactly that, so it must not be gated on build.
if: ${{ needs.workflow-variables.outputs.is-preview == 'true' && needs.validate-release.result == 'success' }}
runs-on: ubuntu-latest
steps:
- name: 'Checkout ${{ github.ref }}'
uses: actions/checkout@v6
- name: 'Setup .NET'
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.dotnet-sdk-version }}
- name: 'Snapshot PublicAPI.Shipped.txt'
shell: bash
run: cp src/PolylineAlgorithm/PublicAPI.Shipped.txt src/PolylineAlgorithm/PublicAPI.Shipped.txt.bak
- name: 'Sync PublicAPI.Unshipped.txt (add new + remove dropped preview APIs)'
shell: bash
run: dotnet format analyzers src/PolylineAlgorithm/PolylineAlgorithm.csproj --diagnostics RS0016 RS0017
- name: 'Guard against accidental shipped API removal'
shell: bash
run: |
SHIPPED="src/PolylineAlgorithm/PublicAPI.Shipped.txt"
if ! diff -q "$SHIPPED" "$SHIPPED.bak" > /dev/null 2>&1; then
echo "::error::Breaking change detected — a shipped API was removed from PublicAPI.Shipped.txt."
echo "::error::This requires a major version bump. Reverting the unintended change."
cp "$SHIPPED.bak" "$SHIPPED"
exit 1
fi
rm -f "$SHIPPED.bak"
- name: 'Configure git identity'
uses: './.github/actions/git/configure-identity'
- name: 'Commit and push updated API files'
shell: bash
run: |
git add src/PolylineAlgorithm/PublicAPI.Unshipped.txt
git diff --staged --quiet || (
git commit -m "Sync PublicAPI.Unshipped.txt (add new, remove dropped preview APIs)" &&
git pull --rebase origin ${{ github.ref_name }} &&
git push
)
promote-api-files:
name: 'Promote PublicAPI files (Unshipped -> Shipped)'
needs: [workflow-variables, test, validate-release]
if: ${{ needs.workflow-variables.outputs.is-release == 'true' }}
runs-on: ubuntu-latest
steps:
- name: 'Checkout ${{ github.ref }}'
uses: actions/checkout@v6
- name: 'Promote Unshipped.txt into Shipped.txt'
shell: bash
run: |
UNSHIPPED="src/PolylineAlgorithm/PublicAPI.Unshipped.txt"
SHIPPED="src/PolylineAlgorithm/PublicAPI.Shipped.txt"
# Append every non-blank, non-header line from Unshipped into Shipped
tail -n +2 "$UNSHIPPED" | grep -v '^[[:space:]]*$' >> "$SHIPPED" || true
# Reset Unshipped to just the nullable-enable header (with BOM to match convention)
printf '\xef\xbb\xbf#nullable enable\n' > "$UNSHIPPED"
- name: 'Configure git identity'
uses: './.github/actions/git/configure-identity'
- name: 'Commit and push promoted API files'
shell: bash
run: |
git add src/PolylineAlgorithm/PublicAPI.Shipped.txt src/PolylineAlgorithm/PublicAPI.Unshipped.txt
git diff --staged --quiet || (
git commit -m "Promote PublicAPI.Unshipped.txt into PublicAPI.Shipped.txt for release" &&
git pull --rebase origin ${{ github.ref_name }} &&
git push
)
pack:
name: 'Package binaries'
needs: [versioning, build, test, validate-release]
runs-on: ubuntu-latest
env:
assembly-version: ${{ needs.versioning.outputs.assembly-version }}
assembly-informational-version: ${{ needs.versioning.outputs.assembly-informational-version }}
file-version: ${{ needs.versioning.outputs.file-version }}
release-version: ${{ needs.versioning.outputs.release-version }}
package-artifact-name: package
outputs:
package-artifact-name: ${{ env.package-artifact-name }}
steps:
- name: 'Checkout ${{ github.base_ref }}'
uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.dotnet-sdk-version }}
- name: Download Build
uses: actions/download-artifact@v8
with:
name: build
- name: Pack with .NET
run: |
dotnet pack ${{ vars.SRC_DEFAULT_GLOB_PATTERN }} --configuration ${{ env.build-configuration }} /p:Platform="${{ env.build-platform }}" /p:PackageVersion=${{ env.release-version }} /p:Version=${{ env.assembly-version }} /p:AssemblyInformationalVersion=${{ env.assembly-informational-version }} /p:FileVersion=${{ env.file-version }} --output ${{ runner.temp }}/${{ env.nuget-packages-directory }}
- name: Upload Package
uses: actions/upload-artifact@v7
with:
name: ${{ env.package-artifact-name }}
path: |
${{ runner.temp }}/${{ env.nuget-packages-directory }}/**/*.nupkg
${{ runner.temp }}/${{ env.nuget-packages-directory }}/**/*.snupkg
benchmark:
name: Benchmark with .NET CLI on ${{ matrix.os }}
needs: [workflow-variables, build, validate-release]
if: ${{ needs.workflow-variables.outputs.is-release == 'true' || vars.BENCHMARKDOTNET_RUN_OVERRIDE == 'true' }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
- name: Install .NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.x
10.x
- name: Download Build
uses: actions/download-artifact@v8
with:
name: build
- name: Benchmark
working-directory: ${{ vars.BENCHMARKDOTNET_WORKING_DIRECTORY }}
run: dotnet run --configuration ${{ env.build-configuration }} /p:Platform=${{ env.build-platform }} --framework ${{ vars.DEFAULT_BUILD_FRAMEWORK }} --runtimes ${{ vars.BENCHMARKDOTNET_RUNTIMES }} --filter ${{ vars.BENCHMARKDOTNET_FILTER }} --artifacts ${{ runner.temp }}/benchmarks/ --exporters GitHub --memory --iterationTime 100 --join
- name: Upload Benchmark Results
uses: actions/upload-artifact@v7
with:
name: benchmark-${{ matrix.os }}
path: |
${{ runner.temp }}/benchmarks/**/*-report-github.md
- name: Write Benchmark Summary
shell: bash
run: cat **/*-report-github.md > $GITHUB_STEP_SUMMARY
working-directory: ${{ runner.temp }}/benchmarks/
publish-documentation:
name: 'Publish documentation'
needs: [pack, benchmark, validate-release, workflow-variables]
if: ${{ needs.workflow-variables.outputs.is-release == 'true' }}
uses: ./.github/workflows/publish-documentation.yml
permissions:
actions: read
pages: write
id-token: write
publish-package:
name: 'Publish package'
needs: [pack, validate-release, publish-documentation, update-api-unshipped, promote-api-files]
if: |
always() &&
needs.pack.result == 'success' &&
needs.validate-release.result == 'success' &&
(needs.publish-documentation.result == 'success' || needs.publish-documentation.result == 'skipped') &&
(needs.promote-api-files.result == 'success' || needs.promote-api-files.result == 'skipped') &&
(needs.update-api-unshipped.result == 'success' || needs.update-api-unshipped.result == 'skipped')
env:
package-artifact-name: ${{ needs.pack.outputs.package-artifact-name }}
runs-on: ubuntu-latest
environment: 'NuGet'
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.dotnet-sdk-version }}
- name: 'Publish package to Azure Artifact feed'
uses: ./.github/actions/nuget/publish-package
with:
package-artifact-name: ${{ env.package-artifact-name }}
nuget-feed-url: ${{ vars.NUGET_PACKAGE_FEED_URL }}
nuget-feed-api-key: ${{ secrets.NUGET_PACKAGE_FEED_API_KEY }}
nuget-feed-server: 'NuGet'
working-directory: ${{ runner.temp }}/${{ env.nuget-packages-directory }}
dotnet-sdk-version: ${{ env.dotnet-sdk-version }}'
release:
name: 'Create release'
needs: [workflow-variables, publish-package, validate-release, versioning]
runs-on: ubuntu-latest
env:
release-version: ${{ needs.versioning.outputs.release-version }}
is-preview: ${{ needs.workflow-variables.outputs.is-preview }}
notes-start-tag: ${{ needs.workflow-variables.outputs.notes-start-tag }}
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
with:
fetch-tags: true
- name: 'Determine notes start tag'
id: determine-notes-start-tag
run: |
notes_start_tag=$(git describe --abbrev=0 --tags 2>/dev/null || echo "")
echo "notes-start-tag=$notes_start_tag" >> $GITHUB_OUTPUT
shell: bash
- name: 'Create GitHub Release'
uses: ./.github/actions/github/create-release
with:
release-version: ${{ env.release-version }}
is-preview: ${{ env.is-preview }}
notes-start-tag: ${{ steps.determine-notes-start-tag.outputs.notes-start-tag }}
update-changelog:
name: 'Update CHANGELOG.md'
needs: [workflow-variables, release, versioning]
if: ${{ needs.workflow-variables.outputs.is-release == 'true' }}
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
release-version: ${{ needs.versioning.outputs.release-version }}
steps:
- name: 'Checkout ${{ github.ref }}'
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
- name: 'Fetch release notes'
shell: bash
run: |
gh release view ${{ env.release-version }} --json body --jq '.body' > /tmp/release-notes.txt
- name: 'Prepend entry to CHANGELOG.md'
shell: bash
run: |
release_date=$(date -u +%Y-%m-%d)
{
echo "## ${{ env.release-version }} — ${release_date}"
echo ""
cat /tmp/release-notes.txt
echo ""
} > /tmp/new-entry.txt
awk '
/<!-- New entries are prepended automatically by the release workflow. -->/ {
print
print ""
while ((getline line < "/tmp/new-entry.txt") > 0) print line
close("/tmp/new-entry.txt")
next
}
{ print }
' CHANGELOG.md > /tmp/changelog-new.md
mv /tmp/changelog-new.md CHANGELOG.md
- name: 'Configure git identity'
uses: './.github/actions/git/configure-identity'
- name: 'Commit and push CHANGELOG.md'
shell: bash
run: |
git add CHANGELOG.md
git diff --staged --quiet || (
git commit -m "Update CHANGELOG.md for ${{ env.release-version }}" &&
git pull --rebase origin ${{ github.ref_name }} &&
git push
)
- name: 'Write changelog summary'
shell: bash
run: |
echo "✅ CHANGELOG.md updated for **${{ env.release-version }}**." >> $GITHUB_STEP_SUMMARY
merge-to-main:
name: 'Merge ${{ github.ref_name }} into main'
needs: [workflow-variables, release, versioning, update-changelog]
if: ${{ needs.workflow-variables.outputs.is-release == 'true' }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
env:
GH_TOKEN: ${{ github.token }}
current-branch: ${{ github.ref_name }}
current-version: ${{ needs.versioning.outputs.friendly-version }}
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: 'Detect if current branch is the latest release'
id: detect-latest
run: |
git fetch origin
latest_version=$(git ls-remote --heads origin 'release/*' | grep -oP 'release/\K\d+\.\d+' | sort -V | tail -1)
current_version=$(echo "${{ env.current-version }}" | grep -oP '^\d+\.\d+')
echo "Latest release branch version: $latest_version"
echo "Current version (normalized): $current_version"
if [[ "$latest_version" == "$current_version" ]]; then
echo "is-latest=true" >> $GITHUB_OUTPUT
else
echo "is-latest=false" >> $GITHUB_OUTPUT
fi
- name: 'Check if PR to main already exists'
id: check-pr
if: ${{ steps.detect-latest.outputs.is-latest == 'true' }}
run: |
pr_count=$(gh pr list --head "${{ env.current-branch }}" --base main --state open --limit 1 --json id --jq '. | length')
if [[ $pr_count -gt 0 ]]; then
echo "pr-exists=true" >> $GITHUB_OUTPUT
else
echo "pr-exists=false" >> $GITHUB_OUTPUT
fi
- name: 'Create PR: Merge ${{ env.current-branch }} into main'
if: ${{ steps.detect-latest.outputs.is-latest == 'true' && steps.check-pr.outputs.pr-exists == 'false' }}
run: |
gh pr create \
--title "Merge ${{ env.current-branch }} into main" \
--fill \
--base main \
--head "${{ env.current-branch }}"
- name: 'Write merge summary'
run: |
if [[ "${{ steps.detect-latest.outputs.is-latest }}" == "true" ]]; then
echo "✅ PR created to merge **${{ env.current-branch }}** into **main**." >> $GITHUB_STEP_SUMMARY
else
echo "⏭️ Skipped merge to main: **${{ env.current-branch }}** is not the highest release branch." >> $GITHUB_STEP_SUMMARY
fi
create-support-branch:
name: 'Create support branch for ${{ github.ref_name }}'
needs: [workflow-variables, release, versioning]
if: ${{ needs.workflow-variables.outputs.is-release == 'true' }}
runs-on: ubuntu-latest
env:
current-version: ${{ needs.versioning.outputs.friendly-version }}
steps:
- name: 'Checkout ${{ github.head_ref || github.ref }}'
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: 'Resolve support branch name'
id: resolve-support-branch
run: |
major_minor=$(echo "${{ env.current-version }}" | grep -oP '^\d+\.\d+')
echo "support-branch=support/$major_minor" >> $GITHUB_OUTPUT
- name: 'Check if support branch already exists'
id: check-support-branch
run: |
git fetch origin
if git ls-remote --exit-code --heads origin "${{ steps.resolve-support-branch.outputs.support-branch }}" > /dev/null 2>&1; then
echo "support-branch-exists=true" >> $GITHUB_OUTPUT
else
echo "support-branch-exists=false" >> $GITHUB_OUTPUT
fi
- name: 'Configure git identity'
if: ${{ steps.check-support-branch.outputs.support-branch-exists == 'false' }}
uses: './.github/actions/git/configure-identity'
- name: 'Create support branch'
if: ${{ steps.check-support-branch.outputs.support-branch-exists == 'false' }}
run: |
git checkout -b "${{ steps.resolve-support-branch.outputs.support-branch }}"
git push --set-upstream origin "${{ steps.resolve-support-branch.outputs.support-branch }}"
- name: 'Write support branch summary'
run: |
if [[ "${{ steps.check-support-branch.outputs.support-branch-exists }}" == "false" ]]; then
echo "✅ Created support branch **${{ steps.resolve-support-branch.outputs.support-branch }}**." >> $GITHUB_STEP_SUMMARY
else
echo "⏭️ Support branch **${{ steps.resolve-support-branch.outputs.support-branch }}** already exists." >> $GITHUB_STEP_SUMMARY
fi