35
35
outputs :
36
36
k6_version : ${{ steps.get_k6_version.outputs.k6_version }}
37
37
go_version : ${{ steps.get_go_version.outputs.go_version }}
38
+ sign_windows_artifacts : ${{ steps.determine_windows_signing.outputs.sign_windows_artifacts }}
38
39
steps :
39
40
- name : Checkout code
40
41
uses : actions/checkout@v5
47
48
INPUT_K6_VERSION : ${{ github.event.inputs.k6_version }}
48
49
run : |
49
50
set -x # Show exactly what commands are executed
50
- if [[ "${{ github.event_name } }" == "workflow_dispatch" ]] && [[ "${INPUT_K6_VERSION}" != "" ]]; then
51
+ if [[ "${GITHUB_EVENT_NAME }" == "workflow_dispatch" ]] && [[ "${INPUT_K6_VERSION}" != "" ]]; then
51
52
VERSION="${INPUT_K6_VERSION}"
52
53
echo "Building custom dev build with version '${VERSION}' from manual workflow_dispatch..."
53
54
elif [[ "${GITHUB_REF}" =~ ^refs/tags/v.+$ ]]; then
65
66
INPUT_GO_VERSION : ${{ github.event.inputs.go_version }}
66
67
run : |
67
68
set -x # Show exactly what commands are executed
68
- if [[ "${{ github.event_name } }" == "workflow_dispatch" ]] && [[ "${INPUT_GO_VERSION}" != "" ]]; then
69
+ if [[ "${GITHUB_EVENT_NAME }" == "workflow_dispatch" ]] && [[ "${INPUT_GO_VERSION}" != "" ]]; then
69
70
GO_VERSION="${INPUT_GO_VERSION}"
70
71
echo "Using custom Go version '${GO_VERSION}' from manual workflow_dispatch..."
71
72
else
75
76
echo "GO_VERSION=${GO_VERSION}"
76
77
echo "go_version=${GO_VERSION}" >> $GITHUB_OUTPUT
77
78
79
+ # Secrets are unavailable when building from project forks, so this
80
+ # will fail for external PRs, even if we wanted to do it. And we don't.
81
+ # We are only going to sign packages that are built from the default branch
82
+ # or a version tag, or manually triggered dev builds, so we have enough
83
+ # assurance that package signing works, but don't sign every PR build.
84
+ - name : Determine whether to sign the Windows artifacts
85
+ id : determine_windows_signing
86
+ env :
87
+ SIGN_FILES : ${{ github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' }}
88
+ run : |
89
+ set -x # Show exactly what commands are executed
90
+ if [[ "${SIGN_FILES}" == "true" ]]; then
91
+ echo "Windows artifacts will be signed"
92
+ sign_windows_artifacts="true"
93
+ else
94
+ echo "Windows artifacts will not be signed"
95
+ sign_windows_artifacts="false"
96
+ fi
97
+ echo "sign_windows_artifacts=${sign_windows_artifacts}" >> ${GITHUB_OUTPUT}
98
+
78
99
build :
79
100
runs-on : ubuntu-latest
80
101
needs : [configure]
@@ -228,17 +249,111 @@ jobs:
228
249
-t $DOCKER_IMAGE_ID:latest-with-browser \
229
250
-t ghcr.io/$GHCR_IMAGE_ID:latest-with-browser .
230
251
231
- package-windows :
252
+ # Forks, PRs etc. won't actually sign the binary, but the workflow will run most of the same steps as
253
+ # GitHub Actions workflows don't support conditional `needs` so we have to run the signing step unconditionally.
254
+ sign-binaries :
232
255
permissions :
233
256
contents : read
234
257
actions : read
235
258
id-token : write # Required for Vault
236
259
260
+ env :
261
+ VERSION : ${{ needs.configure.outputs.k6_version }}
262
+
263
+ environment :
264
+ name : azure-trusted-signing
265
+
237
266
runs-on : windows-latest
238
267
defaults :
239
268
run :
240
269
shell : pwsh
241
270
needs : [configure, build]
271
+ outputs :
272
+ binary_artifact_name : ${{ steps.assign-artifact-names.outputs.binary-artifact-name }}
273
+ windows_binary_artifact_name : ${{ steps.assign-artifact-names.outputs.windows-binary-artifact-name }}
274
+ steps :
275
+ - name : Download binaries
276
+ uses : actions/download-artifact@v4
277
+ with :
278
+ name : binaries
279
+ path : dist
280
+
281
+ - name : Unzip Windows binary
282
+ run : |
283
+ Expand-Archive -Path ".\dist\k6-${env:VERSION}-windows-amd64.zip" -DestinationPath .\packaging\
284
+
285
+ - name : Upload artifact for Windows installer build
286
+ uses : actions/upload-artifact@v4
287
+ with :
288
+ name : windows-binary
289
+ path : ' packaging/k6-${{ env.VERSION }}-windows-amd64/k6.exe'
290
+ retention-days : 7
291
+ if-no-files-found : error
292
+
293
+ - name : Get secrets for Azure Trusted Signing
294
+ uses : grafana/shared-workflows/actions/get-vault-secrets@get-vault-secrets/v1.3.0
295
+ id : get-signing-secrets
296
+ if : needs.configure.outputs.sign_windows_artifacts == 'true'
297
+ with :
298
+ export_env : false
299
+ repo_secrets : |
300
+ client-id=azure-trusted-signing:client-id
301
+ subscription-id=azure-trusted-signing:subscription-id
302
+ tenant-id=azure-trusted-signing:tenant-id
303
+
304
+ - name : Sign Windows binary
305
+ uses : grafana/shared-workflows/actions/azure-trusted-signing@azure-trusted-signing/v1.0.0
306
+ id : sign-artifacts
307
+ if : needs.configure.outputs.sign_windows_artifacts == 'true'
308
+ with :
309
+ application-description : ' Grafana k6'
310
+ artifact-to-sign : ' windows-binary'
311
+ azure-client-id : ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).client-id }}
312
+ azure-subscription-id : ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).subscription-id }}
313
+ azure-tenant-id : ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).tenant-id }}
314
+ signed-artifact-name : ' windows-binary-signed'
315
+
316
+ - name : Download signed Windows binary
317
+ uses : actions/download-artifact@v4
318
+ if : needs.configure.outputs.sign_windows_artifacts == 'true'
319
+ with :
320
+ name : ${{ steps.sign-artifacts.outputs.artifact-name }}
321
+ path : ' packaging/k6-${{ env.VERSION }}-windows-amd64'
322
+
323
+ # Re-zip the signed Windows binary to replace the original unsigned version
324
+ - name : Zip signed Windows binary
325
+ if : needs.configure.outputs.sign_windows_artifacts == 'true'
326
+ run : |
327
+ Compress-Archive -Path ".\packaging\*" -DestinationPath ".\dist\k6-${env:VERSION}-windows-amd64.zip" -Force
328
+
329
+ - name : Upload signed artifacts
330
+ uses : actions/upload-artifact@v4
331
+ if : needs.configure.outputs.sign_windows_artifacts == 'true'
332
+ with :
333
+ name : binaries-signed
334
+ path : dist/
335
+ retention-days : 7
336
+ if-no-files-found : error
337
+
338
+ - name : Assign artifact name for Windows binary for installer build
339
+ id : assign-artifact-names
340
+ env :
341
+ BINARY_ARTIFACT_NAME : ${{ needs.configure.outputs.sign_windows_artifacts == 'true' && 'binaries-signed' || 'binaries' }}
342
+ WINDOWS_BINARY_ARTIFACT_NAME : ${{ needs.configure.outputs.sign_windows_artifacts == 'true' && steps.sign-artifacts.outputs.artifact-name || 'windows-binary' }}
343
+ run : |
344
+ echo "binary-artifact-name=${env:BINARY_ARTIFACT_NAME}" >> ${env:GITHUB_OUTPUT}
345
+ echo "windows-binary-artifact-name=${env:WINDOWS_BINARY_ARTIFACT_NAME}" >> ${env:GITHUB_OUTPUT}
346
+
347
+ package :
348
+ permissions :
349
+ contents : read
350
+ actions : read
351
+
352
+ runs-on : windows-latest
353
+ defaults :
354
+ run :
355
+ shell : pwsh
356
+ needs : [configure, build, sign-binaries]
242
357
env :
243
358
VERSION : ${{ needs.configure.outputs.k6_version }}
244
359
steps :
@@ -255,71 +370,93 @@ jobs:
255
370
curl -Lso wix311-binaries.zip https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip
256
371
Expand-Archive -Path .\wix311-binaries.zip -DestinationPath .\wix311\
257
372
echo "$pwd\wix311" | Out-File -FilePath $env:GITHUB_PATH -Append
258
- - name : Download binaries
373
+ - name : Download Windows binary
259
374
uses : actions/download-artifact@v5
260
375
with :
261
- name : binaries
262
- path : dist
263
- - name : Unzip Windows binary
264
- run : |
265
- Expand-Archive -Path ".\dist\k6-$env:VERSION-windows-amd64.zip" -DestinationPath .\packaging\
266
- move .\packaging\k6-$env:VERSION-windows-amd64\k6.exe .\packaging\
267
- rmdir .\packaging\k6-$env:VERSION-windows-amd64\
376
+ name : ${{ needs.sign-binaries.outputs.windows_binary_artifact_name }}
377
+ path : packaging
268
378
269
379
- name : Create the MSI package
270
380
run : |
271
381
$env:VERSION = $env:VERSION -replace 'v(\d+\.\d+\.\d+).*','$1'
272
382
pandoc -s -f markdown -t rtf -o packaging\LICENSE.rtf LICENSE.md
273
383
cd .\packaging
274
- candle.exe -arch x64 "-dVERSION=$env:VERSION" k6.wxs
384
+ candle.exe -arch x64 "-dVERSION=${ env:VERSION} " k6.wxs
275
385
light.exe -ext WixUIExtension k6.wixobj
276
-
277
- # GH secrets are unavailable when building from project forks, so this
278
- # will fail for external PRs, even if we wanted to do it. And we don't.
279
- # We are only going to sign packages that are built from master or a
280
- # version tag, or manually triggered dev builds, so we have enough
281
- # assurance that package signing works, but don't sign every PR build.
282
- - if : ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' }}
283
- uses : grafana/shared-workflows/actions/get-vault-secrets@get-vault-secrets/v1.3.0
284
- with :
285
- repo_secrets : |
286
- WIN_SIGN_CERT=winsign:WIN_SIGN_CERT
287
- WIN_SIGN_PASS=winsign:WIN_SIGN_PASS
288
-
289
- - name : Sign Windows binary and .msi package
290
- if : ${{ env.WIN_SIGN_CERT != '' && env.WIN_SIGN_PASS != '' }}
291
- run : |
292
- # Convert base64 certificate to PFX
293
- $bytes = [Convert]::FromBase64String("${{ env.WIN_SIGN_CERT }}")
294
- [IO.File]::WriteAllBytes("k6.pfx", $bytes)
295
-
296
- # Get the latest signtool executable
297
- $SignTool = Get-ChildItem -Path "${env:ProgramFiles(x86)}\Windows Kits\10\bin" -Recurse -Filter signtool.exe | Where-Object { $_.DirectoryName -like "*\x64" } | Sort-Object -Descending | Select-Object -First 1
298
-
299
- # Sign the Windows binary
300
- & $SignTool sign /f k6.pfx /p "${{ env.WIN_SIGN_PASS }}" /tr "http://timestamp.digicert.com" /td sha256 /fd sha256 "packaging\k6.exe"
301
-
302
- # Sign the MSI package
303
- & $SignTool sign /f k6.pfx /p "${{ env.WIN_SIGN_PASS }}" /tr "http://timestamp.digicert.com" /td sha256 /fd sha256 "packaging\k6.msi"
304
-
305
- # Cleanup signing artifacts
306
- del k6.pfx
307
386
308
387
- name : Rename MSI package
309
388
# To keep it consistent with the other artifacts
310
- run : move "packaging\k6.msi" "packaging\k6-$env:VERSION-windows-amd64.msi"
389
+ run : move "packaging\k6.msi" "packaging\k6-${ env:VERSION} -windows-amd64.msi"
311
390
312
- - name : Upload artifacts
391
+ - name : Upload Windows installer
313
392
uses : actions/upload-artifact@v4
314
393
with :
315
394
name : binaries-windows
316
395
path : |
317
396
packaging/k6-*.msi
318
397
retention-days : 7
398
+ if-no-files-found : error
399
+
400
+ # Forks, PRs etc. won't actually sign the installer, but the workflow will run most of the same steps as
401
+ # GitHub Actions workflows don't support conditional `needs` so we have to run the signing step unconditionally.
402
+ sign-packages :
403
+ permissions :
404
+ actions : read
405
+ contents : read
406
+ id-token : write # Required for Vault
407
+
408
+ environment :
409
+ name : azure-trusted-signing
410
+
411
+ outputs :
412
+ artifact_name : ${{ steps.assign-artifact-name.outputs.artifact-name }}
413
+
414
+ runs-on : windows-latest
415
+ defaults :
416
+ run :
417
+ shell : pwsh
418
+ needs : [configure, package]
419
+ steps :
420
+ - name : Download Windows artifacts
421
+ uses : actions/download-artifact@v4
422
+ if : needs.configure.outputs.sign_windows_artifacts == 'true'
423
+ with :
424
+ name : binaries-windows
425
+ path : packaging
426
+
427
+ - name : Get secrets for Azure Trusted Signing
428
+ uses : grafana/shared-workflows/actions/get-vault-secrets@get-vault-secrets/v1.3.0
429
+ id : get-signing-secrets
430
+ if : needs.configure.outputs.sign_windows_artifacts == 'true'
431
+ with :
432
+ export_env : false
433
+ repo_secrets : |
434
+ client-id=azure-trusted-signing:client-id
435
+ subscription-id=azure-trusted-signing:subscription-id
436
+ tenant-id=azure-trusted-signing:tenant-id
437
+
438
+ - name : Sign Windows installer
439
+ uses : grafana/shared-workflows/actions/azure-trusted-signing@azure-trusted-signing/v1.0.0
440
+ id : sign-artifacts
441
+ if : needs.configure.outputs.sign_windows_artifacts == 'true'
442
+ with :
443
+ application-description : ' Grafana k6'
444
+ artifact-to-sign : ' binaries-windows'
445
+ azure-client-id : ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).client-id }}
446
+ azure-subscription-id : ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).subscription-id }}
447
+ azure-tenant-id : ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).tenant-id }}
448
+ signed-artifact-name : ' binaries-windows-signed'
449
+
450
+ - name : Assign artifact name for Windows installer
451
+ id : assign-artifact-name
452
+ env :
453
+ ARTIFACT_NAME : ${{ needs.configure.outputs.sign_windows_artifacts == 'true' && steps.sign-artifacts.outputs.artifact-name || 'binaries-windows' }}
454
+ run : |
455
+ echo "artifact-name=${env:ARTIFACT_NAME}" >> ${env:GITHUB_OUTPUT}
319
456
320
457
publish-github :
321
458
runs-on : ubuntu-latest
322
- needs : [configure, build, package-windows ]
459
+ needs : [configure, sign-binaries, sign-packages ]
323
460
if : ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch' }}
324
461
env :
325
462
VERSION : ${{ needs.configure.outputs.k6_version }}
@@ -334,12 +471,12 @@ jobs:
334
471
- name : Download binaries
335
472
uses : actions/download-artifact@v5
336
473
with :
337
- name : binaries
474
+ name : ${{ needs.sign- binaries.outputs.binary_artifact_name }}
338
475
path : dist
339
476
- name : Download Windows binaries
340
477
uses : actions/download-artifact@v5
341
478
with :
342
- name : binaries-windows
479
+ name : ${{ needs.sign-packages.outputs.artifact_name }}
343
480
path : dist
344
481
- name : Generate checksum file
345
482
run : cd dist && sha256sum * > "k6-${VERSION}-checksums.txt"
@@ -363,7 +500,7 @@ jobs:
363
500
364
501
publish-packages :
365
502
runs-on : ubuntu-latest
366
- needs : [configure, build, package-windows ]
503
+ needs : [configure, sign-binaries, sign-packages ]
367
504
if : ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch' }}
368
505
env :
369
506
VERSION : ${{ needs.configure.outputs.k6_version }}
@@ -380,12 +517,12 @@ jobs:
380
517
- name : Download binaries
381
518
uses : actions/download-artifact@v5
382
519
with :
383
- name : binaries
520
+ name : ${{ needs.sign- binaries.outputs.binary_artifact_name }}
384
521
path : dist
385
522
- name : Download Windows binaries
386
523
uses : actions/download-artifact@v5
387
524
with :
388
- name : binaries-windows
525
+ name : ${{ needs.sign-packages.outputs.artifact_name }}
389
526
path : dist
390
527
- name : Rename binaries
391
528
# To be consistent with the filenames used in dl.k6.io
@@ -409,15 +546,15 @@ jobs:
409
546
- name : Setup docker compose environment
410
547
run : |
411
548
cat > packaging/.env <<EOF
412
- AWS_ACCESS_KEY_ID=${{ env. AWS_ACCESS_KEY_ID } }
413
- AWS_CF_DISTRIBUTION="${{ env. AWS_CF_DISTRIBUTION } }"
549
+ AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
550
+ AWS_CF_DISTRIBUTION="${AWS_CF_DISTRIBUTION}"
414
551
AWS_DEFAULT_REGION=us-east-2
415
- AWS_SECRET_ACCESS_KEY=${{ env. AWS_SECRET_ACCESS_KEY } }
416
- AWS_SESSION_TOKEN=${{ env. AWS_SESSION_TOKEN } }
417
- PGP_SIGN_KEY_PASSPHRASE=${{ env. PGP_SIGN_KEY_PASSPHRASE } }
418
- S3_BUCKET=${{ env. S3_BUCKET } }
552
+ AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
553
+ AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}
554
+ PGP_SIGN_KEY_PASSPHRASE=${PGP_SIGN_KEY_PASSPHRASE}
555
+ S3_BUCKET=${S3_BUCKET}
419
556
EOF
420
- echo "${{ env. PGP_SIGN_KEY } }" > packaging/sign-key.gpg
557
+ echo "${PGP_SIGN_KEY}" > packaging/sign-key.gpg
421
558
- name : Publish packages
422
559
env :
423
560
GITHUB_ACTOR : ${{ github.actor }}
0 commit comments