-
Notifications
You must be signed in to change notification settings - Fork 2
324 lines (284 loc) · 12.7 KB
/
Copy pathrelease.yml
File metadata and controls
324 lines (284 loc) · 12.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
317
318
319
320
321
322
323
324
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
env:
TAURI_CLI_VERSION: 2.11.2
jobs:
build-and-release-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Restore Rust cache
uses: Swatinem/rust-cache@v2
with:
workspaces: |
src-tauri -> target
shared-key: windows-rust-v1
- name: Restore Tauri CLI cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/cargo-tauri.exe
~/.cargo/.crates.toml
~/.cargo/.crates2.json
key: ${{ runner.os }}-tauri-cli-${{ env.TAURI_CLI_VERSION }}-v1
- name: Validate tag matches app version
shell: pwsh
run: |
$tag = "${env:GITHUB_REF_NAME}"
if (-not $tag.StartsWith("v")) { throw "Expected tag to start with 'v' (got '$tag')" }
$expected = $tag.Substring(1)
$cargoToml = Get-Content -Raw "src-tauri/Cargo.toml"
$match = [regex]::Match($cargoToml, '(?m)^\s*version\s*=\s*"([^"]+)"\s*$')
if (-not $match.Success) {
throw "Could not parse package version from src-tauri/Cargo.toml."
}
$actual = $match.Groups[1].Value
if ($actual -ne $expected) {
throw "Tag version ($expected) does not match src-tauri/Cargo.toml version ($actual)."
}
- name: Install Tauri CLI
shell: pwsh
run: |
$timer = Measure-Command {
$expectedVersion = [regex]::Escape($env:TAURI_CLI_VERSION)
$versionOutput = (& cargo tauri --version 2>$null)
$hasExpectedVersion = $LASTEXITCODE -eq 0 -and $versionOutput -match "tauri-cli\s+$expectedVersion\b"
if ($hasExpectedVersion) {
Write-Host "Tauri CLI $env:TAURI_CLI_VERSION already available from cache."
}
else {
cargo install tauri-cli --version $env:TAURI_CLI_VERSION --locked --force
if ($LASTEXITCODE -ne 0) { throw "Failed to install Tauri CLI $env:TAURI_CLI_VERSION." }
$versionOutput = (& cargo tauri --version).Trim()
if ($versionOutput -notmatch "tauri-cli\s+$expectedVersion\b") {
throw "Expected Tauri CLI $env:TAURI_CLI_VERSION, got '$versionOutput'."
}
}
}
Write-Host ("Tauri CLI setup completed in {0:N1}s" -f $timer.TotalSeconds)
- name: Install Windows bundler tools
shell: pwsh
run: |
$timer = Measure-Command {
$makensis = Get-Command makensis -ErrorAction SilentlyContinue
if ($makensis) {
Write-Host "NSIS already available at $($makensis.Source)."
}
else {
choco install nsis --no-progress -y
}
}
Write-Host ("NSIS setup completed in {0:N1}s" -f $timer.TotalSeconds)
- name: Validate updater signing secrets
shell: pwsh
env:
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
run: |
if ([string]::IsNullOrWhiteSpace("${env:TAURI_SIGNING_PRIVATE_KEY}")) {
throw "Missing TAURI_SIGNING_PRIVATE_KEY secret. Configure updater signing secrets before releasing."
}
- name: Validate Cloudflare Pages publish secrets
shell: pwsh
env:
WEBSITE_REPO_TOKEN: ${{ secrets.WEBSITE_REPO_TOKEN }}
run: |
if ([string]::IsNullOrWhiteSpace("${env:WEBSITE_REPO_TOKEN}")) {
throw "Missing WEBSITE_REPO_TOKEN secret. This token must be able to push to prgmitchell/MIDIMasterWebsite."
}
- name: Validate Netlify bridge publish secrets
shell: pwsh
env:
NETLIFY_BRIDGE_PUBLISH: ${{ vars.NETLIFY_BRIDGE_PUBLISH }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: |
$bridgeRaw = "${env:NETLIFY_BRIDGE_PUBLISH}"
if ([string]::IsNullOrWhiteSpace($bridgeRaw)) { $bridgeRaw = "true" }
$bridgeEnabled = @("1", "true", "yes", "on") -contains $bridgeRaw.Trim().ToLowerInvariant()
if (-not $bridgeEnabled) {
Write-Host "Netlify bridge publishing is disabled."
exit 0
}
if ([string]::IsNullOrWhiteSpace("${env:NETLIFY_AUTH_TOKEN}")) {
throw "Missing NETLIFY_AUTH_TOKEN secret. It is required while NETLIFY_BRIDGE_PUBLISH is enabled."
}
if ([string]::IsNullOrWhiteSpace("${env:NETLIFY_SITE_ID}")) {
throw "Missing NETLIFY_SITE_ID secret. It is required while NETLIFY_BRIDGE_PUBLISH is enabled."
}
- name: Build (Tauri)
shell: pwsh
env:
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
run: |
Push-Location "src-tauri"
try {
$timer = Measure-Command {
cargo tauri build --bundles nsis
}
Write-Host ("Tauri bundle build completed in {0:N1}s" -f $timer.TotalSeconds)
} finally {
Pop-Location
}
- name: Generate updater metadata (latest.json)
shell: pwsh
run: |
$tag = "${env:GITHUB_REF_NAME}"
$repo = "${env:GITHUB_REPOSITORY}"
$nsisDir = "src-tauri/target/release/bundle/nsis"
$setupExe = Get-ChildItem -Path $nsisDir -Filter *.exe |
Where-Object { $_.Name -like "*setup*.exe" } |
Select-Object -First 1
if (-not $setupExe) {
throw "Could not find NSIS setup executable in $nsisDir"
}
$sigPath = "$($setupExe.FullName).sig"
if (-not (Test-Path $sigPath)) {
throw "Missing signature file for updater artifact: $sigPath"
}
$signature = (Get-Content -Raw $sigPath).Trim()
$downloadUrl = "https://github.com/$repo/releases/download/$tag/$($setupExe.Name)"
$latest = @{
version = $tag
notes = "See release notes on GitHub."
pub_date = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
platforms = @{
"windows-x86_64" = @{
signature = $signature
url = $downloadUrl
}
}
}
$latestJsonPath = "src-tauri/target/release/bundle/latest.json"
$latest | ConvertTo-Json -Depth 8 | Out-File -FilePath $latestJsonPath -Encoding utf8
- name: Checkout Cloudflare Pages source
uses: actions/checkout@v4
with:
repository: prgmitchell/MIDIMasterWebsite
token: ${{ secrets.WEBSITE_REPO_TOKEN }}
path: midimaster-website
- name: Publish updater metadata to Cloudflare Pages source
shell: pwsh
run: |
$timer = Measure-Command {
$tag = "${env:GITHUB_REF_NAME}"
$latestJsonPath = "src-tauri/target/release/bundle/latest.json"
if (-not (Test-Path -LiteralPath $latestJsonPath)) {
throw "Updater metadata file not found: $latestJsonPath"
}
$websiteRoot = "midimaster-website"
$targetPath = Join-Path $websiteRoot "public/latest.json"
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $targetPath) | Out-Null
Copy-Item -LiteralPath $latestJsonPath -Destination $targetPath -Force
Push-Location $websiteRoot
try {
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add public/latest.json
git diff --cached --quiet
if ($LASTEXITCODE -eq 0) {
Write-Host "Cloudflare Pages updater metadata is already current."
}
elseif ($LASTEXITCODE -eq 1) {
git commit -m "Update MIDIMaster updater metadata for $tag"
if ($LASTEXITCODE -ne 0) { throw "Failed to commit website updater metadata." }
git push
if ($LASTEXITCODE -ne 0) { throw "Failed to push website updater metadata." }
}
else {
throw "Failed to compare staged website updater metadata."
}
}
finally {
Pop-Location
}
}
Write-Host ("Cloudflare Pages updater metadata publish completed in {0:N1}s" -f $timer.TotalSeconds)
- name: Publish updater metadata to Netlify bridge
shell: pwsh
env:
NETLIFY_BRIDGE_PUBLISH: ${{ vars.NETLIFY_BRIDGE_PUBLISH }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: |
$bridgeRaw = "${env:NETLIFY_BRIDGE_PUBLISH}"
if ([string]::IsNullOrWhiteSpace($bridgeRaw)) { $bridgeRaw = "true" }
$bridgeEnabled = @("1", "true", "yes", "on") -contains $bridgeRaw.Trim().ToLowerInvariant()
if (-not $bridgeEnabled) {
Write-Host "Netlify bridge publishing is disabled."
exit 0
}
$timer = Measure-Command {
$latestJsonPath = "src-tauri/target/release/bundle/latest.json"
if (-not (Test-Path -LiteralPath $latestJsonPath)) {
throw "Updater metadata file not found: $latestJsonPath"
}
$websiteCatalogPath = "midimaster-website/public/catalog.json"
if (-not (Test-Path -LiteralPath $websiteCatalogPath)) {
throw "Website store catalog not found: $websiteCatalogPath"
}
$publishDir = Join-Path $env:RUNNER_TEMP "netlify-bridge"
if (Test-Path -LiteralPath $publishDir) {
Remove-Item -LiteralPath $publishDir -Recurse -Force
}
New-Item -ItemType Directory -Force -Path (Join-Path $publishDir "updates") | Out-Null
Copy-Item -LiteralPath $latestJsonPath -Destination (Join-Path $publishDir "updates/latest.json") -Force
Copy-Item -LiteralPath $websiteCatalogPath -Destination (Join-Path $publishDir "catalog.json") -Force
$redirects = @(
"/latest.json /updates/latest.json 301"
"/packages/* https://store.midimaster.app/packages/:splat 301"
"/icons/* https://store.midimaster.app/icons/:splat 301"
"/* https://midimaster.app/:splat 301"
) -join "`n"
$redirects += "`n"
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText((Join-Path $publishDir "_redirects"), $redirects, $utf8NoBom)
& "scripts/netlify/Invoke-NetlifyMergeDeploy.ps1" `
-SourceDir $publishDir `
-SiteId "${env:NETLIFY_SITE_ID}"
}
Write-Host ("Netlify bridge redirect publish completed in {0:N1}s" -f $timer.TotalSeconds)
- name: Prepare GitHub release asset list
id: release_assets
shell: pwsh
env:
UPDATER_BRIDGE_RELEASE: ${{ vars.UPDATER_BRIDGE_RELEASE }}
UPDATER_BRIDGE_INCLUDE_SIG: ${{ vars.UPDATER_BRIDGE_INCLUDE_SIG }}
run: |
$bridgeRaw = "${env:UPDATER_BRIDGE_RELEASE}"
if ([string]::IsNullOrWhiteSpace($bridgeRaw)) { $bridgeRaw = "true" }
$bridgeEnabled = @("1", "true", "yes", "on") -contains $bridgeRaw.Trim().ToLowerInvariant()
$includeSigRaw = "${env:UPDATER_BRIDGE_INCLUDE_SIG}"
$includeSig = @("1", "true", "yes", "on") -contains $includeSigRaw.Trim().ToLowerInvariant()
$files = @(
"src-tauri/target/release/bundle/nsis/*.exe"
)
if ($bridgeEnabled) {
$files += "src-tauri/target/release/bundle/latest.json"
if ($includeSig) {
$files += "src-tauri/target/release/bundle/nsis/*.exe.sig"
}
Write-Host "Bridge release mode is ON."
} else {
Write-Host "Bridge release mode is OFF."
}
"files<<EOF" >> $env:GITHUB_OUTPUT
$files -join "`n" >> $env:GITHUB_OUTPUT
"EOF" >> $env:GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: MIDIMaster ${{ github.ref_name }}
draft: false
prerelease: false
generate_release_notes: true
fail_on_unmatched_files: true
files: ${{ steps.release_assets.outputs.files }}