Repository navigation
209 lines (202 loc) · 8.33 KB
/
Copy pathrelease.yml
File metadata and controls
209 lines (202 loc) · 8.33 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
# Release: runs when a tag starting with v is pushed (git tag v0.1.0 && git push origin v0.1.0).
# It checks the tag against Cargo.toml and CHANGELOG.md, runs the tests, builds the Linux binary
# and the container image (ghcr.io/<owner>/rostdav), and creates the GitHub release.
name: Release
on:
push:
# a plain filter: GitHub's glob is ambiguous for "+*"; the verify job rejects tags that are no release
tags: ["v*"]
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
verify:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.v.outputs.version }}
steps:
- uses: actions/checkout@v7
- name: Tag, Cargo.toml and CHANGELOG.md agree
id: v
run: |
version="${GITHUB_REF_NAME#v}"
cargo_version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
test "$version" = "$cargo_version" || { echo "tag $version, Cargo.toml $cargo_version"; exit 1; }
grep -q "^## \[$version\]" CHANGELOG.md || { echo "no CHANGELOG.md section for $version"; exit 1; }
echo "version=$version" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.99.1
- uses: Swatinem/rust-cache@v2
- name: Tests
run: cargo test --workspace --locked
# One build per architecture, each on a runner of its own kind (no emulation). The binary in the
# tarball is the one inside the image, built on Debian bookworm, so it runs wherever the image does.
build:
needs: verify
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
- arch: arm64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v7
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the image and check it before anything is pushed
uses: docker/build-push-action@v7
with:
context: .
load: true
tags: rostdav:release-check
cache-from: type=gha,scope=${{ matrix.arch }}
cache-to: type=gha,scope=${{ matrix.arch }},mode=max
- name: Start it and check health, user and data directory mode
run: |
docker run -d --name rd -p 127.0.0.1:18080:8080 rostdav:release-check
for i in $(seq 1 30); do curl -sf http://127.0.0.1:18080/readyz && break; sleep 1; done
curl -sf http://127.0.0.1:18080/readyz
test "$(docker exec rd id -u)" = 10001
test "$(docker exec rd stat -c %a /data)" = 700
docker exec rd rostdav healthcheck
# the admin commands must work beside the running server (ADR 0010)
printf 'korrekt-pferd-batterie\n' | docker exec -i rd rostdav admin user add ci --admin
docker exec rd rostdav admin user list | grep -qw ci
docker rm -f rd
- name: Take the binary out of the image, smoke-test and package it
run: |
id="$(docker create rostdav:release-check)"
docker cp "$id:/usr/local/bin/rostdav" ./rostdav
docker rm "$id"
scripts/smoke.sh ./rostdav
name="rostdav-${{ needs.verify.outputs.version }}-${{ matrix.target }}"
mkdir "$name"
cp rostdav LICENSE-APACHE LICENSE-MIT README.md CHANGELOG.md rostdav.example.toml "$name/"
tar czf "$name.tar.gz" "$name"
sha256sum "$name.tar.gz" > "$name.tar.gz.sha256"
# the bare binary: what the updater of a running server downloads (signed in the release job)
mkdir bare
cp rostdav "bare/$name"
- uses: actions/upload-artifact@v7
with:
name: binary-${{ matrix.arch }}
path: |
rostdav-*.tar.gz*
bare/rostdav-*
if-no-files-found: error
- name: Push this architecture by digest (the tags come in the next job)
id: push
uses: docker/build-push-action@v7
with:
context: .
outputs: type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=${{ matrix.arch }}
- name: Keep the digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.push.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- uses: actions/upload-artifact@v7
with:
name: digest-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
image:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/download-artifact@v8
with:
path: /tmp/digests
pattern: digest-*
merge-multiple: true
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v6
id: meta
with:
images: ghcr.io/${{ github.repository }}
# 0.1.0 -> 0.1.0, 0.1, 0 and latest; a pre-release (0.2.0-rc.1) gets only its own tag
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !contains(github.ref_name, '-') }}
- name: One image name for both architectures
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
- name: Show what was published
run: docker buildx imagetools inspect "ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }}"
release:
needs: [verify, build, image]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
pattern: binary-*
merge-multiple: true
- name: Sign the bare binaries (minisign)
env:
MINISIGN_SECRET_KEY: ${{ secrets.MINISIGN_SECRET_KEY }}
MINISIGN_PASSWORD: ${{ secrets.MINISIGN_PASSWORD }}
run: |
# artifacts keep their folder: bare/rostdav-<version>-<target>
mkdir -p assets
mv bare/rostdav-* assets/ 2>/dev/null || true
if [ -z "$MINISIGN_SECRET_KEY" ]; then
echo "::warning::no MINISIGN_SECRET_KEY secret: the release is not signed, so a running server cannot install it by itself"
exit 0
fi
sudo apt-get update -qq && sudo apt-get install -y minisign
key="$RUNNER_TEMP/minisign.key"
(umask 077; printf '%s\n' "$MINISIGN_SECRET_KEY" > "$key")
for f in assets/rostdav-*; do
printf '%s\n' "$MINISIGN_PASSWORD" | minisign -S -H -s "$key" -m "$f" -x "$f.minisig" -t "rostdav ${{ needs.verify.outputs.version }}"
# it must verify with the public key that is built into the program, or the updater refuses it
minisign -V -p crates/rostdav-app/update-key.pub -m "$f" -x "$f.minisig"
done
shred -u "$key"
- name: Release notes from CHANGELOG.md
run: |
awk -v v="${{ needs.verify.outputs.version }}" '
$0 ~ "^## \\[" v "\\]" { on = 1; next }
on && /^## \[/ { exit }
on { print }
' CHANGELOG.md > notes.md
test -s notes.md
- name: Create the release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
flags=""
case "$GITHUB_REF_NAME" in *-*) flags="--prerelease";; esac
# a tag that is pushed again (after a fix) replaces its release; the tag itself stays
gh release delete "$GITHUB_REF_NAME" --yes 2>/dev/null || true
gh release create "$GITHUB_REF_NAME" $flags --title "Rostdav ${{ needs.verify.outputs.version }}" \
--notes-file notes.md rostdav-*.tar.gz rostdav-*.tar.gz.sha256 assets/rostdav-*