|
| 1 | +# BLXCode release: optional semver bump, signed tauri build, GitHub release upload. |
| 2 | +$ErrorActionPreference = "Stop" |
| 3 | + |
| 4 | +$script:RELEASE_EXIT_USER = 1 |
| 5 | +$script:RELEASE_EXIT_BUILD = 2 |
| 6 | + |
| 7 | +$script:RELEASE_DRY_RUN = 0 |
| 8 | +$script:RELEASE_REQUIRE_SIGNING = 0 |
| 9 | +$script:RELEASE_NO_CHANGELOG = 0 |
| 10 | +$script:RELEASE_CLOBBER = 0 |
| 11 | +$script:RELEASE_DO_BUILD = 0 |
| 12 | +$script:RELEASE_DO_UPLOAD = 0 |
| 13 | +$script:RELEASE_UPLOAD_ONLY = 0 |
| 14 | +$script:RELEASE_DO_TAG = 0 |
| 15 | +$script:RELEASE_DO_PUSH = 0 |
| 16 | +$script:RELEASE_DO_COMMIT = 0 |
| 17 | +$script:RELEASE_BUMP = "" |
| 18 | +$script:RELEASE_BUNDLES = "" |
| 19 | +$script:RELEASE_PLATFORM_OVERRIDE = "" |
| 20 | +$script:RELEASE_LINUX_ARCH = if ($env:RELEASE_LINUX_ARCH) { $env:RELEASE_LINUX_ARCH } else { "all" } |
| 21 | +$script:RELEASE_VERSION = "" |
| 22 | +$script:RELEASE_NO_BUILD = 0 |
| 23 | + |
| 24 | +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 25 | +$ReleaseScriptDir = Join-Path $ScriptDir "release" |
| 26 | + |
| 27 | +. (Join-Path $ReleaseScriptDir "common.ps1") |
| 28 | +. (Join-Path $ReleaseScriptDir "changelog.ps1") |
| 29 | +. (Join-Path $ReleaseScriptDir "version.ps1") |
| 30 | +. (Join-Path $ReleaseScriptDir "linux_targets.ps1") |
| 31 | +. (Join-Path $ReleaseScriptDir "build.ps1") |
| 32 | +. (Join-Path $ReleaseScriptDir "upload.ps1") |
| 33 | + |
| 34 | +function Show-ReleaseUsage { |
| 35 | + @" |
| 36 | +Usage: powershell -ExecutionPolicy Bypass -File scripts/release.ps1 [options] |
| 37 | +
|
| 38 | +Build signed Tauri bundles for the current host. |
| 39 | +Optionally bump version, rewrite CHANGELOG, tag, push, and upload to GitHub. |
| 40 | +
|
| 41 | +Options: |
| 42 | + --bump patch|minor|major Bump version in Cargo.toml + tauri.conf.json + CHANGELOG |
| 43 | + --no-changelog Skip CHANGELOG rewrite on bump |
| 44 | + --build Run cargo tauri build (default when not --upload-only / --no-build) |
| 45 | + --no-build Skip build |
| 46 | + --bundles LIST Pass to cargo tauri build --bundles (e.g. msi) |
| 47 | + --tag Create annotated git tag v{version} |
| 48 | + --push git push + push tag (requires --tag) |
| 49 | + --commit Commit version + CHANGELOG files |
| 50 | + --upload Upload bundle artifacts to GitHub release |
| 51 | + --upload-only Only upload (no bump/build/tag) |
| 52 | + --clobber Replace existing release assets with same name |
| 53 | + --require-signing Require TAURI_SIGNING_PRIVATE_KEY |
| 54 | + --allow-unsigned Alias for default unsigned build (no-op) |
| 55 | + --platform linux|macos|windows |
| 56 | + --linux-arch native|amd64|arm64|all |
| 57 | + Linux only: deb/rpm/AppImage per arch (default: all) |
| 58 | + --dry-run Print planned actions only |
| 59 | + -h, --help Show this help |
| 60 | +
|
| 61 | +Examples: |
| 62 | + scripts\release.cmd |
| 63 | + powershell -ExecutionPolicy Bypass -File scripts\release.ps1 --platform windows |
| 64 | + powershell -ExecutionPolicy Bypass -File scripts\release.ps1 --bump patch --build --upload |
| 65 | +"@ |
| 66 | +} |
| 67 | + |
| 68 | +$i = 0 |
| 69 | +while ($i -lt $args.Count) { |
| 70 | + switch ($args[$i]) { |
| 71 | + "--bump" { |
| 72 | + if ($i + 1 -ge $args.Count) { throw "--bump requires patch|minor|major" } |
| 73 | + $script:RELEASE_BUMP = $args[$i + 1] |
| 74 | + $i += 2 |
| 75 | + continue |
| 76 | + } |
| 77 | + "--no-changelog" { $script:RELEASE_NO_CHANGELOG = 1; $i++; continue } |
| 78 | + "--build" { $script:RELEASE_DO_BUILD = 1; $i++; continue } |
| 79 | + "--no-build" { $script:RELEASE_DO_BUILD = 0; $script:RELEASE_NO_BUILD = 1; $i++; continue } |
| 80 | + "--bundles" { |
| 81 | + if ($i + 1 -ge $args.Count) { throw "--bundles requires a list" } |
| 82 | + $script:RELEASE_BUNDLES = $args[$i + 1] |
| 83 | + $i += 2 |
| 84 | + continue |
| 85 | + } |
| 86 | + "--tag" { $script:RELEASE_DO_TAG = 1; $i++; continue } |
| 87 | + "--push" { $script:RELEASE_DO_PUSH = 1; $i++; continue } |
| 88 | + "--commit" { $script:RELEASE_DO_COMMIT = 1; $i++; continue } |
| 89 | + "--upload" { $script:RELEASE_DO_UPLOAD = 1; $i++; continue } |
| 90 | + "--upload-only" { $script:RELEASE_UPLOAD_ONLY = 1; $script:RELEASE_DO_UPLOAD = 1; $i++; continue } |
| 91 | + "--clobber" { $script:RELEASE_CLOBBER = 1; $i++; continue } |
| 92 | + "--require-signing" { $script:RELEASE_REQUIRE_SIGNING = 1; $i++; continue } |
| 93 | + "--allow-unsigned" { $i++; continue } |
| 94 | + "--platform" { |
| 95 | + if ($i + 1 -ge $args.Count) { throw "--platform requires linux|macos|windows" } |
| 96 | + $script:RELEASE_PLATFORM_OVERRIDE = $args[$i + 1] |
| 97 | + $i += 2 |
| 98 | + continue |
| 99 | + } |
| 100 | + "--linux-arch" { |
| 101 | + if ($i + 1 -ge $args.Count) { throw "--linux-arch requires native|amd64|arm64|all" } |
| 102 | + $script:RELEASE_LINUX_ARCH = $args[$i + 1] |
| 103 | + $i += 2 |
| 104 | + continue |
| 105 | + } |
| 106 | + "--dry-run" { $script:RELEASE_DRY_RUN = 1; $i++; continue } |
| 107 | + "-h" { Show-ReleaseUsage; exit 0 } |
| 108 | + "--help" { Show-ReleaseUsage; exit 0 } |
| 109 | + default { throw "Unknown option: $($args[$i]) (use --help)" } |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +Initialize-ReleaseCommon $ReleaseScriptDir |
| 114 | +Write-ReleaseInfo "Git remote: $script:RELEASE_GIT_REMOTE | GitHub: $script:RELEASE_GH_REPO" |
| 115 | + |
| 116 | +if ($script:RELEASE_UPLOAD_ONLY -eq 1) { |
| 117 | + $script:RELEASE_DO_BUILD = 0 |
| 118 | +} elseif ($script:RELEASE_NO_BUILD -ne 1 -and $script:RELEASE_DO_BUILD -eq 0 -and $script:RELEASE_DO_TAG -eq 0 -and -not $script:RELEASE_BUMP) { |
| 119 | + $script:RELEASE_DO_BUILD = 1 |
| 120 | +} elseif ($script:RELEASE_BUMP -and $script:RELEASE_NO_BUILD -ne 1 -and $script:RELEASE_DO_BUILD -eq 0 -and $script:RELEASE_UPLOAD_ONLY -ne 1) { |
| 121 | + $script:RELEASE_DO_BUILD = 1 |
| 122 | +} |
| 123 | + |
| 124 | +if ($script:RELEASE_DO_PUSH -eq 1 -and $script:RELEASE_DO_TAG -ne 1) { |
| 125 | + Stop-Release "--push requires --tag" |
| 126 | +} |
| 127 | + |
| 128 | +$script:RELEASE_VERSION = Read-ReleaseVersion |
| 129 | +$platform = Get-ReleasePlatform |
| 130 | +Write-ReleaseInfo "Project version: $script:RELEASE_VERSION (platform: $platform)" |
| 131 | + |
| 132 | +Import-ReleaseEnv |
| 133 | + |
| 134 | +$tagCurrent = "v$script:RELEASE_VERSION" |
| 135 | +if (Test-ReleaseGhReleaseExists $tagCurrent) { |
| 136 | + Write-ReleaseInfo "GitHub release $tagCurrent already exists" |
| 137 | +} elseif (Test-ReleaseRemoteTagExists $tagCurrent) { |
| 138 | + Write-ReleaseInfo "Remote tag $tagCurrent already exists" |
| 139 | +} |
| 140 | + |
| 141 | +if ($script:RELEASE_UPLOAD_ONLY -eq 1) { |
| 142 | + $script:RELEASE_BUMP = "" |
| 143 | + $script:RELEASE_DO_TAG = 0 |
| 144 | + $script:RELEASE_DO_BUILD = 0 |
| 145 | +} |
| 146 | + |
| 147 | +if ($script:RELEASE_BUMP) { |
| 148 | + Invoke-ReleaseBumpVersion $script:RELEASE_BUMP |
| 149 | + $tagCurrent = "v$script:RELEASE_VERSION" |
| 150 | + if ((Test-ReleaseGhReleaseExists $tagCurrent) -or (Test-ReleaseRemoteTagExists $tagCurrent)) { |
| 151 | + Stop-Release "Release $tagCurrent already exists on GitHub after bump" |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | +if ($script:RELEASE_DO_BUILD -eq 1) { |
| 156 | + Invoke-ReleasePrepareDeps |
| 157 | + try { |
| 158 | + Invoke-ReleaseBuild |
| 159 | + } catch { |
| 160 | + Write-ReleaseError $_.Exception.Message |
| 161 | + exit $script:RELEASE_EXIT_BUILD |
| 162 | + } |
| 163 | + Write-ReleaseInfo "Build artifacts (v$script:RELEASE_VERSION):" |
| 164 | + Show-ReleaseArtifacts $script:RELEASE_VERSION |
| 165 | +} |
| 166 | + |
| 167 | +if ($script:RELEASE_DO_COMMIT -eq 1) { |
| 168 | + if ($script:RELEASE_DRY_RUN -eq 1) { |
| 169 | + Write-ReleaseInfo "Would: git commit version + CHANGELOG" |
| 170 | + } else { |
| 171 | + & git add CHANGELOG.md Cargo.toml src-tauri/Cargo.toml src-tauri/tauri.conf.json |
| 172 | + $releaseStatus = (& git status --porcelain scripts/release.sh scripts/release/ .gitignore docs/user/building.md scripts/release.ps1 scripts/release.cmd 2>$null) |
| 173 | + if ($releaseStatus) { |
| 174 | + & git add scripts/release.sh scripts/release/ .gitignore docs/user/building.md scripts/release.ps1 scripts/release.cmd |
| 175 | + } |
| 176 | + & git commit -m "chore: release v$script:RELEASE_VERSION" |
| 177 | + if ($LASTEXITCODE -ne 0) { Stop-Release "git commit failed" } |
| 178 | + Write-ReleaseInfo "Committed release files" |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +if ($script:RELEASE_DO_TAG -eq 1) { |
| 183 | + Write-ReleaseGitDirtyWarn |
| 184 | + if ((Test-ReleaseRemoteTagExists $tagCurrent) -or (Test-ReleaseLocalTagExists $tagCurrent)) { |
| 185 | + Write-ReleaseWarn "Tag $tagCurrent already exists; skipping git tag (use --upload to add assets)" |
| 186 | + } elseif ($script:RELEASE_DRY_RUN -eq 1) { |
| 187 | + Write-ReleaseInfo "Would: git tag -a $tagCurrent -m `"BLXCode $script:RELEASE_VERSION`"" |
| 188 | + } else { |
| 189 | + & git tag -a $tagCurrent -m "BLXCode $script:RELEASE_VERSION" |
| 190 | + if ($LASTEXITCODE -ne 0) { Stop-Release "git tag failed" } |
| 191 | + Write-ReleaseInfo "Created tag $tagCurrent" |
| 192 | + } |
| 193 | +} |
| 194 | + |
| 195 | +if ($script:RELEASE_DO_PUSH -eq 1) { |
| 196 | + if ($script:RELEASE_DRY_RUN -eq 1) { |
| 197 | + Write-ReleaseInfo "Would: git push $script:RELEASE_GIT_REMOTE && git push $script:RELEASE_GIT_REMOTE $tagCurrent" |
| 198 | + } else { |
| 199 | + & git push $script:RELEASE_GIT_REMOTE |
| 200 | + if ($LASTEXITCODE -ne 0) { Stop-Release "git push failed" } |
| 201 | + if (Test-ReleaseLocalTagExists $tagCurrent) { |
| 202 | + if (-not (Test-ReleaseRemoteTagExists $tagCurrent)) { |
| 203 | + & git push $script:RELEASE_GIT_REMOTE $tagCurrent |
| 204 | + if ($LASTEXITCODE -ne 0) { Stop-Release "git tag push failed" } |
| 205 | + Write-ReleaseInfo "Pushed tag $tagCurrent to $script:RELEASE_GIT_REMOTE" |
| 206 | + } else { |
| 207 | + Write-ReleaseInfo "Tag $tagCurrent already on $script:RELEASE_GIT_REMOTE; skipping tag push" |
| 208 | + } |
| 209 | + } |
| 210 | + } |
| 211 | +} |
| 212 | + |
| 213 | +if ($script:RELEASE_DO_UPLOAD -eq 1) { |
| 214 | + Invoke-ReleaseUploadArtifacts $script:RELEASE_VERSION |
| 215 | +} |
| 216 | + |
| 217 | +Write-ReleaseInfo "Done." |
| 218 | + |
0 commit comments