-
Notifications
You must be signed in to change notification settings - Fork 2
498 lines (445 loc) · 20.2 KB
/
build-applications.yaml
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
name: "Build application"
on:
workflow_call:
inputs:
appsToBuild:
required: false
type: string
default: ""
depsUpdate:
required: false
type: boolean
default: false
publishArtifacts:
required: false
type: boolean
default: false
sendNotifications:
required: false
default: false
type: boolean
jobs:
prepare:
name: Prepare to Build
runs-on: ubuntu-latest
outputs:
matrices: ${{ steps.prepare-matrices.outputs.matrices }}
steps:
- name: Lowercase repository owner
shell: bash
run: echo "LOWERCASE_REPO_OWNER=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5
with:
python-version: 3.x
cache: pip
- name: Install Python Requirements
shell: bash
run: pip install -r ./.github/scripts/requirements.txt && pip freeze
- name: Prepare Matrices
id: prepare-matrices
env:
TOKEN: ${{ steps.app-token.outputs.token }}
shell: bash
run: |
set -x
if [[ -z "${{ inputs.appsToBuild }}" ]]; then
matrices=$(python ./.github/scripts/prepare-matrices.py "all" "${{ inputs.publishArtifacts }}")
else
matrices=$(python ./.github/scripts/prepare-matrices.py "${{ inputs.appsToBuild }}" "${{ inputs.publishArtifacts }}")
fi
echo "matrices=${matrices}" >> $GITHUB_OUTPUT
echo "${matrices}"
build-platform-app:
name: "Build ${{ matrix.app.name }} ${{ matrix.app.channel }} (${{ matrix.app.platform }})"
needs: prepare
runs-on: ubuntu-latest
if: ${{ toJSON(fromJSON(needs.prepare.outputs.matrices).appsPlatforms) != '[]' && toJSON(fromJSON(needs.prepare.outputs.matrices).appsPlatforms) != '' }}
strategy:
fail-fast: false
matrix:
app: "${{ fromJSON(needs.prepare.outputs.matrices).appsPlatforms }}"
permissions:
contents: read
packages: write
steps:
- name: Log Matrix Input
shell: bash
run: |
cat << EOF
${{ toJSON(matrix.app)}}
EOF
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
repository: ${{ matrix.app.repository }}
ref: ${{ matrix.app.branch }}
token: ${{ github.token }}
path: ${{ matrix.app.repository }}
fetch-depth: ${{ matrix.app.fetch_full_history && '0' || '1' }}
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
path: nightly-stack
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5
with:
go-version: "1.23"
check-latest: true
- name: Install build dependencies
run: |
sudo apt-get update && sudo apt-get install -y build-essential libsqlite3-dev
- name: Update go modules
if: ${{ matrix.app.update_modules_enabled }}
run: |
set -x
cd ${{ matrix.app.repository }}/${{ matrix.app.path }}
COSMOSSDK_BRANCH=${{ matrix.app.update_modules_branch }} ${{ github.workspace }}/nightly-stack/.github/scripts/update-go-modules.sh
- name: show output of modified go.sum and go.mod
if: ${{ matrix.app.update_modules_enabled }}
run: |
echo "############"
echo "# go.mod"
echo "############"
cat ${{ matrix.app.repository }}/${{ matrix.app.path }}/go.mod
echo -e "\n\n"
echo "############"
echo "# go.mod"
echo "############"
cat ${{ matrix.app.repository }}/${{ matrix.app.path }}/go.sum
- name: register cosmossdk and cometbft versions
id: modules_versions
run: |
set -x
cd ${{ matrix.app.repository }}/${{ matrix.app.path }}
# Get Cosmos SDK version with fallback
COSMOSSDK_VERSION=$(go list -m -f '{{.Version}}' github.com/cosmos/cosmos-sdk 2>/dev/null || echo "unknown")
if [ -z "$COSMOSSDK_VERSION" ]; then
COSMOSSDK_VERSION="unknown"
fi
# Get CometBFT version with fallback
COMETBFT_VERSION=$(go list -m -f '{{.Version}}' github.com/cometbft/cometbft 2>/dev/null || echo "unknown")
if [ -z "$COMETBFT_VERSION" ]; then
COMETBFT_VERSION="unknown"
fi
echo "cosmossdk=${COSMOSSDK_VERSION}" >> $GITHUB_OUTPUT
echo "cometbft=${COMETBFT_VERSION}" >> $GITHUB_OUTPUT
- name: Create application binary
id: build
env:
MATRIX_APP_REPOSITORY: ${{ matrix.app.repository }}
MATRIX_APP_PATH: ${{ matrix.app.path }}
GOARCH: ${{ matrix.app.target_arch }}
BINARY_NAME: ${{ matrix.app.binary_name }}
run: ./nightly-stack/apps/${{ matrix.app.name }}/ci/build.sh
- name: Run and monitor application
shell: bash
# no arm64 runners as of now : https://github.com/orgs/community/discussions/19197
if: ${{ matrix.app.tests_enabled }}
env:
MATRIX_APP_REPOSITORY: ${{ matrix.app.repository }}
MATRIX_APP_PATH: ${{ matrix.app.path }}
GOARCH: ${{ matrix.app.target_arch }}
BINARY_NAME: ${{ matrix.app.binary_name }}
BINARY_BUILD_OUTPUT_PATH: ${{ matrix.app.repository }}/${{ matrix.app.binary_build_output_path }}
run: ./nightly-stack/apps/${{ matrix.app.name }}/ci/test.sh
- name: Export Build Result
if: ${{ !matrix.app.publish_artifacts }}
id: export-build
shell: bash
run: |
mkdir -p /tmp/${{ matrix.app.name }}/build
echo "${{ matrix.app.name }}" > "/tmp/${{ matrix.app.name }}/build/${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}"
- name: Upload Build Result
if: ${{ !matrix.app.publish_artifacts }}
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
with:
name: wfl-build-${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
path: /tmp/${{ matrix.app.name }}/*
if-no-files-found: error
retention-days: 1
- name: Create archive
if: ${{ matrix.app.publish_artifacts }}
env:
BINARY_NAME: ${{ matrix.app.binary_name }}
BINARY_BUILD_OUTPUT_PATH: ${{ matrix.app.binary_build_output_path }}
run: |
set -oue pipefail
set -x
# Create archive
if [[ ! -z $BINARY_BUILD_OUTPUT_PATH ]]; then
BINARY_PATH=${{ matrix.app.repository }}/$BINARY_BUILD_OUTPUT_PATH
else
if [[ -z $BINARY_NAME ]]; then
BINARY_PATH=$(find $(go env GOPATH)/bin | tail -n 1)
else
BINARY_PATH=$(find $(go env GOPATH)/bin | grep $BINARY_NAME | tail -n 1)
fi
fi
chmod +x $BINARY_PATH
mv $BINARY_PATH ${{ github.workspace }}/${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
- name: Upload Artifact
if: ${{ matrix.app.publish_artifacts }}
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
with:
name: ${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
path: ${{ github.workspace }}/${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
retention-days: 10
- name: Setup Docker Buildx
if: ${{ matrix.app.publish_artifacts }}
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3
- name: Login to GitHub Container Registry
if: ${{ matrix.app.publish_artifacts }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"
- name: Setup Goss
if: ${{ matrix.app.tests_enabled && matrix.app.publish_artifacts }}
uses: e1himself/goss-installation-action@8c646222c1cb43528392161394b745cb5d28e8f9 # v1
with:
version: v0.4.4
- name: Lowercase repository owner
if: ${{ matrix.app.publish_artifacts }}
shell: bash
run: echo "LOWERCASE_REPO_OWNER=${GITHUB_REPOSITORY_OWNER,,}" >> "${GITHUB_ENV}"
- name: Prepare Build Outputs
if: ${{ matrix.app.publish_artifacts }}
id: prepare-build-outputs
shell: bash
run: |
image_name="ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/${{ matrix.app.name }}"
outputs="type=image,name=${image_name},push-by-digest=true,name-canonical=true,push=true"
echo "image_name=${image_name}" >> $GITHUB_OUTPUT
echo "outputs=${outputs}" >> $GITHUB_OUTPUT
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
if: ${{ matrix.app.publish_artifacts }}
with:
name: ${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
path: nightly-stack/apps/${{ matrix.app.name}}
- name: Build Image
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6
id: build-image
if: ${{ matrix.app.publish_artifacts }}
with:
build-args: |-
BINARY=${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
context: ./nightly-stack/${{ matrix.app.context }}
file: ./nightly-stack/${{ matrix.app.dockerfile }}
platforms: ${{ matrix.app.target_arch }}
outputs: ${{ steps.prepare-build-outputs.outputs.outputs }}
cache-from: type=gha
cache-to: type=gha,mode=max
labels: |-
org.opencontainers.image.title=${{ steps.prepare-build-outputs.outputs.image_name }}
org.opencontainers.image.url=https://ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/${{ steps.prepare-build-outputs.outputs.image_name }}
org.opencontainers.image.source=https://github.com/${{ env.LOWERCASE_REPO_OWNER }}/containers
org.opencontainers.image.version=${{ matrix.app.channel }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.vendor=${{ env.LOWERCASE_REPO_OWNER }}
org.opencontainers.image.authors=${{ env.LOWERCASE_REPO_OWNER }}
org.cosmos.cosmossdk.version=${{ steps.modules_versions.outputs.cosmossdk }}
org.cosmos.cometbft.version=${{ steps.modules_versions.outputs.cometbft }}
- name: Run Goss Tests
id: dgoss
if: ${{ matrix.app.tests_enabled && matrix.app.publish_artifacts }}
env:
CONTAINER_RUNTIME: docker
GOSS_FILE: ./nightly-stack/${{ matrix.app.goss_config }}
GOSS_OPTS: --retry-timeout 60s --sleep 2s --color --format documentation
GOSS_SLEEP: 2
GOSS_FILES_STRATEGY: cp
CONTAINER_LOG_OUTPUT: goss_container_log_output
shell: bash
run: |
set -x
ls -l ./nightly-stack/${{ matrix.app.goss_config }}
image_name="${{ steps.prepare-build-outputs.outputs.image_name }}@${{ steps.build-image.outputs.digest }}"
dgoss run ${image_name}
- name: Export Digest
if: ${{ matrix.app.publish_artifacts }}
id: export-digest
shell: bash
run: |
mkdir -p /tmp/${{ matrix.app.name }}/digests
digest="${{ steps.build-image.outputs.digest }}"
echo "${{ matrix.app.name }}" > "/tmp/${{ matrix.app.name }}/digests/${digest#sha256:}"
- name: Upload Digest
if: ${{ matrix.app.publish_artifacts }}
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
with:
name: wfl-digest-${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
path: /tmp/${{ matrix.app.name }}/*
if-no-files-found: error
retention-days: 1
merge:
name: Merge ${{ matrix.app.name }} ${{ matrix.app.channel }}
runs-on: ubuntu-latest
needs: ["prepare", "build-platform-app"]
# Always run merge, as the prior matrix is all or nothing. We test for prior step failure
# in the "Test Failed Bit" step. This ensures if one app fails, others can still complete.
# if: ${{ always() && inputs.pushArtifacts && toJSON(fromJSON(needs.prepare.outputs.matrices).apps) != '[]' && toJSON(fromJSON(needs.prepare.outputs.matrices).apps) != '' }}
if: ${{ always() }}
strategy:
matrix:
app: "${{ fromJSON(needs.prepare.outputs.matrices).apps }}"
fail-fast: false
steps:
- name: Log Matrix Input
shell: bash
run: |
cat << EOF
${{ toJSON(matrix.app)}}
EOF
- name: Set variables
id: variables
shell: bash
run: |
set -x
echo "LOWERCASE_REPO_OWNER=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV
- name: Download Build output
if: ${{ !matrix.app.publish_artifacts }}
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
pattern: "wfl-build-${{ matrix.app.name }}-${{ matrix.app.channel }}-{linux,darwin}-{amd64,arm64}"
merge-multiple: true
path: /tmp/${{ matrix.app.name }}
- name: Build - Ensure all platforms were built
id: ensure-platforms-build
if: ${{ !matrix.app.publish_artifacts }}
shell: bash
run: |
EXPECTED_COUNT=$(cat << EOF | jq ". | length"
${{ toJSON(matrix.app.platforms) }}
EOF
)
ACTUAL_COUNT=$(ls -1 /tmp/${{ matrix.app.name }}/build | wc -l)
if [[ $EXPECTED_COUNT != $ACTUAL_COUNT ]]; then
echo "Expected $EXPECTED_COUNT platforms, but only found $ACTUAL_COUNT"
echo "Expected: ${{ toJSON(matrix.app.platforms) }}"
echo "Actual: $(cat /tmp/${{ matrix.app.name }}/build/*)"
exit 1
fi
echo "app_status=true" >> $GITHUB_ENV
- name: Download Digests
if: ${{ matrix.app.publish_artifacts }}
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
pattern: "wfl-digest-${{ matrix.app.name }}-${{ matrix.app.channel }}-{linux,darwin}-{amd64,arm64}"
merge-multiple: true
path: /tmp/${{ matrix.app.name }}
- name: Digests - Ensure all platforms were built
id: ensure-platforms
if: ${{ matrix.app.publish_artifacts }}
shell: bash
run: |
EXPECTED_COUNT=$(cat << EOF | jq ". | length"
${{ toJSON(matrix.app.platforms) }}
EOF
)
ACTUAL_COUNT=$(ls -1 /tmp/${{ matrix.app.name }}/digests | wc -l)
if [[ $EXPECTED_COUNT != $ACTUAL_COUNT ]]; then
echo "Expected $EXPECTED_COUNT platforms, but only found $ACTUAL_COUNT"
echo "Expected: ${{ toJSON(matrix.app.platforms) }}"
echo "Actual: $(cat /tmp/${{ matrix.app.name }}/digests/*)"
exit 1
fi
- name: Setup Docker Buildx
if: ${{ matrix.app.publish_artifacts }}
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3
- name: Login to GitHub Container Registry
if: ${{ matrix.app.publish_artifacts }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"
- name: Log Files
if: ${{ matrix.app.publish_artifacts }}
working-directory: /tmp/${{ matrix.app.name }}/digests
shell: bash
run: |
ls -la
cat *
- name: Merge Manifests
id: merge
if: ${{ matrix.app.publish_artifacts }}
working-directory: /tmp/${{ matrix.app.name }}/digests
shell: bash
run: |
set -x
docker buildx imagetools create \
--tag ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/${{ matrix.app.name }}:${{ matrix.app.container_tag_name }} \
$(printf 'ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/${{ matrix.app.name }}@sha256:%s ' *)
echo "app_status=true" >> $GITHUB_ENV
- name: Inspect image
if: ${{ matrix.app.publish_artifacts }}
id: inspect
shell: bash
run: |
docker buildx imagetools inspect ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/${{ matrix.app.name }}:${{ matrix.app.container_tag_name }}
- name: Build successful
id: build-success
if: ${{ always() && env.app_status == 'true' }}
shell: bash
run: |
echo "slack_message=🎉 Nightly build ${{ matrix.app.name }} (${{ matrix.app.channel }})" >> $GITHUB_OUTPUT
echo "slack_color=good" >> $GITHUB_OUTPUT
echo "slack_icon_emoji=:white_check_mark:" >> $GITHUB_OUTPUT
- name: Build failed
id: build-failed
if: ${{ always() && env.app_status != 'true' }}
shell: bash
run: |
echo "slack_message=💥 Nightly build ${{ matrix.app.name }} (${{ matrix.app.channel }})" >> $GITHUB_OUTPUT
echo "slack_color=danger" >> $GITHUB_OUTPUT
echo "slack_icon_emoji=:skull:" >> $GITHUB_OUTPUT
- name: Get previous workflow job status
id: previous-run
if: ${{ always() }}
shell: bash
run: |
set -x
REPO="${GITHUB_REPOSITORY}"
# https://api.github.com/repos/cosmos/nightly-stack/actions/workflows
WORKFLOW_ID="119041783"
JOB_NAME="Build Applications / Merge ${{ matrix.app.name }} ${{ matrix.app.channel }}"
# Get the previous workflow run ID (excluding the current one)
PREVIOUS_RUN_ID=$(curl -s -H "Authorization: token ${{ github.token }}" \
"https://api.github.com/repos/${REPO}/actions/workflows/${WORKFLOW_ID}/runs?per_page=2" \
| jq -r '.workflow_runs[1].id')
# Get the jobs for that specific run
PREVIOUS_STATUS=$(curl -s -H "Authorization: token ${{ github.token }}" \
"https://api.github.com/repos/${REPO}/actions/runs/${PREVIOUS_RUN_ID}/jobs" \
| jq -r --arg JOB_NAME "$JOB_NAME" '.jobs[] | select(.name == $JOB_NAME) | .conclusion')
echo "previous_status=${PREVIOUS_STATUS}" >> $GITHUB_OUTPUT
# If PREVIOUS_STATUS is empty, set it to "unknown"
PREVIOUS_STATUS=${PREVIOUS_STATUS:-unknown}
echo "previous_status=${PREVIOUS_STATUS}" >> $GITHUB_OUTPUT
- name: Notify Slack
if: |
inputs.sendNotifications == true &&
(
(env.app_status != 'true' && steps.previous-run.outputs.previous_status == 'failure') ||
(env.app_status == 'false' && steps.previous-run.outputs.previous_status == 'success')
)
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # v2.3.2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: nightly-stack-build
SLACK_USERNAME: Nightly Builds
SLACK_ICON_EMOJI: ${{ steps.build-failed.outputs.slack_icon_emoji || steps.build-success.outputs.slack_icon_emoji }}
SLACK_COLOR: ${{ steps.build-failed.outputs.slack_color || steps.build-success.outputs.slack_color }}
SLACK_MESSAGE: ${{ steps.build-failed.outputs.slack_message || steps.build-success.outputs.slack_message }}
SLACK_FOOTER: ""
# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
build_success:
name: Build matrix success
runs-on: ubuntu-latest
needs: ["prepare", "merge"]
if: ${{ always() }}
steps:
- name: Check build matrix status
if: ${{ (inputs.appsToBuild != '' && inputs.appsToBuild != '[]') && (needs.merge.result != 'success' && needs.merge.result != 'skipped' && needs.prepare.result != 'success') }}
shell: bash
run: exit 1