-
Notifications
You must be signed in to change notification settings - Fork 0
456 lines (444 loc) · 14.1 KB
/
ci.yml
File metadata and controls
456 lines (444 loc) · 14.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
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
name: CI
on:
pull_request:
paths-ignore:
- "docs/**"
- "**/*.md"
- ".gitignore"
- ".github/ISSUE_TEMPLATE/**"
- ".github/workflows/docs.yml"
push:
branches:
- main
tags:
- "v*"
paths-ignore:
- "docs/**"
- "**/*.md"
- ".gitignore"
- ".github/ISSUE_TEMPLATE/**"
- ".github/workflows/docs.yml"
workflow_dispatch:
inputs:
version:
description: "Release version, for example v0.1.0. Leave empty for a CI build."
required: false
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
HUSKY: "0"
REGISTRY: ghcr.io
jobs:
metadata:
name: Metadata
runs-on: ubuntu-latest
outputs:
created: ${{ steps.resolve.outputs.created }}
is_release: ${{ steps.resolve.outputs.is_release }}
package_version: ${{ steps.resolve.outputs.package_version }}
publish_image: ${{ steps.resolve.outputs.publish_image }}
version: ${{ steps.resolve.outputs.version }}
steps:
- name: Check out
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Resolve build metadata
id: resolve
env:
REQUESTED_VERSION: ${{ github.event.inputs.version || '' }}
run: scripts/resolve-build-metadata.sh >> "$GITHUB_OUTPUT"
frontend:
name: Frontend
runs-on: ubuntu-latest
defaults:
run:
working-directory: ident
steps:
- name: Check out
uses: actions/checkout@v6
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: "24"
- name: Enable Corepack
run: corepack enable
- name: Install
run: pnpm install --frozen-lockfile
- name: Format
run: pnpm format:check
- name: Lint
run: pnpm lint
- name: Test
run: pnpm test
- name: Build
run: pnpm build
backend:
name: Backend
runs-on: ubuntu-latest
defaults:
run:
working-directory: identd
steps:
- name: Check out
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: identd/go.mod
cache-dependency-path: identd/go.sum
- name: Format
run: |
files="$(gofmt -l .)"
if [ -n "$files" ]; then
printf '%s\n' "$files"
exit 1
fi
- name: Lint
run: go vet ./...
- name: Test
run: go test ./...
scripts-test:
name: Scripts Test
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v6
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: "24"
- name: Test
run: node --test scripts/*.test.mjs
artifacts:
name: Artifacts ${{ matrix.id }}
runs-on: ubuntu-latest
needs:
- metadata
- frontend
- backend
- scripts-test
permissions:
contents: read
id-token: write
attestations: write
artifact-metadata: write
strategy:
fail-fast: false
matrix:
include:
- id: linux-amd64
goos: linux
goarch: amd64
goarm: ""
package: deb
nfpm_arch: amd64
- id: linux-arm64
goos: linux
goarch: arm64
goarm: ""
package: deb
nfpm_arch: arm64
- id: linux-armv7
goos: linux
goarch: arm
goarm: "7"
package: deb
nfpm_arch: arm7
- id: darwin-amd64
goos: darwin
goarch: amd64
goarm: ""
package: ""
nfpm_arch: ""
- id: darwin-arm64
goos: darwin
goarch: arm64
goarm: ""
package: ""
nfpm_arch: ""
- id: freebsd-amd64
goos: freebsd
goarch: amd64
goarm: ""
package: ""
nfpm_arch: ""
- id: freebsd-arm64
goos: freebsd
goarch: arm64
goarm: ""
package: ""
nfpm_arch: ""
steps:
- name: Check out
uses: actions/checkout@v6
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: "24"
- name: Enable Corepack
run: corepack enable
- name: Install web dependencies
working-directory: ident
run: pnpm install --frozen-lockfile
- name: Build web dist
working-directory: ident
run: pnpm build
- name: Prepare embedded web assets
run: |
mkdir -p identd/web
rsync -a --delete --exclude .keep ident/dist/ identd/web/
touch identd/web/.keep
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: identd/go.mod
cache-dependency-path: identd/go.sum
- name: Install nFPM
if: matrix.package == 'deb'
run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
- name: Build binary
env:
CREATED: ${{ needs.metadata.outputs.created }}
VERSION: ${{ needs.metadata.outputs.version }}
run: |
set -eu
mkdir -p dist/out
artifact="identd-${{ matrix.id }}"
versioned="identd-$VERSION-${{ matrix.id }}"
(
cd identd
env CGO_ENABLED=0 GOOS="${{ matrix.goos }}" GOARCH="${{ matrix.goarch }}" GOARM="${{ matrix.goarm }}" \
go build -tags embed -trimpath \
-ldflags "-s -w -X main.version=$VERSION -X main.commit=$GITHUB_SHA -X main.buildDate=$CREATED" \
-o "../dist/out/$artifact" .
)
cp "dist/out/$artifact" "dist/out/$versioned"
tmp="$(mktemp -d)"
cp "dist/out/$artifact" "$tmp/identd"
tar -czf "dist/out/$artifact.tar.gz" -C "$tmp" identd
cp "dist/out/$artifact.tar.gz" "dist/out/$versioned.tar.gz"
- name: Build package
if: matrix.package == 'deb'
env:
IDENT_ARCH: ${{ matrix.nfpm_arch }}
IDENT_VERSION: ${{ needs.metadata.outputs.package_version }}
run: |
mkdir -p dist/packages
cp "dist/out/identd-${{ matrix.id }}" dist/identd
nfpm package --packager deb --config packaging/nfpm.yaml --target dist/packages/
cp dist/packages/* dist/out/
cp dist/packages/*.deb "dist/out/identd-${{ matrix.id }}.deb"
- name: Calculate checksums
run: |
find dist/out -maxdepth 1 -type f ! -name 'CHECKSUMS-*' -print0 \
| sort -z \
| xargs -0 sha256sum > "dist/out/CHECKSUMS-${{ matrix.id }}"
- name: Attest artifacts
uses: actions/attest-build-provenance@v4
with:
subject-path: dist/out/*
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: ident-artifacts-${{ matrix.id }}
path: dist/out/*
publish-release:
name: Publish Release
if: needs.metadata.outputs.is_release == 'true'
runs-on: ubuntu-latest
needs:
- metadata
- artifacts
permissions:
contents: write
id-token: write
attestations: write
artifact-metadata: write
steps:
- name: Download release artifacts
uses: actions/download-artifact@v8
with:
pattern: ident-artifacts-*
path: dist/releases
merge-multiple: true
- name: Calculate aggregate checksums
run: |
rm -f dist/releases/SHA256SUMS
find dist/releases -maxdepth 1 -type f -name 'CHECKSUMS-*' -delete
find dist/releases -maxdepth 1 -type f ! -name SHA256SUMS -print0 \
| sort -z \
| xargs -0 sha256sum > dist/releases/SHA256SUMS
- name: Attest release artifacts
uses: actions/attest-build-provenance@v4
with:
subject-path: dist/releases/*
- name: Upload workflow artifacts
uses: actions/upload-artifact@v7
with:
name: ident-release-artifacts
path: dist/releases/*
- name: Create GitHub release
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.metadata.outputs.version }}
run: |
if gh release view "$VERSION" >/dev/null 2>&1; then
gh release upload "$VERSION" dist/releases/* --clobber
gh release edit "$VERSION" --latest
else
gh release create "$VERSION" dist/releases/* --title "$VERSION" --notes "Release $VERSION" --latest
fi
image-build:
name: Image ${{ matrix.platform }}
runs-on: ${{ matrix.runner }}
needs:
- metadata
- frontend
- backend
- scripts-test
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- id: linux-amd64
platform: linux/amd64
runner: ubuntu-latest
qemu: false
- id: linux-arm64
platform: linux/arm64
runner: ubuntu-24.04-arm
qemu: false
- id: linux-armv7
platform: linux/arm/v7
runner: ubuntu-latest
qemu: true
steps:
- name: Check out
uses: actions/checkout@v6
- name: Set image name
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
- name: Set up QEMU
if: matrix.qemu
uses: docker/setup-qemu-action@v4
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
if: needs.metadata.outputs.publish_image == 'true'
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build image
if: needs.metadata.outputs.publish_image != 'true'
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
provenance: mode=max
sbom: true
build-args: |
VERSION=${{ needs.metadata.outputs.version }}
COMMIT=${{ github.sha }}
BUILD_DATE=${{ needs.metadata.outputs.created }}
- name: Build and push by digest
id: build
if: needs.metadata.outputs.publish_image == 'true'
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha,scope=${{ matrix.platform }}
cache-to: type=gha,scope=${{ matrix.platform }},mode=max,ignore-error=true
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
provenance: mode=max
sbom: true
build-args: |
VERSION=${{ needs.metadata.outputs.version }}
COMMIT=${{ github.sha }}
BUILD_DATE=${{ needs.metadata.outputs.created }}
- name: Export digest
if: needs.metadata.outputs.publish_image == 'true'
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
if: needs.metadata.outputs.publish_image == 'true'
uses: actions/upload-artifact@v7
with:
name: digest-${{ matrix.id }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
image-merge:
name: Image Manifest
if: needs.metadata.outputs.publish_image == 'true'
runs-on: ubuntu-latest
needs:
- metadata
- image-build
permissions:
contents: read
packages: write
id-token: write
attestations: write
artifact-metadata: write
steps:
- name: Set image name
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
- name: Download digests
uses: actions/download-artifact@v8
with:
path: /tmp/digests
pattern: digest-*
merge-multiple: true
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ needs.metadata.outputs.version }},enable=${{ needs.metadata.outputs.is_release == 'true' }}
type=raw,value=latest,enable=${{ needs.metadata.outputs.is_release == 'true' }}
type=raw,value=staging,enable=${{ needs.metadata.outputs.is_release != 'true' }}
- name: Create manifest list and push
id: manifest
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
digest="$(docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} --format '{{json .Manifest.Digest}}' | tr -d '"')"
echo "digest=$digest" >> "$GITHUB_OUTPUT"
- name: Attest container image
uses: actions/attest-build-provenance@v4
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.manifest.outputs.digest }}
push-to-registry: true