This repository has been archived by the owner on Dec 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
495 lines (434 loc) · 18.3 KB
/
build.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
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
name: Build
on:
push:
# branches:
# - main
tags:
- '*'
paths-ignore:
- README.md
- LICENSE
- CHANGELOG.md
- docs/**
pull_request:
branches:
- main
paths-ignore:
- README.md
- LICENSE
- CHANGELOG.md
- docs/**
workflow_dispatch:
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
PKG_NAME: 'falu'
PKG_DESCRIPTION: 'Falu CLI'
PKG_MAINTAINER: 'Falu <[email protected]>'
PKG_HOMEPAGE: 'https://falu.io'
PKG_VENDOR: FALU TECHNOLOGIES LIMITED
PKG_LICENSE: MIT
DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/falu-cli
jobs:
Build:
strategy:
fail-fast: true
matrix:
os: [ 'macos', 'ubuntu', 'windows']
arch: [ 'x64', 'arm64' ]
include:
- { os: ubuntu, arch: x64, deb-arch: amd64, rpm-arch: x86_64 }
- { os: ubuntu, arch: arm64, deb-arch: arm64, rpm-arch: aarch64 }
- { os: ubuntu, arch: x64, docker-platform: 'linux/amd64', docker-tag-suffix: '-amd64' }
- { os: ubuntu, arch: arm64, docker-platform: 'linux/arm64/v8', docker-tag-suffix: '-arm64' }
# list of RIDs (Runtime Identifiers) can be found at:
# https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json
- { os: ubuntu, rid-prefix: 'linux' }
- { os: windows, rid-prefix: 'win' }
- { os: macos, rid-prefix: 'osx' }
# macos-latest uses macos-12 which fails to build the app (macos-13 works)
- { os: macos, runs-on: 'macos-13' } # macos-latest
- { os: windows, archive-type: 'zip' } # windows creates zip files, others default to 'tar'
runs-on: ${{ matrix.runs-on || format('{0}-{1}', matrix.os, 'latest') }}
env:
DOTNET_RID: ${{ format('{0}-{1}', matrix.rid-prefix, matrix.arch) }}
outputs:
BINARIES_VERSION: ${{ steps.gitversion.outputs.nuGetVersionV2 }}
DOCKER_IMAGE_LABELS: ${{ steps.docker-meta.outputs.labels }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for GitVersion
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v1
with:
versionSpec: '5.x'
- name: Determine Version
uses: gittools/actions/gitversion/execute@v1
id: gitversion
with:
useConfigFile: true
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Install dependencies
run: dotnet restore --runtime ${{ env.DOTNET_RID }} -v detailed
- name: Build
if: github.event_name == 'pull_request'
run: dotnet build --configuration Release --no-restore
- name: Test
if: github.event_name == 'pull_request'
run: dotnet test --configuration Release --no-build --collect "Code coverage"
- name: Publish
run: >
dotnet publish
-p:PublishSingleFile=true
-p:DebugType=None
-p:DebugSymbols=false
-p:PublishTrimmed=true
-p:AssemblyName=falu
-p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }}
-p:VersionPrefix=${{ steps.gitversion.outputs.nuGetVersionV2 }}
--runtime ${{ env.DOTNET_RID }}
--configuration Release
--output ${{ github.workspace }}/drop/${{ env.DOTNET_RID }}
--self-contained true
--no-restore
src/FaluCli/FaluCli.csproj
- name: Test (Binary) # ensure the CLI can launch (catches global DI issues)
# ARM runners are in preview and we cannot use them, so we skip this test
# https://github.blog/changelog/2023-10-30-accelerate-your-ci-cd-with-arm-based-hosted-runners-in-github-actions/
# TODO: consider using QEMU emulator for ARM?
if: ${{ !contains(matrix.arch, 'arm') }}
run: ./falu logout
working-directory: ${{ github.workspace }}/drop/${{ env.DOTNET_RID }}
- name: Upload Artifact (drop)
uses: actions/upload-artifact@v4
with:
path: ${{ github.workspace }}/drop/**
name: drop-${{ env.DOTNET_RID }}
retention-days: 1
- name: Create Archive Folder
run: mkdir ${{ github.workspace }}/releases
- name: Create Archive (${{ matrix.archive-type || 'tar.gz' }})
uses: thedoctor0/zip-release@master
with:
type: ${{ matrix.archive-type || 'tar' }}
filename: ${{ github.workspace }}/releases/falu-${{ steps.gitversion.outputs.nuGetVersionV2 }}-${{ env.DOTNET_RID }}.${{ matrix.archive-type || 'tar.gz' }}
directory: ${{ github.workspace }}/drop/${{ env.DOTNET_RID }}
- name: Prepare .debpkg and .rpmpkg
if: ${{ matrix.deb-arch || matrix.rpm-arch }}
run: |
mkdir -p .debpkg/usr/bin
cp -p ${{ github.workspace }}/drop/${{ env.DOTNET_RID }}/* .debpkg/usr/bin/
mkdir -p .rpmpkg/usr/bin
cp -p ${{ github.workspace }}/drop/${{ env.DOTNET_RID }}/* .rpmpkg/usr/bin/
- name: 'Build DEB package'
uses: jiro4989/build-deb-action@v3
if: ${{ matrix.deb-arch }}
with:
desc: '${{ env.PKG_DESCRIPTION }}'
maintainer: ${{ env.PKG_MAINTAINER }}
version: ${{ steps.gitversion.outputs.nuGetVersionV2 }}
package: ${{ env.PKG_NAME }}
package_root: .debpkg
arch: '${{ matrix.deb-arch}}'
- name: 'Build RPM package'
uses: jiro4989/build-rpm-action@v2
# TODO: build RPM package for ARM once we have ARM runners
# https://github.blog/changelog/2023-10-30-accelerate-your-ci-cd-with-arm-based-hosted-runners-in-github-actions/
# Not possible on x64 runners: https://github.com/jiro4989/build-rpm-action/issues/6
# if: ${{ matrix.rpm-arch }}
if: ${{ matrix.rpm-arch && matrix.arch == 'x64' }}
with:
summary: '${{ env.PKG_DESCRIPTION }}'
desc: '${{ env.PKG_DESCRIPTION }}'
maintainer: ${{ env.PKG_MAINTAINER }}
vendor: ${{ env.PKG_VENDOR }}
license: ${{ env.PKG_LICENSE }}
version: ${{ steps.gitversion.outputs.majorMinorPatch }}
package: ${{ env.PKG_NAME }}
package_root: .rpmpkg
arch: '${{ matrix.rpm-arch}}'
- name: Rename deb and rpm packages
if: ${{ matrix.deb-arch || matrix.rpm-arch }}
run: |
src=falu_${{ steps.gitversion.outputs.nuGetVersionV2 }}_${{ matrix.deb-arch}}.deb
dest=${{ github.workspace }}/releases/falu-${{ steps.gitversion.outputs.nuGetVersionV2 }}-linux-${{ matrix.deb-arch}}.deb
mv $src $dest
src=falu-${{ steps.gitversion.outputs.majorMinorPatch }}-1.el7.${{ matrix.rpm-arch}}.rpm
dest=${{ github.workspace }}/releases/falu-${{ steps.gitversion.outputs.nuGetVersionV2 }}-linux-${{ matrix.rpm-arch}}.rpm
if [ -f $src ]; then
mv $src $dest
fi
- name: Upload Artifact (releases)
uses: actions/upload-artifact@v4
with:
path: ${{ github.workspace }}/releases/**
name: releases-${{ env.DOTNET_RID }}
retention-days: 1
- name: Test (DEB)
# TODO: test DEB package for ARM once we have ARM runners
# https://github.blog/changelog/2023-10-30-accelerate-your-ci-cd-with-arm-based-hosted-runners-in-github-actions/
# if: ${{ matrix.deb-arch }}
if: ${{ matrix.deb-arch && matrix.arch == 'x64' }}
run: |
sudo apt-get install -y -f \
${{ github.workspace }}/releases/falu-${{ steps.gitversion.outputs.nuGetVersionV2 }}-linux-${{ matrix.deb-arch}}.deb
- name: Test (RPM)
# TODO: test RPM package for ARM once we have ARM runners
# https://github.blog/changelog/2023-10-30-accelerate-your-ci-cd-with-arm-based-hosted-runners-in-github-actions/
# if: ${{ matrix.rpm-arch }}
if: ${{ matrix.rpm-arch && matrix.arch == 'x64' }}
run: |
sudo apt-get install alien
sudo alien -i \
${{ github.workspace }}/releases/falu-${{ steps.gitversion.outputs.nuGetVersionV2 }}-linux-${{ matrix.rpm-arch}}.rpm
- name: Set up Docker QEMU
if: ${{ matrix.docker-platform && matrix.arch == 'arm64' }}
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: ${{ matrix.docker-platform }}
uses: docker/setup-buildx-action@v3
- name: Login to Docker container registry
if: ${{ matrix.docker-platform && github.actor != 'dependabot[bot]' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract docker metadata (tags, labels)
if: ${{ matrix.docker-platform }}
id: docker-meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_NAME }}
labels: |
com.github.image.run.id=${{ github.run_id }}
com.github.image.run.number=${{ github.run_number }}
com.github.image.job.id=${{ github.job }}
com.github.image.source.sha=${{ github.sha }}
com.github.image.source.branch=${{ github.ref }}
org.opencontainers.image.title="Falu CLI"
org.opencontainers.image.documentation="https://falu.io/docs/cli"
org.opencontainers.image.authors="Falu <[email protected]>"
org.opencontainers.image.vendor="Falu"
org.opencontainers.image.version=${{ steps.gitversion.outputs.nuGetVersionV2 }}
org.opencontainers.image.revision=${{ github.sha }}
tags: |
${{ steps.gitversion.outputs.nuGetVersionV2 }}${{ matrix.docker-tag-suffix }}
${{ env.LATEST_TAG }}
env:
LATEST_TAG: ${{ (startsWith(github.ref, 'refs/tags') && format('latest{0}', matrix.docker-tag-suffix)) || '' }}
- name: Build docker image
if: ${{ matrix.docker-platform }}
id: docker-build
uses: docker/build-push-action@v5
with:
platforms: ${{ matrix.docker-platform }}
file: ${{ github.workspace }}/Dockerfile
context: ${{ github.workspace }}/drop/${{ env.DOTNET_RID }}
labels: ${{ steps.docker-meta.outputs.labels }}
tags: ${{ steps.docker-meta.outputs.tags }}
load: true
# provenance=false prevents untagged images from being pushed
# https://github.com/docker/build-push-action/issues/894#issuecomment-1785937908
provenance: false
- name: Test (Docker)
if: ${{ matrix.docker-platform }}
run: docker run --rm ${{ env.DOCKER_IMAGE_NAME }}:${{ steps.gitversion.outputs.nuGetVersionV2 }}${{ matrix.docker-tag-suffix }} --version
- name: Push docker image
if: ${{ matrix.docker-platform && github.actor != 'dependabot[bot]' }}
uses: docker/build-push-action@v5
with:
platforms: ${{ matrix.docker-platform }}
file: ${{ github.workspace }}/Dockerfile
context: ${{ github.workspace }}/drop/${{ env.DOTNET_RID }}
labels: ${{ steps.docker-meta.outputs.labels }}
tags: ${{ steps.docker-meta.outputs.tags }}
push: true
# provenance=false prevents untagged images from being pushed
# https://github.com/docker/build-push-action/issues/894#issuecomment-1785937908
provenance: false
- name: Export docker digest
if: ${{ matrix.docker-platform }}
run: |
mkdir -p ${{ github.workspace }}/docker-digests
digest="${{ steps.docker-build.outputs.digest }}"
touch "${{ github.workspace }}/docker-digests/${digest#sha256:}"
- name: Upload artifact (digest)
if: ${{ matrix.docker-platform }}
uses: actions/upload-artifact@v4
with:
name: docker-digests-${{ env.DOTNET_RID }}
path: ${{ github.workspace }}/docker-digests/*
retention-days: 1
if-no-files-found: error
DockerMerge:
name: Docker Merge Manifests
runs-on: ubuntu-latest
needs: [ Build ]
steps:
- name: Download Artifact (docker-digests)
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/docker-digests
pattern: docker-digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker container registry
if: ${{ github.actor != 'dependabot[bot]' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract docker metadata (tags, labels)
id: docker-meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_NAME }}
labels: ${{ needs.Build.outputs.DOCKER_IMAGE_LABELS }}
tags: |
${{ needs.Build.outputs.BINARIES_VERSION }}
${{ env.LATEST_TAG }}
env:
LATEST_TAG: ${{ (startsWith(github.ref, 'refs/tags') && 'latest') || '' }}
- name: Create manifest list and push
if: ${{ github.actor != 'dependabot[bot]' }}
working-directory: ${{ github.workspace }}/docker-digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.DOCKER_IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
if: ${{ github.actor != 'dependabot[bot]' }}
run: |
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE_NAME }}:${{ needs.Build.outputs.BINARIES_VERSION }}
Checksum:
runs-on: ubuntu-latest
needs: [ Build ]
steps:
- name: Download Artifact (releases)
uses: actions/download-artifact@v4
with:
path: releases
pattern: releases-*
merge-multiple: true
- name: Generate checksum
uses: jmgilman/actions-generate-checksum@v1
with:
method: 'sha256'
output: 'checksum.txt'
patterns: |
releases/falu-*.deb
releases/falu-*.rpm
releases/falu-*.tar.gz
releases/falu-*.zip
# retain only the file names
# waiting on https://github.com/jmgilman/actions-generate-checksum/pull/2
- name: Strip directory
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "releases/falu-"
replace: "falu-"
include: checksum.txt
- name: Upload Artifact (releases)
uses: actions/upload-artifact@v4
with:
path: checksum.txt
name: releases-checksum
retention-days: 1
Packaging:
runs-on: macos-latest
needs: [ Build ]
outputs:
BINARIES_VERSION: ${{ needs.Build.outputs.BINARIES_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Artifact (releases)
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/releases
pattern: releases-*
merge-multiple: true
- name: Prepare templates
run: |
mkdir -p ${{ github.workspace }}/generated/homebrew/
mv packaging/homebrew/formula-template.rb ${{ github.workspace }}/generated/homebrew/falu.rb
mkdir -p ${{ github.workspace }}/generated/scoop/
mv packaging/scoop/bucket-template.json ${{ github.workspace }}/generated/scoop/falu.json
- name: Prepare variables
working-directory: ${{ github.workspace }}/releases
run: |
echo "BINARIES_VERSION=$BINARIES_VERSION" >> "$GITHUB_ENV"
checksumMacARM64=$(shasum -a 256 falu-$BINARIES_VERSION-osx-arm64.tar.gz | cut -d " " -f 1)
checksumMacX64=$(shasum -a 256 falu-$BINARIES_VERSION-osx-x64.tar.gz | cut -d " " -f 1)
checksumLinuxARM64=$(shasum -a 256 falu-$BINARIES_VERSION-linux-arm64.tar.gz | cut -d " " -f 1)
checksumLinuxX64=$(shasum -a 256 falu-$BINARIES_VERSION-linux-x64.tar.gz | cut -d " " -f 1)
checksumWindowsARM64=$(shasum -a 256 falu-$BINARIES_VERSION-win-arm64.zip | cut -d " " -f 1)
checksumWindowsX64=$(shasum -a 256 falu-$BINARIES_VERSION-win-x64.zip | cut -d " " -f 1)
echo "MACOS_ARM64_BINARY_SHA256=$checksumMacARM64" >> "$GITHUB_ENV"
echo "MACOS_X64_BINARY_SHA256=$checksumMacX64" >> "$GITHUB_ENV"
echo "LINUX_ARM64_BINARY_SHA256=$checksumLinuxARM64" >> "$GITHUB_ENV"
echo "LINUX_X64_BINARY_SHA256=$checksumLinuxX64" >> "$GITHUB_ENV"
echo "WINDOWS_ARM64_BINARY_SHA256=$checksumWindowsARM64" >> "$GITHUB_ENV"
echo "WINDOWS_X64_BINARY_SHA256=$checksumWindowsX64" >> "$GITHUB_ENV"
env:
BINARIES_VERSION: ${{ needs.Build.outputs.BINARIES_VERSION }}
- name: Replace tokens
uses: cschleiden/replace-tokens@v1
with:
files: '["${{ github.workspace }}/generated/homebrew/falu.rb","${{ github.workspace }}/generated/scoop/falu.json"]'
- name: Upload Artifact (releases)
uses: actions/upload-artifact@v4
with:
path: ${{ github.workspace }}/generated
name: releases-generated
retention-days: 1
Release:
runs-on: ubuntu-latest
needs: [ DockerMerge, Checksum, Packaging ]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download Artifact (releases)
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/releases
pattern: releases-*
merge-multiple: true
- name: Upload Release
uses: ncipollo/release-action@v1
with:
# comma-separated values ('>' will make it a single line)
artifacts: >
${{ github.workspace }}/releases/checksum.txt,
${{ github.workspace }}/releases/falu-*.deb,
${{ github.workspace }}/releases/falu-*.rpm,
${{ github.workspace }}/releases/falu-*.tar.gz,
${{ github.workspace }}/releases/falu-*.zip
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
allowUpdates: true
- name: Update homebrew tap repository
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.RELEASING_GITHUB_TOKEN }}
with:
source_file: '${{ github.workspace }}/releases/homebrew/falu.rb'
destination_repo: 'faluapp/homebrew-falu-cli'
user_email: '[email protected]'
user_name: 'falu-ci'
commit_message: 'Update homebrew tap to ${{ needs.Packaging.outputs.BINARIES_VERSION }}'
- name: Update scoop bucket repository
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.RELEASING_GITHUB_TOKEN }}
with:
source_file: '${{ github.workspace }}/releases/scoop/falu.json'
destination_repo: 'faluapp/scoop-falu-cli'
user_email: '[email protected]'
user_name: 'falu-ci'
commit_message: 'Update scoop bucket to ${{ needs.Packaging.outputs.BINARIES_VERSION }}'