-
Notifications
You must be signed in to change notification settings - Fork 32
316 lines (281 loc) · 10.7 KB
/
release.yml
File metadata and controls
316 lines (281 loc) · 10.7 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
name: Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
tag:
description: 'Tag to build (e.g., v0.1.0)'
required: true
target:
description: 'Target to build'
required: false
default: all
type: choice
options:
- all
- x86_64-unknown-linux-gnu
- x86_64-apple-darwin
- aarch64-apple-darwin
- x86_64-pc-windows-msvc
env:
CARGO_INCREMENTAL: 0
jobs:
release:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
tag: ${{ steps.push-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- run: pnpm install
- name: Create Release Pull Request
id: changesets
uses: changesets/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push tag if version changed
id: push-tag
if: steps.changesets.outputs.hasChangesets == 'false'
shell: bash
run: |
VERSION=$(node -p "require('./package.json').version")
TAG="v$VERSION"
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
TAG_COMMIT=$(git rev-list -n 1 "$TAG")
HEAD_COMMIT=$(git rev-parse HEAD)
if [ "$TAG_COMMIT" = "$HEAD_COMMIT" ]; then
echo "Tag $TAG already points to this commit"
echo "tag=$TAG" >> $GITHUB_OUTPUT
else
echo "Tag $TAG already points to $TAG_COMMIT; current commit is $HEAD_COMMIT"
echo "Skipping release build for this push"
fi
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -f "$TAG"
if git push origin "$TAG"; then
echo "Pushed tag $TAG"
elif git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1; then
echo "Tag $TAG was created by another process"
else
exit 1
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
fi
prepare-build:
needs: [release]
if: always() && (needs.release.outputs.tag != '' || github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Select build matrix
id: matrix
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TARGET="${{ github.event.inputs.target }}"
else
TARGET="all"
fi
if [ -z "$TARGET" ]; then
TARGET="all"
fi
case "$TARGET" in
all)
MATRIX='{"include":[{"os":"ubuntu-24.04","target":"x86_64-unknown-linux-gnu"},{"os":"macos-15-intel","target":"x86_64-apple-darwin"},{"os":"macos-latest","target":"aarch64-apple-darwin"},{"os":"windows-latest","target":"x86_64-pc-windows-msvc"}]}'
;;
x86_64-unknown-linux-gnu)
MATRIX='{"include":[{"os":"ubuntu-24.04","target":"x86_64-unknown-linux-gnu"}]}'
;;
x86_64-apple-darwin)
MATRIX='{"include":[{"os":"macos-15-intel","target":"x86_64-apple-darwin"}]}'
;;
aarch64-apple-darwin)
MATRIX='{"include":[{"os":"macos-latest","target":"aarch64-apple-darwin"}]}'
;;
x86_64-pc-windows-msvc)
MATRIX='{"include":[{"os":"windows-latest","target":"x86_64-pc-windows-msvc"}]}'
;;
*)
echo "Unsupported target: $TARGET" >&2
exit 1
;;
esac
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
build:
needs: [release, prepare-build]
if: always() && needs.prepare-build.result == 'success'
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.prepare-build.outputs.matrix) }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
steps:
- name: Determine tag
id: get-tag
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
else
echo "tag=${{ needs.release.outputs.tag }}" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
with:
ref: ${{ steps.get-tag.outputs.tag }}
submodules: recursive
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
libwebkit2gtk-4.1-dev \
libappindicator3-dev \
librsvg2-dev \
patchelf \
libpipewire-0.3-dev \
libgbm-dev \
libxcb1-dev \
libegl-dev
- name: Import Apple certificate
if: runner.os == 'macOS'
env:
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
run: |
# Create temporary keychain
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
KEYCHAIN_PASSWORD=$(openssl rand -base64 32)
# Create keychain
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 certificate
echo "$APPLE_CERTIFICATE" | base64 --decode > $RUNNER_TEMP/certificate.p12
security import $RUNNER_TEMP/certificate.p12 \
-P "$APPLE_CERTIFICATE_PASSWORD" \
-A -t cert -f pkcs12 \
-k "$KEYCHAIN_PATH"
# Set keychain as default
security list-keychain -d user -s "$KEYCHAIN_PATH"
# Allow codesign to access keychain
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
# Verify certificate
security find-identity -v -p codesigning "$KEYCHAIN_PATH"
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
cache-bin: "false"
- run: pnpm install
- name: Extract changelog for current version
id: changelog
shell: bash
run: |
VERSION="${{ steps.get-tag.outputs.tag }}"
VERSION="${VERSION#v}" # Remove 'v' prefix
# Extract content between current version header and next version header
CHANGELOG=$(awk -v ver="$VERSION" '
/^## / {
if (found) exit
if ($2 == ver) { found=1; next }
}
found { print }
' CHANGELOG.md)
# Handle multi-line output
echo "content<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Build targeted macOS x64 bundle
if: github.event_name == 'workflow_dispatch' && matrix.target == 'x86_64-apple-darwin'
shell: bash
env:
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
run: pnpm tauri build --target ${{ matrix.target }} --verbose
- name: Upload targeted macOS x64 assets
if: github.event_name == 'workflow_dispatch' && matrix.target == 'x86_64-apple-darwin'
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ steps.get-tag.outputs.tag }}"
BUNDLE_DIR="src-tauri/target/${{ matrix.target }}/release/bundle"
MACOS_DIR="$BUNDLE_DIR/macos"
if [ -f "$MACOS_DIR/lovcode.app.tar.gz" ]; then
mv "$MACOS_DIR/lovcode.app.tar.gz" "$MACOS_DIR/lovcode_x64.app.tar.gz"
fi
if [ -f "$MACOS_DIR/lovcode.app.tar.gz.sig" ]; then
mv "$MACOS_DIR/lovcode.app.tar.gz.sig" "$MACOS_DIR/lovcode_x64.app.tar.gz.sig"
fi
assets=()
while IFS= read -r asset; do
assets+=("$asset")
done < <(
find "$BUNDLE_DIR" -type f \( \
-name '*.dmg' -o \
-name '*.app.tar.gz' -o \
-name '*.sig' \
\) -print
)
if [ "${#assets[@]}" -eq 0 ]; then
echo "No assets found in $BUNDLE_DIR" >&2
find "$BUNDLE_DIR" -type f -print >&2 || true
exit 1
fi
printf 'Uploading assets:\n'
printf ' %s\n' "${assets[@]}"
gh release upload "$TAG" "${assets[@]}" --clobber
- uses: tauri-apps/tauri-action@v0
if: github.event_name != 'workflow_dispatch' || matrix.target != 'x86_64-apple-darwin'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# macOS signing
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
# macOS notarization
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
# Tauri updater signing (empty password)
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
with:
tagName: ${{ steps.get-tag.outputs.tag }}
releaseName: ${{ steps.get-tag.outputs.tag }}
releaseBody: ${{ steps.changelog.outputs.content }}
releaseDraft: false
prerelease: false
includeUpdaterJson: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.target == 'all' }}
args: --target ${{ matrix.target }}
- name: Cleanup keychain
if: runner.os == 'macOS' && always()
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db || true