Repository navigation
364 lines (327 loc) · 14.9 KB
/
Copy pathrelease.yml
File metadata and controls
364 lines (327 loc) · 14.9 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
name: Build and release binaries
on:
workflow_dispatch:
inputs:
tag_name:
description: "Release version tag to stamp into the binaries (for example, v1.0.0)"
required: true
type: string
publish_release:
description: "Publish a GitHub release after all platform builds pass"
required: true
default: true
type: boolean
permissions:
contents: read
jobs:
validate:
name: Validate release tag
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Validate version tag and ensure it is unused
env:
GH_TOKEN: ${{ github.token }}
TAG_NAME: ${{ inputs.tag_name }}
PUBLISH_RELEASE: ${{ inputs.publish_release }}
run: |
set -euo pipefail
if [[ "${PUBLISH_RELEASE}" == "true" && "${GITHUB_REF}" != "refs/heads/main" ]]; then
echo "Releases may only be published from the main branch (current ref: ${GITHUB_REF})." >&2
exit 1
fi
tag_pattern='^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
if [[ ! "${TAG_NAME}" =~ $tag_pattern ]]; then
echo "tag_name must be a stable semantic version such as v1.0.0 (got ${TAG_NAME})" >&2
exit 1
fi
if [[ "${PUBLISH_RELEASE}" == "true" ]] && gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${TAG_NAME}" >/dev/null 2>&1; then
echo "Git tag ${TAG_NAME} already exists; choose an unused version tag." >&2
exit 1
fi
build:
name: Build ${{ matrix.asset_id }}
needs: validate
strategy:
fail-fast: false
matrix:
include:
- runner: windows-latest
target: x86_64-pc-windows-msvc
platform: windows
asset_id: windows-x86_64
- runner: windows-11-arm
target: aarch64-pc-windows-msvc
platform: windows
asset_id: windows-aarch64
- runner: ubuntu-24.04
target: x86_64-unknown-linux-gnu
platform: linux
asset_id: linux-amd64
- runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
platform: linux
asset_id: linux-aarch64
- runner: ubuntu-24.04
target: armv7-unknown-linux-gnueabihf
platform: linux
asset_id: linux-armv7
cross_openssl: true
- runner: ubuntu-24.04
target: riscv64gc-unknown-linux-gnu
platform: linux
asset_id: linux-riscv64
cross_openssl: true
- runner: ubuntu-24.04
target: x86_64-unknown-linux-musl
platform: linux
asset_id: linux-musl-amd64
cross_openssl: true
- runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
platform: linux
asset_id: linux-musl-aarch64
cross_openssl: true
- runner: macos-15-intel
target: x86_64-apple-darwin
platform: macos
asset_id: macos-x86_64
- runner: macos-15
target: aarch64-apple-darwin
platform: macos
asset_id: macos-aarch64
- runner: ubuntu-24.04
target: aarch64-linux-android
platform: android
asset_id: android-termux-aarch64
runs-on: ${{ matrix.runner }}
timeout-minutes: 90
steps:
- name: Check out source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set Cargo package version from release tag (Windows)
if: runner.os == 'Windows'
shell: pwsh
env:
TAG_NAME: ${{ inputs.tag_name }}
run: |
$version = $env:TAG_NAME.Substring(1)
$manifest = [IO.File]::ReadAllText('Cargo.toml')
$manifestPattern = '(?m)^(version = ")[^"\r\n]+(")(\r?)$'
$manifestRegex = [regex]::new($manifestPattern)
if ($manifestRegex.Matches($manifest).Count -ne 1) { throw 'Expected exactly one package version in Cargo.toml.' }
$manifest = $manifestRegex.Replace($manifest, ('${1}' + $version + '${2}${3}'), 1)
[IO.File]::WriteAllText('Cargo.toml', $manifest, [Text.UTF8Encoding]::new($false))
$lock = [IO.File]::ReadAllText('Cargo.lock')
$lockPattern = '(?m)(^name = "rustovan"\r?\nversion = ")[^"\r\n]+(")(\r?)$'
$lockRegex = [regex]::new($lockPattern)
if ($lockRegex.Matches($lock).Count -ne 1) { throw 'Expected exactly one rustovan package entry in Cargo.lock.' }
$lock = $lockRegex.Replace($lock, ('${1}' + $version + '${2}${3}'), 1)
[IO.File]::WriteAllText('Cargo.lock', $lock, [Text.UTF8Encoding]::new($false))
- name: Set Cargo package version from release tag (Unix)
if: runner.os != 'Windows'
shell: bash
env:
TAG_NAME: ${{ inputs.tag_name }}
run: |
version="${TAG_NAME#v}"
python3 - "$version" <<'PY'
import re
import sys
version = sys.argv[1]
def update(path, pattern):
with open(path, encoding="utf-8", newline="") as source:
text = source.read()
updated, count = re.subn(
pattern,
lambda match: match.group(1) + version + match.group(2) + match.group(3),
text,
count=1,
)
if count != 1:
raise SystemExit(f"Expected one version field to update in {path}; found {count}")
with open(path, "w", encoding="utf-8", newline="") as destination:
destination.write(updated)
update("Cargo.toml", r'(?m)^(version = ")[^"\r\n]+(")(\r?)$')
update("Cargo.lock", r'(?m)(^name = "rustovan"\r?\nversion = ")[^"\r\n]+(")(\r?)$')
PY
- name: Install stable Rust and target
run: rustup toolchain install stable --profile minimal --target "${{ matrix.target }}"
- name: Install Linux TLS build dependencies
if: matrix.platform == 'linux'
run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev
- name: Install ARMv7 Linux cross compiler
if: matrix.target == 'armv7-unknown-linux-gnueabihf'
run: |
sudo apt-get update
sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
echo "CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc" >> "$GITHUB_ENV"
echo "CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc" >> "$GITHUB_ENV"
echo "AR_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-ar" >> "$GITHUB_ENV"
- name: Install RISC-V Linux cross compiler
if: matrix.target == 'riscv64gc-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-riscv64-linux-gnu g++-riscv64-linux-gnu libc6-dev-riscv64-cross
echo "CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc" >> "$GITHUB_ENV"
echo "CC_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-gcc" >> "$GITHUB_ENV"
echo "AR_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-ar" >> "$GITHUB_ENV"
- name: Install x86_64 musl linker
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> "$GITHUB_ENV"
echo "CC_x86_64_unknown_linux_musl=musl-gcc" >> "$GITHUB_ENV"
echo "AR_x86_64_unknown_linux_musl=ar" >> "$GITHUB_ENV"
- name: Install ARM64 musl linker
if: matrix.target == 'aarch64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> "$GITHUB_ENV"
echo "CC_aarch64_unknown_linux_musl=musl-gcc" >> "$GITHUB_ENV"
echo "AR_aarch64_unknown_linux_musl=ar" >> "$GITHUB_ENV"
- name: Install macOS TLS build dependencies
if: matrix.platform == 'macos'
run: brew install openssl@3 pkg-config
- name: Configure macOS OpenSSL
if: matrix.platform == 'macos'
run: |
echo "OPENSSL_DIR=$(brew --prefix openssl@3)" >> "$GITHUB_ENV"
echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> "$GITHUB_ENV"
- name: Install Android NDK
if: matrix.platform == 'android'
run: |
set -euo pipefail
sdkmanager="${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager"
test -x "$sdkmanager"
"$sdkmanager" --install "ndk;27.2.12479018"
ndk_root="${ANDROID_HOME}/ndk/27.2.12479018"
test -d "$ndk_root"
toolchain="$ndk_root/toolchains/llvm/prebuilt/linux-x86_64/bin"
echo "ANDROID_NDK_ROOT=$ndk_root" >> "$GITHUB_ENV"
echo "ANDROID_NDK_HOME=$ndk_root" >> "$GITHUB_ENV"
# renameat2 is available from Android API 30. Link against that API
# so the Android binary does not fail to link against the API 24 sysroot.
echo "CC_aarch64_linux_android=$toolchain/aarch64-linux-android30-clang" >> "$GITHUB_ENV"
echo "AR_aarch64_linux_android=$toolchain/llvm-ar" >> "$GITHUB_ENV"
echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$toolchain/aarch64-linux-android30-clang" >> "$GITHUB_ENV"
echo "$toolchain" >> "$GITHUB_PATH"
- name: Build Android ARM64 release with default backend features
if: matrix.platform == 'android'
run: cargo +stable build --release --locked --target "${{ matrix.target }}" --features android-cross
- name: Build Linux cross-target release with vendored OpenSSL
if: matrix.cross_openssl == true
run: cargo +stable build --release --locked --target "${{ matrix.target }}" --features cross-openssl
- name: Build release binary
if: matrix.platform != 'android' && matrix.cross_openssl != true
run: cargo +stable build --release --locked --target "${{ matrix.target }}"
- name: Package Windows binary
if: matrix.platform == 'windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Force dist | Out-Null
Copy-Item "target/${{ matrix.target }}/release/rustovan.exe" "dist/rustovan-${{ matrix.asset_id }}.exe"
- name: Package Unix binary
if: matrix.platform != 'windows'
run: |
set -euo pipefail
mkdir -p dist
cp "target/${{ matrix.target }}/release/rustovan" dist/rustovan
chmod 755 dist/rustovan
tar -C dist -czf "dist/rustovan-${{ matrix.asset_id }}.tar.gz" rustovan
rm dist/rustovan
- name: Upload packaged binary
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: release-${{ matrix.asset_id }}
path: dist/*
if-no-files-found: error
compression-level: 0
publish:
name: Publish GitHub release
if: ${{ inputs.publish_release }}
needs: [validate, build]
runs-on: ubuntu-latest
environment:
name: release-signing
permissions:
contents: write
steps:
- name: Check out release commit
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Download all platform packages
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: release-*
path: dist
merge-multiple: true
- name: Package Windows release binary
shell: bash
run: |
python3 - <<'PY'
from pathlib import Path
from zipfile import ZIP_DEFLATED, ZipFile
binaries = sorted(Path("dist").glob("rustovan-windows-*.exe"))
if not binaries:
raise SystemExit("No Windows build executables were downloaded")
for binary in binaries:
asset_id = binary.stem.removeprefix("rustovan-")
archive = Path("dist") / f"rustovan-{asset_id}.zip"
with ZipFile(archive, "w", compression=ZIP_DEFLATED) as package:
package.write(binary, arcname="rustovan.exe")
binary.unlink()
PY
- name: Generate checksums
run: cd dist && sha256sum * > SHA256SUMS.txt
- name: Sign checksum manifest with OpenPGP
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_FINGERPRINT: ${{ vars.GPG_FINGERPRINT }}
run: |
set -euo pipefail
if [[ -z "${GPG_PRIVATE_KEY}" || -z "${GPG_PASSPHRASE}" || -z "${GPG_FINGERPRINT}" ]]; then
echo "The release-signing environment must define GPG_PRIVATE_KEY, GPG_PASSPHRASE, and GPG_FINGERPRINT." >&2
exit 1
fi
fingerprint="$(printf '%s' "${GPG_FINGERPRINT}" | tr -d '[:space:]' | tr '[:lower:]' '[:upper:]')"
if [[ ! "${fingerprint}" =~ ^([A-F0-9]{40}|[A-F0-9]{64})$ ]]; then
echo "GPG_FINGERPRINT must be a full 40- or 64-character hexadecimal fingerprint." >&2
exit 1
fi
umask 077
export GNUPGHOME="$(mktemp -d)"
status_file="$(mktemp)"
cleanup() {
gpgconf --homedir "${GNUPGHOME}" --kill all >/dev/null 2>&1 || true
rm -f -- "${status_file}"
rm -rf -- "${GNUPGHOME}"
}
trap cleanup EXIT
printf '%s' "${GPG_PRIVATE_KEY}" | gpg --batch --import
imported_fingerprint="$(gpg --batch --with-colons --list-secret-keys "${fingerprint}" | awk -F: '$1 == "fpr" { print toupper($10); exit }')"
if [[ "${imported_fingerprint}" != "${fingerprint}" ]]; then
echo "The imported secret key does not match GPG_FINGERPRINT." >&2
exit 1
fi
printf '%s\n' "${GPG_PASSPHRASE}" | gpg --batch --yes --pinentry-mode loopback --passphrase-fd 0 --local-user "${fingerprint}" --armor --detach-sign --output dist/SHA256SUMS.txt.asc dist/SHA256SUMS.txt
gpg --batch --status-fd 3 --verify dist/SHA256SUMS.txt.asc dist/SHA256SUMS.txt 3>"${status_file}"
if ! awk -v expected="${fingerprint}" '$2 == "VALIDSIG" && (toupper($3) == expected || (NF >= 12 && toupper($12) == expected)) { valid = 1 } END { exit !valid }' "${status_file}"; then
echo "The generated signature did not verify against GPG_FINGERPRINT." >&2
exit 1
fi
- name: Create release and upload assets
env:
GH_TOKEN: ${{ github.token }}
TAG_NAME: ${{ inputs.tag_name }}
run: gh release create "$TAG_NAME" dist/* --target "$GITHUB_SHA" --title "$TAG_NAME" --generate-notes