-
Notifications
You must be signed in to change notification settings - Fork 8
223 lines (215 loc) · 7.66 KB
/
publish.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
name: publish
on:
workflow_dispatch:
inputs:
version:
description: 'The version of the release in semver format. If it is a development release append a build metadata (e.g. v0.38.0-dev).'
required: true
push:
branches:
- main
tags:
- v*
env:
REGISTRY: ghcr.io
DISRUPTOR_IMAGE_NAME: grafana/xk6-disruptor
AGENT_IMAGE_NAME: grafana/xk6-disruptor-agent
jobs:
build-binaries:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
version: ${{ steps.export-version.outputs.version}}
pkg_version: ${{ steps.export-version.outputs.pkg_version }}
image_version: ${{ steps.export-version.outputs.image_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install xk6 (k6 extension builder)
run: |
go install go.k6.io/xk6/cmd/xk6@latest
- name: Install nfpm (dep and rpm package builder)
run: |
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]
- name: get-version
run: |
COMMIT="$(git rev-parse --short HEAD)"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
IMAGE_VERSION=$VERSION
elif [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
VERSION=$GITHUB_REF_NAME
IMAGE_VERSION=$VERSION
else
VERSION=""
IMAGE_VERSION="latest"
fi
PKG_VERSION=${VERSION:-dev-$COMMIT}
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "PKG_VERSION=$PKG_VERSION" >> $GITHUB_ENV
echo "IMAGE_VERSION=$IMAGE_VERSION" >> $GITHUB_ENV
- name: build and package disruptor
env:
VERSION: ${{ env.VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
if [[ -n $VERSION ]]; then
VERSION="-v $VERSION"
fi
./release.sh $VERSION -r $PKG_VERSION
- name: Build and package agent
env:
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
for ARCH in "amd64" "arm64"; do
AGENT="xk6-disruptor-agent"
GOARCH=$ARCH CGO_ENABLED=0 go build -o build/$AGENT-linux-$ARCH ./cmd/agent
tar -zcf dist/$AGENT-${PKG_VERSION}-linux-$ARCH.tar.gz -C build/ $AGENT-linux-$ARCH
done
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: binaries
path: dist/
retention-days: 7
- name: Export version
id: export-version
env:
VERSION: ${{ env.VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
IMAGE_VERSION: ${{ env.IMAGE_VERSION }}
run: |
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "pkg_version=$PKG_VERSION" >> $GITHUB_OUTPUT
echo "image_version=$IMAGE_VERSION" >> $GITHUB_OUTPUT
build-windows-installer:
runs-on: windows-2022
needs: [build-binaries]
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
defaults:
run:
shell: pwsh
steps:
- name: get package info
run: |
# remove 'v' from version as windows only manage numeric version numbers
$Env:VERSION=$Env:GITHUB_REF_NAME.trim("v")
echo "VERSION=$Env:VERSION" >> $Env:GITHUB_ENV
echo "PKGNAME=xk6-disruptor-v$Env:VERSION-windows-amd64" >> $Env:GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v4
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: binaries
path: dist
- 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 .\packaging\wix311\
- name: Unzip Windows binary
run: |
Expand-Archive -Path ".\dist\$Env:PKGNAME.zip" -DestinationPath .\packaging\
- name: Build msi
run: |
cd .\packaging
.\wix311\candle.exe -arch x64 "-dVERSION=$Env:VERSION" xk6disruptor.wxs
.\wix311\light.exe -ext WixUIExtension -o "$Env:PKGNAME.msi" xk6disruptor.wixobj
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: binaries
path: |
packaging/*.msi
retention-days: 7
publish-images:
runs-on: ubuntu-latest
needs: [build-binaries]
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get image version
run: |
echo "VERSION=${{needs.build-binaries.outputs.version}}" >> $GITHUB_ENV
echo "PKG_VERSION=${{needs.build-binaries.outputs.pkg_version}}" >> $GITHUB_ENV
echo "IMAGE_VERSION=${{needs.build-binaries.outputs.image_version}}" >> $GITHUB_ENV
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: binaries
path: dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.9.1
- name: Log into ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push disruptor image
env:
IMAGE_VERSION: ${{ env.IMAGE_VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
IMAGE_TAG="$REGISTRY/$DISRUPTOR_IMAGE_NAME:${IMAGE_VERSION:-latest}"
mkdir images/disruptor/build/
cat dist/xk6-disruptor-${PKG_VERSION}-linux-*.tar.gz | tar -xzf - -i -C images/disruptor/build/
docker buildx build -t $IMAGE_TAG --platform=linux/amd64,linux/arm64 images/disruptor --push
- name: Build and push agent image
env:
IMAGE_VERSION: ${{ env.IMAGE_VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
IMAGE_TAG="$REGISTRY/$AGENT_IMAGE_NAME:${IMAGE_VERSION:-latest}"
mkdir images/agent/build/
cat dist/xk6-disruptor-agent-${PKG_VERSION}-linux-*.tar.gz | tar -xzf - -i -C images/agent/build/
docker buildx build -t $IMAGE_TAG --platform=linux/amd64,linux/arm64 images/agent --push
release-packages:
runs-on: ubuntu-latest
needs: [build-binaries, build-windows-installer]
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: get release version
run: |
VERSION=$GITHUB_REF_NAME
VERSION_SHA=$GITHUB_SHA
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v4
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: binaries
path: dist
- name: Generate checksum file
env:
VERSION: ${{ env.VERSION }}
run: sha256sum dist/* > "xk6-disruptor-${VERSION}-checksums.txt"
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ env.VERSION }}
run: |
MESSAGE="$(cat ./releases/${VERSION}.md)"
assets=()
for asset in ./dist/*; do
assets+=("$asset")
done
gh release create "$VERSION" --target "$VERSION_SHA" -F "./releases/${VERSION}.md" "${assets[@]}"