-
Notifications
You must be signed in to change notification settings - Fork 228
408 lines (363 loc) · 16.1 KB
/
base-ci-goreleaser.yaml
File metadata and controls
408 lines (363 loc) · 16.1 KB
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
name: Reusable GoReleaser CI workflow
on:
workflow_call:
inputs:
distribution:
required: true
type: string
goos:
required: true
type: string
goarch:
required: true
type: string
runner_os:
required: false
type: string
default: ubuntu-24.04
nightly:
required: false
type: boolean
default: false
description: "Set to true to fetch latest otelcol-contrib main branch version instead of building the version in this repo"
config_file:
required: false
type: string
default: default-config.yaml
docker_run_options:
required: false
type: string
otelcol_run_options:
required: false
type: string
permissions:
contents: read
env:
# renovate: datasource=github-releases packageName=goreleaser/goreleaser-pro
GORELEASER_PRO_VERSION: v2.13.3
jobs:
prev-tag:
outputs:
PREVIOUS_RELEASE_TAG: ${{ steps.prev-tag.outputs.PREVIOUS_RELEASE_TAG }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Set goreleaser last tag reference in case of non-nightly release
id: prev-tag
if: inputs.nightly != 'true'
# find previous tag by filtering out nightly tags and binary release (OCB, OpAMP) tags and then choosing the
# second to last tag (last one is the current release)
run: |
prev_tag=$(git tag | grep -v "cmd" | grep -v "nightly" | sort -r --version-sort | head -n 2 | tail -n 1)
echo "PREVIOUS_RELEASE_TAG=$prev_tag" >> "$GITHUB_OUTPUT"
check-goreleaser:
strategy:
matrix:
GOOS: ${{ fromJSON( inputs.goos) }}
GOARCH: ${{ fromJSON( inputs.goarch) }}
exclude:
- GOOS: darwin
GOARCH: "386"
- GOOS: darwin
GOARCH: s390x
- GOOS: windows
GOARCH: arm64
- GOOS: darwin
GOARCH: arm
- GOOS: windows
GOARCH: arm
- GOOS: windows
GOARCH: s390x
- GOOS: darwin
GOARCH: ppc64le
- GOOS: windows
GOARCH: ppc64le
- GOOS: darwin
GOARCH: riscv64
- GOOS: windows
GOARCH: riscv64
runs-on: ${{ inputs.runner_os }}
needs: prev-tag
outputs:
version: ${{ steps.prep.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Setup QEMU
if: runner.os != 'Windows'
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
with:
platforms: arm64,ppc64le,linux/arm/v7,s390x,riscv64
- name: Setup wixl # Required to build MSI packages for Windows
if: runner.os != 'Windows'
run: |
sudo apt-get update
sudo apt-get install -y wixl
- name: Setup Docker Buildx
if: runner.os != 'Windows'
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Setup Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version: "~1.25.0"
check-latest: true
- name: Create artifacts directory to store build artifacts
if: inputs.distribution == 'otelcol-contrib'
run: mkdir -p distributions/otelcol-contrib/artifacts
- name: "[Nightly] Get latest finished run ID from contrib repo build-and-test"
id: get-run-id
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux'
env:
GH_TOKEN: ${{ github.token }}
run: |
run_id=$(gh run list \
--branch main \
--workflow build-and-test \
--repo open-telemetry/opentelemetry-collector-contrib \
--limit 1 \
--status success \
--json databaseId \
--jq '.[0].databaseId' \
)
echo "Found run ID: $run_id"
echo "run_id=$run_id" >> "$GITHUB_OUTPUT"
- name: "[Nightly] Create sub-directory for otelcol-contrib nightly build"
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux'
run: mkdir -p distributions/otelcol-contrib/artifacts/otelcol-contrib_linux_amd64_v1
- name: "[Nightly] Download built otelcol-contrib artifact from contrib repo"
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux'
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: collector-binaries-linux-amd64
repository: open-telemetry/opentelemetry-collector-contrib
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.get-run-id.outputs.run_id }}
- name: "[Nightly] Move downloaded artifact"
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly == true && matrix.GOARCH == 'amd64' && matrix.GOOS == 'linux'
env:
folder: distributions/otelcol-contrib/artifacts/otelcol-contrib-linux_linux_amd64_v1/
run: |
mkdir -p ${{ env.folder }}
mv otelcontribcol_linux_amd64 ${{ env.folder }}/otelcol-contrib
- name: Generate the sources for ${{ inputs.distribution }}
if: inputs.nightly != true
env:
DISTRIBUTIONS: ${{ inputs.distribution }}
run: make generate-sources
# otelcol-contrib is built in a separate stage
- name: Build ${{ inputs.distribution }}
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly != true
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
with:
distribution: goreleaser-pro
version: ${{ env.GORELEASER_PRO_VERSION }}
workdir: distributions/otelcol-contrib
args: --snapshot --clean --timeout 2h --split --config .goreleaser-build.yaml
env:
GOOS: ${{ matrix.GOOS }}
GOARCH: ${{ matrix.GOARCH }}
GOARM: "7" # Default is 6
GOAMD64: v1
GOPPC64: power8
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
GORELEASER_PREVIOUS_TAG: ${{ needs.prev-tag.outputs.PREVIOUS_RELEASE_TAG }}
- name: Move built artifacts
if: inputs.distribution == 'otelcol-contrib' && inputs.nightly != true
run: mv distributions/otelcol-contrib/dist/**/* distributions/otelcol-contrib/artifacts/
- name: Show built or downloaded content
if: inputs.distribution == 'otelcol-contrib' && runner.os != 'Windows'
run: ls -laR distributions/otelcol-contrib/artifacts
- name: Run GoReleaser for ${{ inputs.distribution }}
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
with:
distribution: goreleaser-pro
version: ${{ env.GORELEASER_PRO_VERSION }}
workdir: distributions/${{ inputs.distribution }}
args: --snapshot --clean --skip=sign,sbom --timeout 2h --split
env:
GOOS: ${{ matrix.GOOS }}
GOARCH: ${{ matrix.GOARCH }}
GOARM: "7" # Default is 6
GOAMD64: v1
GOPPC64: power8
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
GORELEASER_PREVIOUS_TAG: ${{ needs.prev-tag.outputs.PREVIOUS_RELEASE_TAG }}
- name: Print built artifacts
run: cat ./distributions/${{ inputs.distribution }}/dist/**/artifacts.json
- name: Print metadata
run: cat ./distributions/${{ inputs.distribution }}/dist/**/metadata.json
- name: Print dist folder contents
if: always() && runner.os != 'Windows'
run: ls -laR ./distributions/${{ inputs.distribution }}/dist
- name: Upload linux service packages
if: ${{ matrix.GOOS == 'linux' && matrix.GOARCH == 'amd64' && (inputs.distribution == 'otelcol-contrib' || inputs.distribution == 'otelcol') }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: linux-packages
path: distributions/${{ inputs.distribution }}/dist/linux_amd64_v1/*
if-no-files-found: error
- name: Upload MSI packages
if: matrix.GOOS == 'windows' && matrix.GOARCH == 'amd64' && (inputs.distribution == 'otelcol-contrib' || inputs.distribution == 'otelcol')
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: msi-packages
path: distributions/${{ inputs.distribution }}/dist/windows_amd64_v1/**/*.msi
if-no-files-found: error
- name: Prepare variables
if: matrix.GOOS == 'linux' || matrix.GOOS == 'windows'
id: prep
shell: bash
run: |
# Find version number and types of built artifacts
version=$(cat ./distributions/${{ inputs.distribution }}/dist/**/metadata.json | jq -r '.version')
arch="${{ matrix.GOOS }}-${{ matrix.GOARCH }}"
echo "version=$version" >> $GITHUB_OUTPUT
echo "arch=$arch" >> $GITHUB_OUTPUT
echo "types=$(cat ./distributions/${{ inputs.distribution }}/dist/**/artifacts.json | jq '[.[].type]' | tr -d '\n' )" >> $GITHUB_OUTPUT
# Find binary path
echo "binarypath=$(cat ./distributions/${{ inputs.distribution }}/dist/**/artifacts.json | jq -r 'map(select(any(.type; contains("Binary")))) | .[].path' )" >> "$GITHUB_OUTPUT"
echo "TAG=${{ inputs.distribution }}:$version-$arch" >> $GITHUB_ENV
- name: Print version and target
if: matrix.GOOS == 'linux' || matrix.GOOS == 'windows'
run: |
echo 'Version: ${{ steps.prep.outputs.version }}'
echo 'Types: ${{ steps.prep.outputs.types }}'
echo 'Arch: ${{ steps.prep.outputs.arch }}'
echo 'Binary path: ${{ steps.prep.outputs.binarypath }}'
echo 'Images?: ${{ steps.prep.outputs.container-images }}'
echo 'Image tag: ${{ env.TAG }}'
- name: Copy binary to distro root folder
if: matrix.GOOS == 'linux' || matrix.GOOS == 'windows'
run: cp ./distributions/${{ inputs.distribution }}/${{ steps.prep.outputs.binarypath }} ./distributions/${{ inputs.distribution }}
- name: Build container images locally (Linux)
if: matrix.GOOS == 'linux' && contains(steps.prep.outputs.types, 'Docker Image')
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: ./distributions/${{ inputs.distribution }}
push: false
load: true
tags: ${{ env.TAG }}
- name: Build container images locally (Windows)
if: matrix.GOOS == 'windows' && contains(steps.prep.outputs.types, 'Docker Image')
run: |
docker build -f ./distributions/${{ inputs.distribution }}/Windows.dockerfile `
-t ${{ env.TAG }} `
--build-arg WIN_VERSION=2022 `
./distributions/${{ inputs.distribution }}/
- name: Export container image to tarball
if: (matrix.GOOS == 'linux' || matrix.GOOS == 'windows') && contains(steps.prep.outputs.types, 'Docker Image')
run: |
docker save ${{ env.TAG }} > ${{ runner.temp }}/${{ inputs.distribution }}.tar
- name: Upload container image artifact
if: (matrix.GOOS == 'linux' || matrix.GOOS == 'windows') && contains(steps.prep.outputs.types, 'Docker Image')
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: ${{ inputs.distribution }}-image-${{ steps.prep.outputs.version }}-${{ steps.prep.outputs.arch }}
path: ${{ runner.temp }}/${{ inputs.distribution }}.tar
retention-days: 7
- if: always()
run: ./.github/workflows/scripts/check-disk-space.sh
docker-tests:
needs:
- check-goreleaser
strategy:
matrix:
GOOS: ${{ fromJSON( inputs.goos) }}
GOARCH: ${{ fromJSON( inputs.goarch) }}
exclude:
- GOOS: darwin
- GOOS: windows
GOARCH: "386"
- GOOS: windows
GOARCH: arm64
runs-on: ${{ inputs.runner_os }}
env:
TAG: ${{ needs.check-goreleaser.outputs.version }}-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup QEMU
if: runner.os != 'Windows'
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
with:
platforms: arm64,ppc64le,linux/arm/v7,s390x,riscv64
- name: Download container image artifact
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: ${{ inputs.distribution }}-image-${{ env.TAG }}
- name: Load image into docker
run: |
docker image load --input ./${{ inputs.distribution }}.tar
docker image ls
docker image inspect ${{ inputs.distribution }}:${{ env.TAG }}
- name: Run container image (Linux)
if: matrix.GOOS == 'linux'
run: |
echo "Running container..."
docker run --name ${{ inputs.distribution }} \
-d \
${{ inputs.docker_run_options }} \
-v ${PWD}/tests/docker-tests/${{ inputs.config_file }}:/config.yaml \
${{ inputs.distribution }}:${{ env.TAG }} \
${{ inputs.otelcol_run_options }} --config /config.yaml
echo "docker ps:"
echo ""
docker ps
echo "Sleeping for a bit..."
sleep 10
echo "Checking logs for correct startup..."
docker logs ${{ inputs.distribution }} &>docker-logs-${{ inputs.distribution }}.log
if cat docker-logs-${{ inputs.distribution }}.log | grep "Everything is ready."; then
echo "${{ inputs.distribution }} started up correctly"
else
echo "${{ inputs.distribution }} failed to start"
echo "Printing container logs below..."
echo ""
cat docker-logs-${{ inputs.distribution }}.log
exit 1
fi
- name: Run container image (Windows)
if: matrix.GOOS == 'windows'
run: |
echo "Running container..."
docker run --name ${{ inputs.distribution }} `
-d `
${{ inputs.docker_run_options }} `
-v ${PWD}\tests\docker-tests:C:\config `
${{ inputs.distribution }}:${{ env.TAG }} `
--config C:\config\${{ inputs.config_file }} `
${{ inputs.otelcol_run_options }}
echo "docker ps:"
echo ""
docker ps
echo "Sleeping for a bit..."
sleep 10
echo "Checking logs for correct startup..."
docker logs ${{ inputs.distribution }} *> "docker-logs-${{ inputs.distribution }}.log"
if (Get-Content docker-logs-${{ inputs.distribution }}.log | Select-String -Pattern "Everything is ready.") {
echo "${{ inputs.distribution }} started up correctly"
} else {
echo "${{ inputs.distribution }} failed to start"
echo "Printing container logs below..."
echo ""
Get-Content docker-logs-${{ inputs.distribution }}.log
exit 1
}
- name: Run golden tests
if: matrix.GOOS == 'linux' && matrix.GOARCH == 'amd64' && inputs.distribution == 'otelcol-contrib'
run: |
echo "Running golden tests..."
cd tests/golden
MY_UID="$(id -u)" MY_GID="$(id -g)" IMG=${{ inputs.distribution }}:${{ env.TAG }} docker compose up -d --wait
exit_code=$(docker wait golden)
docker logs golden
if [ "$exit_code" -ne 0 ]; then
docker logs collector
exit 1
fi
- if: always()
run: ./.github/workflows/scripts/check-disk-space.sh