-
Notifications
You must be signed in to change notification settings - Fork 59
281 lines (259 loc) · 8.27 KB
/
Copy pathrelease-images.yml
File metadata and controls
281 lines (259 loc) · 8.27 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
name: release-images
on:
# Run as soon as the tag workflow finishes
workflow_run:
workflows: ["tag-repo-version"]
types: [completed]
jobs:
build-and-push:
# Only run if the tag workflow succeeded
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
# The commit that tag-repo-version ran on (the tag points at this)
SOURCE_SHA: ${{ github.event.workflow_run.head_sha }}
strategy:
matrix:
service: [web, worker]
steps:
- name: Checkout (full history for tags)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --tags --force
- name: Resolve the tag that points at the workflow SHA
id: tag
shell: bash
run: |
set -euo pipefail
echo "SOURCE_SHA=${SOURCE_SHA}"
# Find tags that point at exactly this SHA; pick semver-ish vX.Y.Z
TAG=$(git tag --points-at "${SOURCE_SHA}" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n1 || true)
if [ -z "${TAG}" ]; then
echo "No vX.Y.Z tag found pointing at ${SOURCE_SHA}"
echo "Known tags for debugging:"
git tag --points-at "${SOURCE_SHA}" || true
exit 1
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "Resolved tag: ${TAG}"
- name: Check out the exact tagged revision
run: git checkout ${{ steps.tag.outputs.tag }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build & push ${{ matrix.service }}
uses: docker/build-push-action@v6
with:
context: .
file: apps/${{ matrix.service }}/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
# Tag with the resolved vX.Y.Z + "latest"
tags: |
ghcr.io/${{ github.repository_owner }}/kurrier-${{ matrix.service }}:${{ steps.tag.outputs.tag }}
ghcr.io/${{ github.repository_owner }}/kurrier-${{ matrix.service }}:latest
build-args: |
NODE_ENV=production
provenance: true
sbom: true
github-release:
needs: build-and-push
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
# tag_name: v${{ steps.v.outputs.ver }}
# name: v${{ steps.v.outputs.ver }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#name: release-images
#
#on:
# # Run as soon as the tag workflow finishes
# workflow_run:
# workflows: ["tag-repo-version"]
# types: [completed]
#
#jobs:
# build-and-push:
# # Only run if the tag workflow succeeded
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
#
# env:
# # The commit that tag-repo-version ran on (the tag points at this)
# SOURCE_SHA: ${{ github.event.workflow_run.head_sha }}
#
# strategy:
# matrix:
# service: [web, worker]
#
# steps:
# - name: Checkout (full history for tags)
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
#
# - name: Fetch tags
# run: git fetch --tags --force
#
# - name: Resolve the tag that points at the workflow SHA
# id: tag
# shell: bash
# run: |
# set -euo pipefail
# echo "SOURCE_SHA=${SOURCE_SHA}"
# # Find tags that point at exactly this SHA; pick semver-ish vX.Y.Z
# TAG=$(git tag --points-at "${SOURCE_SHA}" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n1 || true)
# if [ -z "${TAG}" ]; then
# echo "No vX.Y.Z tag found pointing at ${SOURCE_SHA}"
# echo "Known tags for debugging:"
# git tag --points-at "${SOURCE_SHA}" || true
# exit 1
# fi
# echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
# echo "Resolved tag: ${TAG}"
#
# - name: Check out the exact tagged revision
# run: git checkout ${{ steps.tag.outputs.tag }}
#
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
#
# - name: Set up Buildx
# uses: docker/setup-buildx-action@v3
#
# - name: Log in to GHCR
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Build & push ${{ matrix.service }}
# uses: docker/build-push-action@v6
# with:
# context: .
# file: apps/${{ matrix.service }}/Dockerfile
# push: true
# platforms: linux/amd64,linux/arm64
# # Tag with the resolved vX.Y.Z + "latest"
# tags: |
# ghcr.io/${{ github.repository_owner }}/kurrier-${{ matrix.service }}:${{ steps.tag.outputs.tag }}
# ghcr.io/${{ github.repository_owner }}/kurrier-${{ matrix.service }}:latest
# build-args: |
# NODE_ENV=production
# provenance: true
# sbom: true
#
# github-release:
# needs: build-and-push
# runs-on: ubuntu-latest
# permissions:
# contents: write
# steps:
# - name: Read version from repo-version package
# id: v
# run: |
# FILE=packages/repo-version/package.json
# if [ ! -f "$FILE" ]; then
# echo "::error::$FILE not found"; exit 1
# fi
# VER=$(jq -r .version "$FILE")
# if [ -z "$VER" ] || [ "$VER" = "null" ]; then
# echo "::error::version missing in $FILE"; exit 1
# fi
# echo "ver=$VER" >> "$GITHUB_OUTPUT"
# echo "Resolved version: $VER"
#
# - name:
# Guard: version must be present
# run: |
# if [ -z "${{ steps.v.outputs.ver }}" ]; then
# echo "::error::Empty version output"; exit 1
# fi
#
# # (Optional) Create the tag using the SAME id
# - name: Create tag if missing and push
# env:
# VER: ${{ steps.v.outputs.ver }}
# run: |
# set -euo pipefail
# TAG="v${VER}"
# git fetch --tags --force
# if git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then
# echo "Tag $TAG already exists on origin; nothing to do."
# exit 0
# fi
# git tag -a "$TAG" -m "Release $TAG"
# git push origin "$TAG"
#
# - name: Create GitHub Release
# uses: softprops/action-gh-release@v2
# with:
# tag_name: ${{ github.ref_name }}
# name: ${{ github.ref_name }}
# generate_release_notes: true
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#name: release-images
#on:
# push:
# tags: ['v*.*.*'] # build on release tags; adjust if you want main pushes too
#
#jobs:
# build-and-push:
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
# strategy:
# matrix:
# service: [web, worker]
# steps:
# - uses: actions/checkout@v4
#
# - uses: docker/setup-qemu-action@v3
# - uses: docker/setup-buildx-action@v3
#
# - uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Build & push ${{ matrix.service }}
# uses: docker/build-push-action@v6
# with:
# context: .
# file: apps/${{ matrix.service }}/Dockerfile
# push: true
# platforms: linux/amd64,linux/arm64
# tags: |
# ghcr.io/${{ github.repository_owner }}/kurrier-${{ matrix.service }}:${{ github.ref_name }}
# ghcr.io/${{ github.repository_owner }}/kurrier-${{ matrix.service }}:latest
# build-args: |
# NODE_ENV=production
# provenance: true
# sbom: true