Repository navigation
448 lines (389 loc) · 17.1 KB
/
Copy pathrelease.yml
File metadata and controls
448 lines (389 loc) · 17.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
name: release
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.1.0)"
required: true
permissions:
contents: write
issues: read
packages: write
pull-requests: read
jobs:
prepare:
name: Prepare ${{ inputs.version }}
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- name: Restrict workflow to maintainers/admins
env:
GH_TOKEN: ${{ github.token }}
run: |
permission="$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$GITHUB_ACTOR/permission" --jq .permission)"
if [[ "$permission" != "admin" ]]; then
echo "::error::$GITHUB_ACTOR has $permission permission on $GITHUB_REPOSITORY, and this workflow requires admin"
exit 1
fi
- name: Validate release version is semantic
env:
VERSION: ${{ inputs.version }}
run: |
SEMVER='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*)?$'
if [[ ! "$VERSION" =~ $SEMVER ]]; then
echo "::error::Release version '$VERSION' is not a valid semantic version (expected x.y.z or x.y.z-prerelease, e.g. 1.2.3 or 1.2.3-rc1). Aborting."
exit 1
fi
- name: Validate release version against branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ inputs.version }}"
REF="${{ github.ref_name }}"
REPO="${{ github.repository }}"
if [[ "$REF" == support/* ]]; then
MAJOR="${REF#support/}"; MAJOR="${MAJOR%%.*}"
if [[ "$VERSION" != "$MAJOR".* ]]; then
echo "::error::Release version '$VERSION' is not part of the '$REF' line (expected ${MAJOR}.x). Aborting."
exit 1
fi
elif [[ "$REF" == "develop" ]]; then
MAJOR="${VERSION%%.*}"
if git ls-remote --exit-code --heads \
"https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git" \
"support/${MAJOR}.x" >/dev/null 2>&1; then
echo "::error::A 'support/${MAJOR}.x' branch exists; release version '$VERSION' from that branch, not develop. Aborting."
exit 1
fi
fi
- name: Cache Homebrew
uses: actions/cache@v6
with:
path: /home/linuxbrew/.linuxbrew
key: ${{ runner.os }}-homebrew
- name: Install Homebrew
run: |
if ! command -v brew >/dev/null 2>&1; then
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew --version
- name: Install git-flow AVH
run: |
git clone https://github.com/petervanderdoes/gitflow-avh.git
cd gitflow-avh
sudo make install
- name: Configure git credentials
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global credential.helper store
echo "https://x-access-token:${{ secrets.GITFLOW_RELEASES_TOKEN }}@github.com" > ~/.git-credentials
- name: Checkout sources on base branch
uses: actions/checkout@v7
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
persist-credentials: false
- name: Pin maven.packages.aklivity.io to IPv4
run: |
ipv4=$(getent ahostsv4 maven.packages.aklivity.io | awk 'NR==1{print $1}')
if [ -n "$ipv4" ]; then
echo "$ipv4 maven.packages.aklivity.io" | sudo tee -a /etc/hosts
fi
- name: Initialize GitFlow
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
git fetch origin main
git branch main origin/main || true
git fetch origin develop
git branch develop origin/develop || true
git flow init -df
- name: Start GitFlow release
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
git flow release start ${{ inputs.version }} ${{ github.ref_name }}
- name: Setup JDK
uses: actions/setup-java@v5
with:
java-version: 25
distribution: zulu
- name: Update POM versions on release branch
run: |
./mvnw org.codehaus.mojo:versions-maven-plugin:2.18.0:set -DgenerateBackupPoms=false -DnewVersion=${{ inputs.version }}
- name: Cache gitflow-changelog events
uses: actions/cache@v6
with:
path: .gitflow-changelog-cache.json
key: gitflow-changelog-v3-${{ github.repository }}-${{ github.run_id }}
restore-keys: |
gitflow-changelog-v3-${{ github.repository }}-
- name: Generate CHANGELOG on release branch
id: changelog
continue-on-error: true
uses: aklivity/gitflow-changelog@v0
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Warn if CHANGELOG generation failed on release branch
if: steps.changelog.outcome == 'failure'
run: echo "::warning::CHANGELOG generation failed on release/${{ inputs.version }}; release/${{ inputs.version }} will carry the previous CHANGELOG.md unchanged."
- name: Commit POM versions and CHANGELOG on release branch
run: git commit -a -m "Prepare release ${{ inputs.version }}"
- name: No-merge release branch into base branch
run: |
git config merge.ours.driver true
git fetch origin ${{ github.ref_name }}
git checkout ${{ github.ref_name }}
git merge -s ours release/${{ inputs.version }} \
-m "No-merge release ${{ inputs.version }} into ${{ github.ref_name }}"
- name: Push changes to base branch and release branch
run: |
git push origin ${{ github.ref_name }} release/${{ inputs.version }}
deploy:
name: Deploy ${{ inputs.version }}
runs-on: ubuntu-24.04
timeout-minutes: 120
needs: prepare
steps:
- name: Checkout GitHub sources
uses: actions/checkout@v7
with:
ref: release/${{ inputs.version }}
fetch-depth: 0
- name: Pin maven.packages.aklivity.io to IPv4
run: |
ipv4=$(getent ahostsv4 maven.packages.aklivity.io | awk 'NR==1{print $1}')
if [ -n "$ipv4" ]; then
echo "$ipv4 maven.packages.aklivity.io" | sudo tee -a /etc/hosts
fi
- name: Setup JDK
uses: actions/setup-java@v5
with:
java-version: 25
distribution: zulu
server-id: github
server-username: GITHUB_ACTOR
server-password: GITHUB_TOKEN
- name: Route Docker Hub pulls through mirror.gcr.io
run: |
sudo mkdir -p /etc/docker
if [ -f /etc/docker/daemon.json ]; then
sudo jq '. + {"registry-mirrors": ["https://mirror.gcr.io"]}' /etc/docker/daemon.json > /tmp/daemon.json
else
echo '{"registry-mirrors": ["https://mirror.gcr.io"]}' > /tmp/daemon.json
fi
sudo mv /tmp/daemon.json /etc/docker/daemon.json
sudo systemctl restart docker
timeout 30 sh -c 'until docker info >/dev/null 2>&1; do sleep 1; done'
- name: Create Maven cache key input
run: |
find . -name pom.xml -print0 \
| sort -z \
| xargs -0 sed -E '0,/<version>[^<]+<\/version>/s//<version>IGNORED<\/version>/' \
> .maven-cache-key
- name: Cache Maven packages
uses: actions/cache@v6
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('.maven-cache-key') }}
restore-keys: ${{ runner.os }}-m2-
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine docker tags
id: tag
run: .github/scripts/release-tags.sh "${{ inputs.version }}" >> "$GITHUB_OUTPUT"
- name: Deploy via Maven
run: |
./mvnw -B -U -nsu -ntp -Dmaven.build.cache.enabled=false clean deploy -Drelease -Ddocker.latest.tag=${{ steps.tag.outputs.latest }} -DskipTests
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Uncache Maven project release artifacts
if: always()
run: |
GROUP_ID=`./mvnw help:evaluate -Dexpression=project.groupId -q -DforceStdout`
rm -fr ~/.m2/repository/$(echo $GROUP_ID | tr . /)
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup buildx to publish multi-arch images
run: |
# The docker-container driver runs its own BuildKit instance that does
# not inherit the daemon's registry-mirrors, so scope the mirror to
# docker.io here too. ghcr.io is not matched and pulls direct.
cat > /tmp/buildkitd.toml <<'EOF'
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
EOF
docker buildx create --driver docker-container --name release --use --config /tmp/buildkitd.toml
- name: Extract docker build contexts
run: |
find cloud/docker-image/target/docker -name docker-build.tar -print0 | while IFS= read -r -d '' tar; do
ctx="${tar%.tar}"
rm -rf "$ctx" && mkdir -p "$ctx"
tar -xf "$tar" -C "$ctx"
done
- name: Publish zilla image to GitHub Container Registry
uses: docker/build-push-action@v7
with:
context: cloud/docker-image/target/docker/ghcr.io/aklivity/zilla/${{ inputs.version }}/tmp/docker-build
platforms: linux/amd64,linux/arm64
push: true
provenance: false
cache-from: type=registry,ref=ghcr.io/aklivity/zilla-buildcache:latest
cache-to: type=registry,ref=ghcr.io/aklivity/zilla-buildcache:latest,mode=max
tags: |
ghcr.io/aklivity/zilla:${{ inputs.version }}
${{ steps.tag.outputs.minor && format('ghcr.io/aklivity/zilla:{0}', steps.tag.outputs.minor) || '' }}
${{ steps.tag.outputs.major && format('ghcr.io/aklivity/zilla:{0}', steps.tag.outputs.major) || '' }}
${{ steps.tag.outputs.latest && 'ghcr.io/aklivity/zilla:latest' || '' }}
- name: Publish zilla-alpine image to GitHub Container Registry
uses: docker/build-push-action@v7
with:
context: cloud/docker-image/target/docker/ghcr.io/aklivity/zilla/${{ inputs.version }}-alpine/tmp/docker-build
file: cloud/docker-image/target/docker/ghcr.io/aklivity/zilla/${{ inputs.version }}-alpine/tmp/docker-build/alpine.Dockerfile
platforms: linux/amd64
push: true
provenance: false
cache-from: type=registry,ref=ghcr.io/aklivity/zilla-buildcache:alpine
cache-to: type=registry,ref=ghcr.io/aklivity/zilla-buildcache:alpine,mode=max
tags: |
ghcr.io/aklivity/zilla:${{ inputs.version }}-alpine
${{ steps.tag.outputs.minor && format('ghcr.io/aklivity/zilla:{0}-alpine', steps.tag.outputs.minor) || '' }}
${{ steps.tag.outputs.major && format('ghcr.io/aklivity/zilla:{0}-alpine', steps.tag.outputs.major) || '' }}
${{ steps.tag.outputs.latest && 'ghcr.io/aklivity/zilla:alpine' || '' }}
- name: Setup helm
uses: azure/setup-helm@v5
- name: Publish zilla chart to GitHub Container Registry
run: |
helm push cloud/helm-chart/target/helm/repo/zilla-${{ inputs.version }}.tgz oci://ghcr.io/aklivity/charts
finalize:
name: Finalize ${{ inputs.version }}
runs-on: ubuntu-24.04
timeout-minutes: 30
needs: deploy
steps:
- name: Cache Homebrew
uses: actions/cache@v6
with:
path: /home/linuxbrew/.linuxbrew
key: ${{ runner.os }}-homebrew
- name: Install Homebrew
run: |
if ! command -v brew >/dev/null 2>&1; then
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew --version
- name: Install git-flow AVH
run: |
git clone https://github.com/petervanderdoes/gitflow-avh.git
cd gitflow-avh
sudo make install
- name: Configure git credentials
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global credential.helper store
echo "https://x-access-token:${{ secrets.GITFLOW_RELEASES_TOKEN }}@github.com" > ~/.git-credentials
- name: Checkout GitHub sources on release branch
uses: actions/checkout@v7
with:
ref: release/${{ inputs.version }}
fetch-depth: 0
persist-credentials: false
- name: Initialize GitFlow
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
git fetch origin main
git branch main origin/main || true
git fetch origin develop
git branch develop origin/develop || true
git fetch origin ${{ github.ref_name }}
git branch ${{ github.ref_name }} origin/${{ github.ref_name }} || true
git flow init -df
- name: Determine release version facts
id: tag
run: .github/scripts/release-tags.sh "${{ inputs.version }}" >> "$GITHUB_OUTPUT"
- name: Extract release notes from CHANGELOG on release branch
if: steps.tag.outputs.semver == 'true'
run: |
NOTES="$RUNNER_TEMP/release-notes.md"
CHANGELOG="$RUNNER_TEMP/CHANGELOG.md"
git show release/${{ inputs.version }}:CHANGELOG.md > "$CHANGELOG" || true
.github/scripts/release-notes.sh "${{ inputs.version }}" "$CHANGELOG" > "$NOTES"
if [ ! -s "$NOTES" ]; then
echo "::warning::CHANGELOG.md on release/${{ inputs.version }} has no [${{ inputs.version }}] section; the GitHub Release will link to the full changelog instead."
PREVIOUS=$({ git tag --list | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' || true; echo "${{ inputs.version }}"; } \
| sort -V -u | grep -B1 -x -- "${{ inputs.version }}" | head -n1)
{
echo "## [${{ inputs.version }}](https://github.com/${{ github.repository }}/tree/${{ inputs.version }})"
echo
if [ "$PREVIOUS" != "${{ inputs.version }}" ]; then
echo "[Full Changelog](https://github.com/${{ github.repository }}/compare/$PREVIOUS...${{ inputs.version }})"
fi
} > "$NOTES"
fi
- name: Tag the release
if: startsWith(github.ref_name, 'support/')
run: |
git tag -a ${{ inputs.version }} -m "${{ inputs.version }}" release/${{ inputs.version }}
git push origin refs/tags/${{ inputs.version }}
- name: Finish release
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
git config --local "gitflow.branch.release/${{ inputs.version }}.base" ${{ github.ref_name }}
if [[ "${{ github.ref_name }}" == support/* ]]; then
git flow release finish -p -n ${{ inputs.version }}
else
git flow release finish -p ${{ inputs.version }} -m "${{ inputs.version }}"
fi
- name: Checkout base branch for CHANGELOG
run: |
git fetch origin ${{ github.ref_name }}
git checkout ${{ github.ref_name }}
- name: Cache gitflow-changelog events
uses: actions/cache@v6
with:
path: .gitflow-changelog-cache.json
key: gitflow-changelog-v3-${{ github.repository }}-${{ github.run_id }}
restore-keys: |
gitflow-changelog-v3-${{ github.repository }}-
- name: Generate CHANGELOG on base branch
id: changelog
continue-on-error: true
uses: aklivity/gitflow-changelog@v0
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Warn if CHANGELOG generation failed on base branch
if: steps.changelog.outcome == 'failure'
run: echo "::warning::CHANGELOG generation failed on ${{ github.ref_name }}; the release itself (tag, merge) already completed successfully — rerun CHANGELOG generation manually or it will catch up next release."
- name: Commit and push CHANGELOG on base branch (if needed)
run: |
git diff --quiet && git diff --cached --quiet || git commit -a -m "Update CHANGELOG.md"
git push origin ${{ github.ref_name }}
- name: Create GitHub Release
if: steps.tag.outputs.semver == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NOTES="$RUNNER_TEMP/release-notes.md"
if gh release view ${{ inputs.version }} --repo ${{ github.repository }} >/dev/null 2>&1; then
gh release edit ${{ inputs.version }} --repo ${{ github.repository }} \
--title ${{ inputs.version }} \
--notes-file "$NOTES" \
--latest=${{ steps.tag.outputs.highest }}
else
gh release create ${{ inputs.version }} --repo ${{ github.repository }} \
--title ${{ inputs.version }} \
--notes-file "$NOTES" \
--latest=${{ steps.tag.outputs.highest }} \
--verify-tag
fi
- name: Skip GitHub Release for pre-release version
if: steps.tag.outputs.semver != 'true'
run: echo "::notice::${{ inputs.version }} is not an x.y.z release version; skipping GitHub Release creation."