Skip to content

Commit 5bc55c8

Browse files
authored
Merge pull request #156 from grafana/152-refactor-github-workflows
Refactor GitHub workflows
2 parents 73c4d99 + 9c010ed commit 5bc55c8

File tree

15 files changed

+789
-169
lines changed

15 files changed

+789
-169
lines changed

.github/release.bats

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bats
2+
3+
setup() {
4+
cd $BATS_TEST_DIRNAME
5+
6+
EXE="$(ls $(git rev-parse --show-toplevel)/dist/xk6_linux_$(dpkg --print-architecture)_v*/xk6)"
7+
IMAGE=grafana/xk6:latest-$(dpkg --print-architecture)
8+
IFS=', ' read -r -a K6_VERSIONS <<<"${K6_VERSIONS:-latest}"
9+
K6_EXTENSION_MODULE=github.com/grafana/xk6-faker
10+
K6_EXTENSION_VERSION="v0.4.3"
11+
12+
if [ -z "$(docker images $IMAGE --format json)" ]; then
13+
echo " - building release" >&3
14+
goreleaser release --clean --snapshot
15+
fi
16+
}
17+
18+
@test 'build (k6 versions: ${K6_VERSIONS[@]:-latest})' {
19+
for K6_VERSION in "${K6_VERSIONS[@]}"; do
20+
[ -f ./k6 ] && rm ./k6 </dev/null
21+
run $EXE build $K6_VERSION --with "${K6_EXTENSION_MODULE}@${K6_EXTENSION_VERSION}"
22+
[ $status -eq 0 ]
23+
echo "$output" | grep -q "xk6 has now produced a new k6 binary"
24+
./k6 version | grep -q "${K6_EXTENSION_MODULE} ${K6_EXTENSION_VERSION}"
25+
done
26+
}
27+
28+
@test 'build using docker (k6 versions: ${K6_VERSIONS[@]:-latest})' {
29+
for K6_VERSION in "${K6_VERSIONS[@]}"; do
30+
[ -f ./k6 ] && rm ./k6 </dev/null
31+
run docker run --rm -u "$(id -u):$(id -g)" -v "${PWD}:/xk6" $IMAGE build $K6_VERSION --with "${K6_EXTENSION_MODULE}@${K6_EXTENSION_VERSION}"
32+
33+
[ $status -eq 0 ]
34+
echo "$output" | grep -q "xk6 has now produced a new k6 binary"
35+
./k6 version | grep -q "${K6_EXTENSION_MODULE} ${K6_EXTENSION_VERSION}"
36+
done
37+
}

.github/validate.bats

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bats
2+
3+
setup() {
4+
cd $BATS_TEST_DIRNAME
5+
6+
EXE="$(ls $(git rev-parse --show-toplevel)/dist/xk6_linux_$(dpkg --print-architecture)_v*/xk6)"
7+
IFS=', ' read -r -a K6_VERSIONS <<<"${K6_VERSIONS:-latest}"
8+
K6_EXTENSION_MODULE=github.com/grafana/xk6-faker
9+
K6_EXTENSION_VERSION="v0.4.3"
10+
11+
if [ ! -x "$EXE" ]; then
12+
echo " - building snapshot" >&3
13+
goreleaser build --clean --snapshot --single-target
14+
fi
15+
}
16+
17+
@test 'build (k6 versions: ${K6_VERSIONS[@]:-latest})' {
18+
for K6_VERSION in "${K6_VERSIONS[@]}"; do
19+
[ -f ./k6 ] && rm ./k6 </dev/null
20+
run $EXE build $K6_VERSION --with "${K6_EXTENSION_MODULE}@${K6_EXTENSION_VERSION}"
21+
[ $status -eq 0 ]
22+
echo "$output" | grep -q "xk6 has now produced a new k6 binary"
23+
./k6 version | grep -q "${K6_EXTENSION_MODULE} ${K6_EXTENSION_VERSION}"
24+
done
25+
}

.github/workflows/ci.yml

Lines changed: 0 additions & 106 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,24 @@
11
name: Release
22

33
on:
4+
# #region triggers
45
push:
56
tags: ["v*.*.*"]
7+
# #endregion triggers
68

79
jobs:
810
release:
911
name: Release
10-
runs-on: ubuntu-latest
11-
permissions:
12-
contents: write
13-
packages: write
14-
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v4
17-
18-
- name: Set up Go
19-
uses: actions/setup-go@v5
20-
with:
21-
go-version: "1.23.x"
22-
23-
- name: Set up QEMU
24-
uses: docker/setup-qemu-action@v3
25-
with:
26-
platforms: "amd64,arm64"
27-
28-
- name: Dry Run GoReleaser
29-
uses: goreleaser/goreleaser-action@v6
30-
with:
31-
version: "~> v2"
32-
args: release --clean --snapshot
33-
34-
- name: Test Docker Image
35-
run: |
36-
mkdir ${{ runner.temp }}/testrun
37-
cd ${{ runner.temp }}/testrun
38-
docker run --rm -u "$(id -u):$(id -g)" -v "$PWD:/xk6" ${{ github.repository }}:latest-amd64 \
39-
build --with github.com/grafana/xk6-faker
40-
./k6 version | grep -q xk6-faker
41-
42-
- name: Login to Docker Hub
43-
uses: docker/login-action@v3
44-
with:
45-
username: ${{ secrets.DOCKER_USER }}
46-
password: ${{ secrets.DOCKER_PASS }}
47-
48-
- name: Login to GitHub Packages
49-
uses: docker/login-action@v3
50-
with:
51-
registry: ghcr.io
52-
username: ${{ github.actor }}
53-
password: ${{ secrets.GITHUB_TOKEN }}
54-
55-
- name: Run GoReleaser
56-
uses: goreleaser/goreleaser-action@v6
57-
with:
58-
version: "~> v2"
59-
args: release --clean
60-
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12+
uses: ./.github/workflows/tooling-release.yml
13+
secrets:
14+
# #region secrets
15+
docker-user: ${{secrets.DOCKER_USER}}
16+
docker-token: ${{secrets.DOCKER_PASS}}
17+
# #endregion
18+
with:
19+
# #region inputs
20+
go-version: ${{vars.GO_VERSION}}
21+
goreleaser-version: ${{vars.GORELEASER_VERSION}}
22+
k6-versions: ${{vars.K6_VERSIONS}}
23+
bats: ./.github/release.bats
24+
# #endregion inputs

0 commit comments

Comments
 (0)