-
Notifications
You must be signed in to change notification settings - Fork 0
348 lines (291 loc) · 12.3 KB
/
release.yml
File metadata and controls
348 lines (291 loc) · 12.3 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Existing git tag to release (e.g. v0.5.0)"
required: true
type: string
permissions:
contents: write
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- platform: windows-latest
args: "--bundles nsis,msi"
- platform: macos-latest
args: "--target universal-apple-darwin --bundles app,dmg,updater"
- platform: ubuntu-latest
args: "--bundles appimage,deb,rpm"
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve release tag
id: release_tag
shell: bash
run: |
if [ "${{ github.event_name }}" = "push" ]; then
TAG="${GITHUB_REF_NAME}"
else
TAG="${{ inputs.tag }}"
fi
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.]+)?$ ]]; then
echo "Invalid tag format: $TAG"
echo "Expected format like v0.5.0"
exit 1
fi
git fetch --tags --force
if ! git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
echo "Tag not found: $TAG"
echo "Create/push the tag first, then re-run release."
exit 1
fi
echo "version=$TAG" >> "$GITHUB_OUTPUT"
# ── macOS: universal binary needs both targets ──────────────────────────
- name: Add macOS targets
if: matrix.platform == 'macos-latest'
run: |
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
# ── Node.js ─────────────────────────────────────────────────────────────
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install frontend dependencies
run: npm ci
- name: Validate version consistency
shell: bash
run: |
TAG_VERSION="${{ steps.release_tag.outputs.version }}"
TAG_VERSION="${TAG_VERSION#v}"
PKG_VERSION=$(node -p "require('./package.json').version")
TAURI_VERSION=$(node -p "require('./src-tauri/tauri.conf.json').version")
echo "Release tag version: $TAG_VERSION"
echo "package.json version: $PKG_VERSION"
echo "tauri.conf.json version: $TAURI_VERSION"
if [ "$TAG_VERSION" != "$PKG_VERSION" ] || [ "$TAG_VERSION" != "$TAURI_VERSION" ]; then
echo "Version mismatch detected."
echo "Tag version must match package.json and src-tauri/tauri.conf.json."
exit 1
fi
- name: Extract release notes from CHANGELOG.md
id: changelog
shell: bash
run: |
VERSION_NO_V="${{ steps.release_tag.outputs.version }}"
VERSION_NO_V="${VERSION_NO_V#v}"
SECTION=$(awk -v version="$VERSION_NO_V" '
$0 ~ "^## \\[" version "\\]" { in_section=1; next }
in_section && $0 ~ /^## \[/ { exit }
in_section { print }
' CHANGELOG.md)
MACOS_NOTE="\n\n---\n\n### 🚩 macOS 无签名运行说明\n\n**首次打开如遇“无法验证开发者”或“已损坏”提示,请右键 App → 打开,或在终端执行:**\n\n\n xattr -dr com.apple.quarantine /Applications/TimeLens.app\n\n**如仍无法运行,请在“系统设置 → 隐私与安全性”中允许此 App。**\n"
if [ -z "$SECTION" ]; then
echo "notes=No changelog entry found for version ${VERSION_NO_V}.${MACOS_NOTE}" >> "$GITHUB_OUTPUT"
else
{
echo "notes<<EOF"
printf '%s\n' "$SECTION"
printf '%b' "$MACOS_NOTE"
echo "EOF"
} >> "$GITHUB_OUTPUT"
fi
# ── Rust ────────────────────────────────────────────────────────────────
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
# ── Linux system libs (required by glib-sys, gtk, webkit2gtk) ─────────────
- name: Install Linux dependencies
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y \
libwebkit2gtk-4.1-dev \
libgtk-3-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
libglib2.0-dev \
pkg-config
# ── Build & publish ──────────────────────────────────────────────────────
- name: Build and release
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
with:
tagName: ${{ steps.release_tag.outputs.version }}
releaseName: "TimeLens ${{ steps.release_tag.outputs.version }}"
releaseBody: ${{ steps.changelog.outputs.notes }}
releaseDraft: false
prerelease: false
args: ${{ matrix.args }}
build-msix:
name: Build and upload MSIX
runs-on: windows-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve release tag
id: release_tag
shell: pwsh
run: |
if ("${{ github.event_name }}" -eq "push") {
$tag = "${{ github.ref_name }}"
} else {
$tag = "${{ inputs.tag }}"
}
if ($tag -notmatch '^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.]+)?$') {
Write-Error "Invalid tag format: $tag"
}
git fetch --tags --force
git rev-parse -q --verify "refs/tags/$tag" | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Error "Tag not found: $tag"
}
$versionNoV = $tag.TrimStart('v')
$msixVersion = "$versionNoV.0"
"tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"version=$versionNoV" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"msix_version=$msixVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install frontend dependencies
run: npm ci
- name: Validate version consistency
shell: pwsh
run: |
$tagVersion = "${{ steps.release_tag.outputs.version }}"
$pkgVersion = (node -p "require('./package.json').version").Trim()
$tauriVersion = (node -p "require('./src-tauri/tauri.conf.json').version").Trim()
Write-Host "Release tag version: $tagVersion"
Write-Host "package.json version: $pkgVersion"
Write-Host "tauri.conf.json version: $tauriVersion"
if ($tagVersion -ne $pkgVersion -or $tagVersion -ne $tauriVersion) {
Write-Error "Version mismatch detected. Tag version must match package.json and src-tauri/tauri.conf.json."
}
- name: Build MSIX package
shell: pwsh
run: |
./scripts/build-msix.ps1 -Version "${{ steps.release_tag.outputs.msix_version }}"
- name: Upload MSIX to release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release_tag.outputs.tag }}
files: src-tauri/windows/out/TimeLens-${{ steps.release_tag.outputs.msix_version }}.msix
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-windows-with-webview2:
name: Build and upload Windows installers (WithWebView2)
runs-on: windows-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve release tag
id: release_tag
shell: pwsh
run: |
if ("${{ github.event_name }}" -eq "push") {
$tag = "${{ github.ref_name }}"
} else {
$tag = "${{ inputs.tag }}"
}
if ($tag -notmatch '^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.]+)?$') {
Write-Error "Invalid tag format: $tag"
}
git fetch --tags --force
git rev-parse -q --verify "refs/tags/$tag" | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Error "Tag not found: $tag"
}
$versionNoV = $tag.TrimStart('v')
"tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"version=$versionNoV" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install frontend dependencies
run: npm ci
- name: Validate version consistency
shell: pwsh
run: |
$tagVersion = "${{ steps.release_tag.outputs.version }}"
$pkgVersion = (node -p "require('./package.json').version").Trim()
$tauriVersion = (node -p "require('./src-tauri/tauri.conf.json').version").Trim()
Write-Host "Release tag version: $tagVersion"
Write-Host "package.json version: $pkgVersion"
Write-Host "tauri.conf.json version: $tauriVersion"
if ($tagVersion -ne $pkgVersion -or $tagVersion -ne $tauriVersion) {
Write-Error "Version mismatch detected. Tag version must match package.json and src-tauri/tauri.conf.json."
}
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
- name: Build NSIS/MSI with bundled WebView2 runtime
shell: pwsh
run: |
$overridePath = "src-tauri/tauri.webview2.override.json"
$override = @{
bundle = @{
windows = @{
webviewInstallMode = @{
type = "offlineInstaller"
silent = $true
}
}
}
}
$override | ConvertTo-Json -Depth 16 | Set-Content -Path $overridePath -Encoding UTF8
npx tauri build --bundles nsis,msi --config $overridePath
- name: Prepare renamed WithWebView2 artifacts
id: artifacts
shell: pwsh
run: |
$bundleRoot = "src-tauri/target/release/bundle"
$nsis = Get-ChildItem -Path (Join-Path $bundleRoot "nsis") -Filter "*.exe" -File | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$msi = Get-ChildItem -Path (Join-Path $bundleRoot "msi") -Filter "*.msi" -File | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if (-not $nsis) { throw "NSIS installer not found." }
if (-not $msi) { throw "MSI installer not found." }
$version = "${{ steps.release_tag.outputs.version }}"
$outDir = Join-Path $bundleRoot "with-webview2"
New-Item -ItemType Directory -Path $outDir -Force | Out-Null
$nsisOut = Join-Path $outDir "TimeLens-$version-WithWebView2-Setup.exe"
$msiOut = Join-Path $outDir "TimeLens-$version-WithWebView2.msi"
Copy-Item -Path $nsis.FullName -Destination $nsisOut -Force
Copy-Item -Path $msi.FullName -Destination $msiOut -Force
"nsis_file=$nsisOut" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"msi_file=$msiOut" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Upload WithWebView2 installers to release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release_tag.outputs.tag }}
files: |
${{ steps.artifacts.outputs.nsis_file }}
${{ steps.artifacts.outputs.msi_file }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}