Skip to content

Commit e09a820

Browse files
authored
Merge pull request #153 from grafana/145-use-goreleaser-to-release-docker-images
Use GoReleaser to release docker images
2 parents beb63d4 + 543eca5 commit e09a820

File tree

17 files changed

+1052
-167
lines changed

17 files changed

+1052
-167
lines changed

.github/workflows/ci.yml

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,72 +16,72 @@ jobs:
1616
# Default is true, cancels jobs for other platforms in the matrix if one fails
1717
fail-fast: false
1818
matrix:
19-
os: [ ubuntu-latest, macos-latest, windows-latest ]
20-
go-version: [ 1.22.x ]
19+
os: [ubuntu-latest, macos-latest, windows-latest]
20+
go-version: [1.23.x]
2121

2222
# Set some variables per OS, usable via ${{ matrix.VAR }}
2323
# XK6_BIN_PATH: the path to the compiled k6 binary, for artifact publishing
2424
# SUCCESS: the typical value for $? per OS (Windows/pwsh returns 'True')
2525
include:
26-
- os: ubuntu-latest
27-
XK6_BIN_PATH: ./cmd/xk6/xk6
28-
SUCCESS: 0
26+
- os: ubuntu-latest
27+
XK6_BIN_PATH: ./cmd/xk6/xk6
28+
SUCCESS: 0
2929

30-
- os: macos-latest
31-
XK6_BIN_PATH: ./cmd/xk6/xk6
32-
SUCCESS: 0
30+
- os: macos-latest
31+
XK6_BIN_PATH: ./cmd/xk6/xk6
32+
SUCCESS: 0
3333

34-
- os: windows-latest
35-
XK6_BIN_PATH: ./cmd/xk6/xk6.exe
36-
SUCCESS: 'True'
34+
- os: windows-latest
35+
XK6_BIN_PATH: ./cmd/xk6/xk6.exe
36+
SUCCESS: "True"
3737

3838
runs-on: ${{ matrix.os }}
3939

4040
steps:
41-
- name: Install Go
42-
uses: actions/setup-go@v3
43-
with:
44-
go-version: ${{ matrix.go-version }}
41+
- name: Install Go
42+
uses: actions/setup-go@v5
43+
with:
44+
go-version: ${{ matrix.go-version }}
4545

46-
- name: Checkout code
47-
uses: actions/checkout@v3
46+
- name: Checkout code
47+
uses: actions/checkout@v3
4848

49-
- name: Print Go version and environment
50-
id: vars
51-
shell: bash
52-
run: |
53-
printf "Using go at: $(which go)\n"
54-
printf "Go version: $(go version)\n"
55-
printf "\n\nGo environment:\n\n"
56-
go env
57-
printf "\n\nSystem environment:\n\n"
58-
env
59-
# Calculate the short SHA1 hash of the git commit
60-
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
61-
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
49+
- name: Print Go version and environment
50+
id: vars
51+
shell: bash
52+
run: |
53+
printf "Using go at: $(which go)\n"
54+
printf "Go version: $(go version)\n"
55+
printf "\n\nGo environment:\n\n"
56+
go env
57+
printf "\n\nSystem environment:\n\n"
58+
env
59+
# Calculate the short SHA1 hash of the git commit
60+
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
61+
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
6262
63-
- name: Cache the build cache
64-
uses: actions/cache@v3
65-
with:
66-
path: ${{ steps.vars.outputs.go_cache }}
67-
key: ${{ runner.os }}-go-ci-${{ hashFiles('**/go.sum') }}
68-
restore-keys: |
69-
${{ runner.os }}-go-ci
63+
- name: Cache the build cache
64+
uses: actions/cache@v3
65+
with:
66+
path: ${{ steps.vars.outputs.go_cache }}
67+
key: ${{ runner.os }}-go-ci-${{ hashFiles('**/go.sum') }}
68+
restore-keys: |
69+
${{ runner.os }}-go-ci
7070
71-
- name: Get dependencies
72-
run: |
73-
go get -v -t -d ./...
71+
- name: Get dependencies
72+
run: |
73+
go get -v -t -d ./...
7474
75-
- name: Build xk6
76-
working-directory: ./cmd/xk6
77-
env:
78-
CGO_ENABLED: 0
79-
run: |
80-
go build -trimpath -ldflags="-w -s" -v
75+
- name: Build xk6
76+
working-directory: ./cmd/xk6
77+
env:
78+
CGO_ENABLED: 0
79+
run: |
80+
go build -trimpath -ldflags="-w -s" -v
8181
82-
- name: Run tests
83-
run: |
84-
go test -v -coverprofile="cover-profile.out" -short -race ./...
82+
- name: Run tests
83+
run: |
84+
go test -v -coverprofile="cover-profile.out" -short -race ./...
8585
8686
golangci-lint:
8787
name: runner / golangci-lint
@@ -92,9 +92,9 @@ jobs:
9292
with:
9393
fetch-depth: 0
9494
- name: Install Go
95-
uses: actions/setup-go@v3
95+
uses: actions/setup-go@v5
9696
with:
97-
go-version: 1.22.x
97+
go-version: 1.23.x
9898
check-latest: true
9999
- name: Retrieve golangci-lint version
100100
run: |

.github/workflows/release.yml

Lines changed: 40 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,101 +2,61 @@ name: Release
22

33
on:
44
push:
5-
branches:
6-
- master
7-
tags:
8-
- 'v*.*.*'
5+
branches: ["master"]
6+
tags: ["v*.*.*"]
97

108
jobs:
11-
docker:
12-
name: Build and publish Docker image
13-
runs-on: ubuntu-latest
14-
env:
15-
IMAGE_REPOSITORY: ${{ github.repository }}
16-
VERSION: ${{ github.ref_name }}
17-
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v4
20-
with:
21-
fetch-depth: 0
22-
23-
- name: Build image
24-
run: |
25-
docker buildx create \
26-
--name multibuilder \
27-
--platform linux/amd64,linux/arm64 \
28-
--bootstrap --use
29-
docker buildx build \
30-
--platform linux/amd64,linux/arm64 \
31-
-t "$IMAGE_REPOSITORY" .
32-
33-
- name: Build k6 binary
34-
run: |
35-
docker run --rm -u "$(id -u):$(id -g)" -v "$PWD:/xk6" \
36-
"$IMAGE_REPOSITORY" build latest \
37-
--with github.com/grafana/xk6-sql \
38-
--with github.com/grafana/xk6-output-influxdb
39-
- name: Check k6 binary
40-
run: |
41-
./k6 version
42-
./k6 version | grep -qz 'xk6-output-influxdb.*xk6-sql'
43-
44-
- name: Log into ghcr.io
45-
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
46-
run: |
47-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
48-
49-
- name: Log into Docker Hub
50-
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
51-
run: |
52-
echo "${{ secrets.DOCKER_PASS }}" | docker login -u "${{ secrets.DOCKER_USER }}" --password-stdin
53-
54-
- name: Publish master image
55-
if: ${{ github.ref == 'refs/heads/master' }}
56-
run: |
57-
echo "Publish as master"
58-
docker buildx build --push \
59-
--platform linux/amd64,linux/arm64 \
60-
-t ${IMAGE_REPOSITORY}:master \
61-
-t "ghcr.io/${IMAGE_REPOSITORY}:master" .
62-
63-
- name: Publish tagged version
64-
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
65-
run: |
66-
VERSION="${VERSION#v}"
67-
echo "Publish as ${VERSION}"
68-
docker buildx build --push \
69-
--platform linux/amd64,linux/arm64 \
70-
-t ${IMAGE_REPOSITORY}:${VERSION} \
71-
-t "ghcr.io/${IMAGE_REPOSITORY}:${VERSION}" .
72-
# We also want to tag the latest stable version as latest
73-
if [[ ! "$VERSION" =~ (RC|rc) ]]; then
74-
echo "Publish as latest"
75-
docker buildx build --push \
76-
--platform linux/amd64,linux/arm64 \
77-
-t ${IMAGE_REPOSITORY}:latest \
78-
-t "ghcr.io/${IMAGE_REPOSITORY}:latest" .
79-
fi
80-
81-
binary:
82-
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
83-
name: Build and attach binary artifacts
9+
release:
10+
name: Release
8411
runs-on: ubuntu-latest
8512
permissions:
8613
contents: write
8714
packages: write
8815
steps:
8916
- name: Checkout
9017
uses: actions/checkout@v4
18+
9119
- name: Set up Go
9220
uses: actions/setup-go@v5
9321
with:
94-
go-version: "1.22.x"
22+
go-version: "1.23.x"
23+
24+
- name: Set up QEMU
25+
uses: docker/setup-qemu-action@v3
26+
with:
27+
platforms: "amd64,arm64"
28+
29+
- name: Dry Run GoReleaser
30+
uses: goreleaser/goreleaser-action@v6
31+
with:
32+
version: "~> v2"
33+
args: release --clean --snapshot
34+
35+
- name: Test Docker Image
36+
run: |
37+
mkdir ${{ runner.temp }}/testrun
38+
cd ${{ runner.temp }}/testrun
39+
docker run --rm -u "$(id -u):$(id -g)" -v "$PWD:/xk6" ${{ github.repository }}:latest-amd64 \
40+
build --with github.com/grafana/xk6-faker
41+
./k6 version | grep -q xk6-faker
42+
43+
- name: Login to Docker Hub
44+
uses: docker/login-action@v3
45+
with:
46+
username: ${{ secrets.DOCKER_USER }}
47+
password: ${{ secrets.DOCKER_PASS }}
48+
49+
- name: Login to GitHub Packages
50+
uses: docker/login-action@v3
51+
with:
52+
registry: ghcr.io
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
9556
- name: Run GoReleaser
9657
uses: goreleaser/goreleaser-action@v6
9758
with:
98-
distribution: goreleaser
99-
version: "2.4.7"
59+
version: "~> v2"
10060
args: release --clean
10161
env:
10262
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# v1.59.1
1+
# v1.63.4
22
# Please don't remove the first line. It uses in CI to determine the golangci version
33
linters-settings:
44
errcheck:

0 commit comments

Comments
 (0)