-
Notifications
You must be signed in to change notification settings - Fork 0
274 lines (254 loc) · 10.4 KB
/
Copy pathrelease.yml
File metadata and controls
274 lines (254 loc) · 10.4 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
create_release:
description: "Create a draft GitHub Release from build artifacts"
type: boolean
default: false
macos_signing_required:
description: "Fail the macOS job when no signing certificate is available (default: true)"
type: boolean
default: true
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: "0"
RUST_BACKTRACE: "1"
# macOS artifacts must be signed by default; workflow_dispatch can opt out
# (e.g. for throwaway ad-hoc builds) by passing macos_signing_required=false.
REQUIRE_SIGNING: ${{ github.event_name == 'push' || inputs.macos_signing_required }}
jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
timeout-minutes: 180
strategy:
fail-fast: false
matrix:
include:
- name: macOS aarch64
os: macos-14
target: aarch64-apple-darwin
artifact: terry-macos-aarch64
package: macos
# Built on an Apple Silicon runner and cross-compiled to x86_64 with
# the Xcode SDK (no Intel runner needed).
- name: macOS x86_64
os: macos-14
target: x86_64-apple-darwin
artifact: terry-macos-x86_64
package: macos
cross: true
- name: Linux x86_64
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
artifact: terry-linux-x86_64
package: linux
- name: Windows x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
artifact: terry-windows-x86_64
package: windows
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Prepare Windows build environment
if: matrix.package == 'windows'
shell: pwsh
run: |
# Required for pet/python-environment-tools git checkouts (MAX_PATH).
git config --system core.longpaths true
git config --global core.longpaths true
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force | Out-Null
# wasmtime / native deps expect cmake on PATH.
if (-not (Get-Command cmake -ErrorAction SilentlyContinue)) {
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" +
[System.Environment]::GetEnvironmentVariable("Path","User")
}
cmake --version
- name: Install Linux dependencies
if: matrix.package == 'linux'
run: |
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \
build-essential \
clang \
cmake \
curl \
git \
jq \
libasound2-dev \
libfontconfig-dev \
libsqlite3-dev \
libssl-dev \
libwayland-dev \
libx11-dev \
libxcb-xfixes0-dev \
libxkbcommon-dev \
libxkbcommon-x11-dev \
libzstd-dev \
libvulkan-dev \
pkg-config
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.95.0"
targets: ${{ matrix.target }}
- name: Prepare macOS x86_64 cross-compilation
if: matrix.cross
shell: bash
run: |
set -euo pipefail
HOST="$(rustc -vV | sed -n 's/^host: //p')"
echo "Cross-compiling ${{ matrix.target }} from ${HOST}"
# Xcode's clang ships a universal SDK, so it can target x86_64 from an
# arm64 runner. Route `cc`-based build scripts and cmake (aws-lc-sys)
# at it; rustc links with the default `cc` since the objects are already
# x86_64.
echo "CC_x86_64_apple_darwin=clang -arch x86_64" >> "$GITHUB_ENV"
echo "CXX_x86_64_apple_darwin=clang++ -arch x86_64" >> "$GITHUB_ENV"
echo "CMAKE_OSX_ARCHITECTURES=x86_64" >> "$GITHUB_ENV"
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
shared-key: release-${{ matrix.target }}
cache-targets: true
- name: Resolve version
id: version
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
VERSION="${GITHUB_REF_NAME#v}"
else
VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
VERSION="${VERSION:-0.0.0}+${GITHUB_SHA::7}"
fi
# Zip/path-safe form (avoid '+' in Windows filenames).
VERSION_SAFE="${VERSION//+/-}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "version_safe=$VERSION_SAFE" >> "$GITHUB_OUTPUT"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "VERSION_SAFE=$VERSION_SAFE" >> "$GITHUB_ENV"
- name: Import macOS signing certificate
if: matrix.package == 'macos'
env:
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
REQUIRE_SIGNING: ${{ env.REQUIRE_SIGNING }}
shell: bash
run: |
set -euo pipefail
if [[ -z "${MACOS_CERTIFICATE}" ]]; then
if [[ "${REQUIRE_SIGNING}" == "true" ]]; then
echo "::error::MACOS_CERTIFICATE secret is not set, but macOS signing is required. " \
"Configure the secret (base64-encoded Developer ID Application .p12) or run " \
"with macos_signing_required=false for an ad-hoc build." >&2
exit 1
fi
echo "::warning::MACOS_CERTIFICATE secret not set; the macOS package will be ad-hoc signed (not a distribution signature)"
exit 0
fi
KEYCHAIN_PATH="$RUNNER_TEMP/terry-signing.keychain-db"
KEYCHAIN_PASSWORD="$(openssl rand -base64 32)"
CERTIFICATE_PATH="$RUNNER_TEMP/certificate.p12"
echo "$MACOS_CERTIFICATE" | base64 --decode > "$CERTIFICATE_PATH"
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
# Import the whole identity (certificate + private key) from the p12.
# `-t cert` would import only the certificate, leaving codesign without
# the private key it needs to produce a signature.
security import "$CERTIFICATE_PATH" -P "$MACOS_CERTIFICATE_PASSWORD" \
-A -f pkcs12 -k "$KEYCHAIN_PATH"
security set-key-partition-list -S apple-tool:,apple:,codesign: -s \
-k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security list-keychain -d user -s "$KEYCHAIN_PATH"
IDENTITY="$(
security find-identity -v -p codesigning "$KEYCHAIN_PATH" \
| sed -n 's/.*"\(Developer ID Application: .*\)"/\1/p' \
| head -1
)"
if [[ -z "$IDENTITY" ]]; then
echo "error: no Developer ID Application identity found in imported certificate" >&2
security find-identity -v -p codesigning "$KEYCHAIN_PATH" >&2 || true
exit 1
fi
echo "MACOS_SIGNING_IDENTITY=$IDENTITY" >> "$GITHUB_ENV"
echo "Imported signing identity: $IDENTITY"
- name: Package macOS
if: matrix.package == 'macos'
shell: bash
env:
REQUIRE_SIGNING: ${{ env.REQUIRE_SIGNING }}
APPLE_NOTARIZATION_KEY: ${{ secrets.APPLE_NOTARIZATION_KEY }}
APPLE_NOTARIZATION_KEY_ID: ${{ secrets.APPLE_NOTARIZATION_KEY_ID }}
APPLE_NOTARIZATION_ISSUER_ID: ${{ secrets.APPLE_NOTARIZATION_ISSUER_ID }}
run: |
chmod +x script/package-macos.sh
ZIP="$(script/package-macos.sh "${{ matrix.target }}" | tee /dev/stderr | tail -n 1)"
mkdir -p dist
cp -f "$ZIP" dist/
- name: Package Linux
if: matrix.package == 'linux'
shell: bash
run: |
chmod +x script/package-linux.sh
ARCHIVE="$(script/package-linux.sh "${{ matrix.target }}" | tee /dev/stderr | tail -n 1)"
mkdir -p dist
cp -f "$ARCHIVE" dist/
- name: Package Windows
if: matrix.package == 'windows'
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$version = if ($env:VERSION_SAFE) { $env:VERSION_SAFE } else { $env:VERSION }
$zip = & ".\script\package-windows.ps1" -Target "${{ matrix.target }}" -Version $version
if (-not $zip) { throw "package-windows.ps1 produced no zip path" }
if ($zip -is [array]) { $zip = ($zip | Where-Object { $_ })[-1] }
Write-Host "Artifact: $zip"
if (-not (Test-Path $zip)) { throw "Zip not found: $zip" }
New-Item -ItemType Directory -Force -Path dist | Out-Null
Copy-Item -Force $zip dist/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: dist/*
if-no-files-found: error
retention-days: 14
release:
name: Publish GitHub Release
needs: build
runs-on: ubuntu-latest
if: |
always() &&
needs.build.result == 'success' &&
(
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
(github.event_name == 'workflow_dispatch' && inputs.create_release == true)
)
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: List artifacts
run: find artifacts -type f | sort
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || format('build-{0}', github.run_id) }}
name: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || format('Terry build {0}', github.run_id) }}
draft: ${{ !startsWith(github.ref, 'refs/tags/v') }}
generate_release_notes: ${{ startsWith(github.ref, 'refs/tags/v') }}
files: artifacts/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}