-
Notifications
You must be signed in to change notification settings - Fork 1.3k
369 lines (350 loc) · 14.3 KB
/
build.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
name: Build
on:
workflow_dispatch:
inputs:
k6_version:
description: 'The version of the release, it must use the semantic versioning format with the v prefix. It is a development release so it is suggested to append a build metadata (e.g. v0.38.0-dev).'
required: true
go_version:
description: 'Go version for building binaries'
default: '1.x'
required: true
push:
branches:
- master
tags:
- v*
pull_request:
defaults:
run:
shell: bash
env:
APP_NAME: "k6"
DOCKER_IMAGE_ID: "grafana/k6"
GHCR_IMAGE_ID: ${{ github.repository }}
DEFAULT_GO_VERSION: "1.22.x"
jobs:
configure:
runs-on: ubuntu-latest
outputs:
k6_version: ${{ steps.get_k6_version.outputs.k6_version }}
go_version: ${{ steps.get_go_version.outputs.go_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get the k6 version
id: get_k6_version
run: |
set -x # Show exactly what commands are executed
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ "${{ github.event.inputs.k6_version }}" != "" ]]; then
VERSION="${{ github.event.inputs.k6_version }}"
echo "Building custom dev build with version '${VERSION}' from manual workflow_dispatch..."
elif [[ "${GITHUB_REF}" =~ ^refs/tags/v.+$ ]]; then
VERSION="${GITHUB_REF##*/}"
echo "Building real version tag '${GITHUB_REF}', parsed '${VERSION}' as the actual version..."
else
VERSION="$(git describe --tags --always --long --dirty)"
echo "Building a non-version ref '${GITHUB_REF}', use '${VERSION}' as the version instead..."
fi
echo "VERSION=${VERSION}"
echo "k6_version=${VERSION}" >> $GITHUB_OUTPUT
- name: Get the used Go version
id: get_go_version
run: |
set -x # Show exactly what commands are executed
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ "${{ github.event.inputs.go_version }}" != "" ]]; then
GO_VERSION="${{ github.event.inputs.go_version }}"
echo "Using custom Go version '${GO_VERSION}' from manual workflow_dispatch..."
else
GO_VERSION="${DEFAULT_GO_VERSION}"
echo "Using the default Go version '${GO_VERSION}'..."
fi
echo "GO_VERSION=${GO_VERSION}"
echo "go_version=${GO_VERSION}" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: [configure]
env:
VERSION: ${{ needs.configure.outputs.k6_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ needs.configure.outputs.go_version }}
check-latest: true
- name: Install nfpm (dep and rpm package builder)
run: |
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]
- name: Install goversioninfo (.syso file creator)
run: |
go install github.com/josephspurrier/goversioninfo/cmd/[email protected]
- name: Generate Windows binary metadata (.syso files)
run: |
IFS=. read -a version_parts <<< "${VERSION#v}"
IFS=- read -a version_patch <<< "${version_parts[2]}"
# Need a blank versioninfo.json for the CLI overrides to work.
echo '{}' > versioninfo.json
set -x
goversioninfo -64 \
-platform-specific=true \
-charset="1200" \
-company="Raintank Inc. d.b.a. Grafana Labs" \
-copyright="© Raintank Inc. d.b.a. Grafana Labs. Licensed under AGPL." \
-description="A modern load testing tool, using Go and JavaScript" \
-icon=packaging/k6.ico \
-internal-name="k6" \
-original-name="k6.exe" \
-product-name="k6" \
-translation="0x0409" \
-ver-major="${version_parts[0]}" \
-ver-minor="${version_parts[1]}" \
-ver-patch="${version_patch[0]}" \
-special-build=$(IFS='-'; echo "${version_patch[*]:1}";) \
-product-version="${VERSION#v}"
set +x
ls -lah | grep -i syso
- name: Build
run: |
go version
./build-release.sh "dist" "${VERSION}"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binaries
path: dist/
retention-days: 7
build-docker:
runs-on: ubuntu-latest
needs: [configure]
env:
VERSION: ${{ needs.configure.outputs.k6_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build
run: |
docker buildx create \
--name multibuilder \
--platform linux/amd64,linux/arm64 \
--bootstrap --use
docker buildx build \
--target release \
--platform linux/amd64,linux/arm64 \
-t $DOCKER_IMAGE_ID .
- name: Check
run: |
docker buildx build --load -t $DOCKER_IMAGE_ID .
# Assert that simple cases works for the new built image
docker run $DOCKER_IMAGE_ID version
docker run $DOCKER_IMAGE_ID --help
docker run $DOCKER_IMAGE_ID help
docker run $DOCKER_IMAGE_ID run --help
docker run $DOCKER_IMAGE_ID inspect --help
docker run $DOCKER_IMAGE_ID status --help
docker run $DOCKER_IMAGE_ID stats --help
docker run $DOCKER_IMAGE_ID scale --help
docker run $DOCKER_IMAGE_ID pause --help
docker run $DOCKER_IMAGE_ID resume --help
- name: Log into registries (ghcr.io and Docker Hub)
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
run: |
# Log into GitHub Container Registry
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
# Log into Docker Hub Registry
echo "${{ secrets.DOCKER_PASS }}" | docker login -u "${{ secrets.DOCKER_USER }}" --password-stdin
- name: Publish k6:master images
if: ${{ github.ref == 'refs/heads/master' }}
run: |
echo "Publish $GHCR_IMAGE_ID:master* images"
docker buildx build --push \
--target release \
--platform linux/amd64,linux/arm64 \
-t $DOCKER_IMAGE_ID:master \
-t ghcr.io/$GHCR_IMAGE_ID:master .
docker buildx build --push \
--target with-browser \
--platform linux/amd64,linux/arm64 \
-t $DOCKER_IMAGE_ID:master-with-browser \
-t ghcr.io/$GHCR_IMAGE_ID:master-with-browser .
- name: Publish tagged version images
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
VERSION="${VERSION#v}"
echo "Publish $GHCR_IMAGE_ID:$VERSION images"
docker buildx build --push \
--target release \
--platform linux/amd64,linux/arm64 \
-t $DOCKER_IMAGE_ID:$VERSION \
-t ghcr.io/$GHCR_IMAGE_ID:$VERSION .
docker buildx build --push \
--target with-browser \
--platform linux/amd64,linux/arm64 \
-t $DOCKER_IMAGE_ID:$VERSION-with-browser \
-t ghcr.io/$GHCR_IMAGE_ID:$VERSION-with-browser .
# We also want to tag the latest stable version as latest
if [[ ! "$VERSION" =~ (RC|rc) ]]; then
echo "Publish $GHCR_IMAGE_ID:latest"
docker buildx build --push \
--target release \
--platform linux/amd64,linux/arm64 \
-t $DOCKER_IMAGE_ID:latest \
-t ghcr.io/$GHCR_IMAGE_ID:latest .
docker buildx build --push \
--target with-browser \
--platform linux/amd64,linux/arm64 \
-t $DOCKER_IMAGE_ID:latest-with-browser \
-t ghcr.io/$GHCR_IMAGE_ID:latest-with-browser .
fi
package-windows:
runs-on: windows-2019
defaults:
run:
shell: pwsh
needs: [configure, build]
env:
VERSION: ${{ needs.configure.outputs.k6_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pandoc
uses: crazy-max/ghaction-chocolatey@0e015857dd851f84fcb7fb53380eb5c4c8202333 # v3.0.0
with:
args: install -y pandoc
- name: Install wix tools
run: |
curl -Lso wix311-binaries.zip https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip
Expand-Archive -Path .\wix311-binaries.zip -DestinationPath .\wix311\
echo "$pwd\wix311" | Out-File -FilePath $env:GITHUB_PATH -Append
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries
path: dist
- name: Unzip Windows binary
run: |
Expand-Archive -Path ".\dist\k6-$env:VERSION-windows-amd64.zip" -DestinationPath .\packaging\
move .\packaging\k6-$env:VERSION-windows-amd64\k6.exe .\packaging\
rmdir .\packaging\k6-$env:VERSION-windows-amd64\
- name: Add signtool to PATH
run: echo "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x64" | Out-File -FilePath $env:GITHUB_PATH -Append
- name: Create the MSI package
run: |
$env:VERSION = $env:VERSION -replace 'v(\d+\.\d+\.\d+).*','$1'
pandoc -s -f markdown -t rtf -o packaging\LICENSE.rtf LICENSE.md
cd .\packaging
candle.exe -arch x64 "-dVERSION=$env:VERSION" k6.wxs
light.exe -ext WixUIExtension k6.wixobj
- name: Sign Windows binary and .msi package
# GH secrets are unavaileble when building from project forks, so this
# will fail for external PRs, even if we wanted to do it. And we don't.
# We are only going to sign packages that are built from master or a
# version tag, or manually triggered dev builds, so we have enough
# assurance that package signing works, but don't sign every PR build.
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' }}
run: |
# Convert base64 certificate to PFX
$bytes = [Convert]::FromBase64String("${{ secrets.WIN_SIGN_CERT }}")
[IO.File]::WriteAllBytes("k6.pfx", $bytes)
# Sign the Windows binary
signtool sign /f k6.pfx /p "${{ secrets.WIN_SIGN_PASS }}" /tr "http://timestamp.digicert.com" /td sha256 /fd sha256 "packaging\k6.exe"
# Sign the MSI package
signtool sign /f k6.pfx /p "${{ secrets.WIN_SIGN_PASS }}" /tr "http://timestamp.digicert.com" /td sha256 /fd sha256 "packaging\k6.msi"
# Cleanup signing artifacts
del k6.pfx
- name: Rename MSI package
# To keep it consistent with the other artifacts
run: move "packaging\k6.msi" "packaging\k6-$env:VERSION-windows-amd64.msi"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-windows
path: |
packaging/k6-*.msi
retention-days: 7
publish-github:
runs-on: ubuntu-latest
needs: [configure, build, package-windows]
if: ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch' }}
env:
VERSION: ${{ needs.configure.outputs.k6_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries
path: dist
- name: Download Windows binaries
uses: actions/download-artifact@v4
with:
name: binaries-windows
path: dist
- name: Generate checksum file
run: cd dist && sha256sum * > "k6-${VERSION}-checksums.txt"
- name: Anchore SBOM Action
continue-on-error: true
uses: anchore/sbom-action@9fece9e20048ca9590af301449208b2b8861333b # v0.15.9
with:
artifact-name: k6-${{ env.VERSION }}-spdx.json
upload-release-assets: false
output-file: dist/k6-${{ env.VERSION }}-spdx.json
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x
assets=()
for asset in ./dist/*; do
assets+=("$asset")
done
gh release create "$VERSION" "${assets[@]}" --target "$GITHUB_SHA" -F "./release notes/${VERSION}.md"
publish-packages:
runs-on: ubuntu-latest
needs: [configure, build, package-windows]
if: ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch' }}
env:
VERSION: ${{ needs.configure.outputs.k6_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries
path: dist
- name: Download Windows binaries
uses: actions/download-artifact@v4
with:
name: binaries-windows
path: dist
- name: Rename binaries
# To be consistent with the filenames used in dl.k6.io
run: |
mv "dist/k6-$VERSION-windows-amd64.msi" "dist/k6-$VERSION-amd64.msi"
mv "dist/k6-$VERSION-linux-amd64.rpm" "dist/k6-$VERSION-amd64.rpm"
mv "dist/k6-$VERSION-linux-amd64.deb" "dist/k6-$VERSION-amd64.deb"
- name: Setup docker-compose environment
run: |
cat > packaging/.env <<EOF
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION=us-east-1
AWS_CF_DISTRIBUTION="${{ secrets.AWS_CF_DISTRIBUTION }}"
PGP_SIGN_KEY_PASSPHRASE=${{ secrets.PGP_SIGN_KEY_PASSPHRASE }}
EOF
echo "${{ secrets.PGP_SIGN_KEY }}" > packaging/sign-key.gpg
- name: Publish packages
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
cd packaging
docker-compose pull packager
docker-compose run --rm packager