-
Notifications
You must be signed in to change notification settings - Fork 0
363 lines (324 loc) · 12.3 KB
/
release.yml
File metadata and controls
363 lines (324 loc) · 12.3 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
name: Release
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
packages: write
issues: write
pull-requests: write
id-token: write
attestations: write
statuses: write
jobs:
# Job 1: Run all CI checks first
ci:
name: CI Checks
uses: ./.github/workflows/ci.yml
# Job 2: Semantic Release
release:
name: Semantic Release
needs: ci
runs-on: ubuntu-latest
outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.tool-versions'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Get pnpm store directory
shell: bash
run: echo "STORE_PATH=$(pnpm store path --silent)" >> "$GITHUB_ENV"
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run semantic-release
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HUSKY: 0
run: |
npx semantic-release
# Check if a new release was published by looking for the tag
if git describe --tags --exact-match HEAD 2>/dev/null; then
VERSION=$(git describe --tags --exact-match HEAD | sed 's/^v//')
echo "new_release_published=true" >> "$GITHUB_OUTPUT"
echo "new_release_version=$VERSION" >> "$GITHUB_OUTPUT"
else
echo "new_release_published=false" >> "$GITHUB_OUTPUT"
fi
# Job 3: Build Docker images per platform
# Uses native ARM runners for public repos, QEMU emulation for private repos
docker-build:
name: Build ${{ matrix.image }} (${{ matrix.arch }})
needs: release
if: needs.release.outputs.new_release_published == 'true'
runs-on: ${{ matrix.arch == 'arm64' && github.event.repository.visibility == 'public' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
strategy:
fail-fast: false
matrix:
include:
# nginx - amd64
- image: nginx
dockerfile: docker/Dockerfile.nginx.prod
platform: linux/amd64
arch: amd64
# nginx - arm64
- image: nginx
dockerfile: docker/Dockerfile.nginx.prod
platform: linux/arm64
arch: arm64
# backend - amd64
- image: backend
dockerfile: docker/Dockerfile.backend.prod
platform: linux/amd64
arch: amd64
# backend - arm64
- image: backend
dockerfile: docker/Dockerfile.backend.prod
platform: linux/arm64
arch: arm64
# sabredav - amd64
- image: sabredav
dockerfile: docker/Dockerfile.sabredav.prod
platform: linux/amd64
arch: amd64
# sabredav - arm64
- image: sabredav
dockerfile: docker/Dockerfile.sabredav.prod
platform: linux/arm64
arch: arm64
# osm-import - amd64
- image: osm-import
dockerfile: docker/Dockerfile.osm-import
platform: linux/amd64
arch: amd64
# osm-import - arm64
- image: osm-import
dockerfile: docker/Dockerfile.osm-import
platform: linux/arm64
arch: arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: v${{ needs.release.outputs.new_release_version }}
- name: Set up QEMU
if: matrix.arch == 'arm64' && github.event.repository.visibility != 'public'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-${{ matrix.image }}
tags: |
type=raw,value=${{ needs.release.outputs.new_release_version }}-${{ matrix.arch }}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platform }}
# Disable provenance/sbom for individual builds - they create manifest lists
# which break docker manifest create. Attestation is done at manifest level.
provenance: false
sbom: false
build-args: ${{ matrix.image == 'nginx' && format('VITE_SENTRY_DSN={0}', secrets.VITE_SENTRY_DSN) || '' }}
# Multi-layer caching strategy for maximum cache hits
cache-from: |
type=gha,scope=${{ matrix.image }}-${{ matrix.arch }}
type=registry,ref=ghcr.io/${{ github.repository }}-${{ matrix.image }}:buildcache-${{ matrix.arch }}
cache-to: |
type=gha,mode=max,scope=${{ matrix.image }}-${{ matrix.arch }}
type=registry,ref=ghcr.io/${{ github.repository }}-${{ matrix.image }}:buildcache-${{ matrix.arch }},mode=max
# Job 4: Create and push multi-arch manifests
docker-manifest:
name: Create ${{ matrix.image }} Manifest
needs: [release, docker-build]
if: needs.release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image:
- nginx
- backend
- sabredav
- osm-import
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest
id: manifest
env:
VERSION: ${{ needs.release.outputs.new_release_version }}
IMAGE: ghcr.io/${{ github.repository }}-${{ matrix.image }}
run: |
# Create manifest for version tag
docker manifest create ${IMAGE}:${VERSION} \
${IMAGE}:${VERSION}-amd64 \
${IMAGE}:${VERSION}-arm64
# Annotate with architecture info
docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-amd64 --arch amd64
docker manifest annotate ${IMAGE}:${VERSION} ${IMAGE}:${VERSION}-arm64 --arch arm64
# Push version manifest and capture digest
DIGEST=$(docker manifest push ${IMAGE}:${VERSION})
echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT"
# Create and push additional tags
for TAG in "${VERSION%.*}" "${VERSION%%.*}" "latest"; do
docker manifest create ${IMAGE}:${TAG} \
${IMAGE}:${VERSION}-amd64 \
${IMAGE}:${VERSION}-arm64
docker manifest annotate ${IMAGE}:${TAG} ${IMAGE}:${VERSION}-amd64 --arch amd64
docker manifest annotate ${IMAGE}:${TAG} ${IMAGE}:${VERSION}-arm64 --arch arm64
docker manifest push ${IMAGE}:${TAG}
done
- name: Attest Docker image
if: ${{ github.event.repository.visibility == 'public' }}
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/${{ github.repository }}-${{ matrix.image }}
subject-digest: ${{ steps.manifest.outputs.digest }}
push-to-registry: true
# Job 5: Build and attach frontend assets
assets:
name: Build Frontend Assets
needs: release
if: needs.release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: v${{ needs.release.outputs.new_release_version }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.tool-versions'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Get pnpm store directory
shell: bash
run: echo "STORE_PATH=$(pnpm store path --silent)" >> "$GITHUB_ENV"
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build frontend
env:
VITE_API_URL: ""
VITE_SENTRY_DSN: ${{ secrets.VITE_SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
pnpm --filter @freundebuch/shared run build
pnpm --filter @freundebuch/frontend run build
- name: Create frontend tarball
env:
VERSION: ${{ needs.release.outputs.new_release_version }}
run: |
cd apps/frontend
tar -czvf "../../frontend-${VERSION}.tar.gz" build/
- name: Attest frontend assets
if: ${{ github.event.repository.visibility == 'public' }}
uses: actions/attest-build-provenance@v2
with:
subject-path: frontend-${{ needs.release.outputs.new_release_version }}.tar.gz
- name: Upload frontend assets to release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.release.outputs.new_release_version }}
files: frontend-${{ needs.release.outputs.new_release_version }}.tar.gz
# Job 6: Deploy to production server
deploy:
name: Deploy to Production
needs: [release, docker-manifest]
if: needs.release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest
steps:
- name: Setup SSH agent
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }}
- name: Add host key to known_hosts
run: |
mkdir -p ~/.ssh
echo "[node4.datenknoten.me]:820 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILOtQWdKnvQYP0gA5tnyYrTt+uGJDek3YGWSHi2M6f35" >> ~/.ssh/known_hosts
- name: Deploy via SSH
env:
DEPLOY_HOST: node4.datenknoten.me
DEPLOY_PORT: 820
DEPLOY_USER: ${{ secrets.DEPLOY_SSH_USER }}
VERSION: ${{ needs.release.outputs.new_release_version }}
run: |
ssh -p "${DEPLOY_PORT}" "${DEPLOY_USER}@${DEPLOY_HOST}" /home/deploy-freundebuch/deploy.sh "${VERSION}"
- name: Send deployment notification
if: success()
env:
WEBHOOK_URL: ${{ secrets.DEPLOYMENT_NOTIFICATION }}
VERSION: ${{ needs.release.outputs.new_release_version }}
REPO: ${{ github.repository }}
run: |
curl -X POST "${WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d "{\"text\": \"✅ **Deployment successful**\n\n**Version:** v${VERSION}\n**Repository:** ${REPO}\n**Release:** https://github.com/${REPO}/releases/tag/v${VERSION}\"}"
# Job 7: Notify on failure
notify-failure:
name: Notify Failure
needs: [ci, release, docker-build, docker-manifest, assets, deploy]
if: always() && contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
steps:
- name: Send failure notification
env:
WEBHOOK_URL: ${{ secrets.DEPLOYMENT_NOTIFICATION }}
REPO: ${{ github.repository }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
curl -X POST "${WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d "{\"text\": \"❌ **Release workflow failed**\n\n**Repository:** ${REPO}\n**Run:** ${RUN_URL}\"}"