f0671c06ad
CI does not have macOS or Windows runners, so provide scripts to build and optionally upload release archives locally. - scripts/build-release-macos.sh — builds x86_64 and aarch64-apple-darwin - scripts/build-release-windows.ps1 — builds x86_64-pc-windows-msvc - scripts/.env.example — template for Gitea credentials Both scripts read GITEA_TOKEN, GITEA_SERVER_URL, and GITEA_REPOSITORY from the environment or from scripts/.env (which is gitignored). Upload to Gitea is skipped when GITEA_TOKEN is not set. Use curl.exe for multipart upload in the PowerShell script to support Windows PowerShell 5.1 (Invoke-RestMethod -Form requires PS 6.1+). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
101 lines
3.4 KiB
PowerShell
101 lines
3.4 KiB
PowerShell
# Build release archive for Windows (x86_64-pc-windows-msvc).
|
|
#
|
|
# Usage:
|
|
# .\scripts\build-release-windows.ps1 [-Version <VERSION>]
|
|
#
|
|
# If -Version is not provided, it is read from Cargo.toml.
|
|
# Set GITEA_TOKEN (and optionally GITEA_SERVER_URL / GITEA_REPOSITORY)
|
|
# to upload the archive to a Gitea release automatically.
|
|
# These can be provided via scripts\.env.
|
|
|
|
param(
|
|
[string]$Version = ""
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$RepoRoot = Split-Path -Parent $ScriptDir
|
|
|
|
# Load .env if present (existing env vars take precedence)
|
|
$EnvFile = Join-Path $ScriptDir ".env"
|
|
if (Test-Path $EnvFile) {
|
|
Get-Content $EnvFile | ForEach-Object {
|
|
if ($_ -match '^\s*#' -or $_ -match '^\s*$') { return }
|
|
$parts = $_ -split '=', 2
|
|
$key = $parts[0].Trim()
|
|
$value = $parts[1].Trim()
|
|
if (-not [System.Environment]::GetEnvironmentVariable($key)) {
|
|
[System.Environment]::SetEnvironmentVariable($key, $value, "Process")
|
|
}
|
|
}
|
|
}
|
|
|
|
# Determine version
|
|
if (-not $Version) {
|
|
$cargoToml = Get-Content (Join-Path $RepoRoot "Cargo.toml") -Raw
|
|
if ($cargoToml -match 'version\s*=\s*"([^"]+)"') {
|
|
$Version = $Matches[1]
|
|
} else {
|
|
Write-Error "Could not determine version from Cargo.toml"
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
$Tag = "v$Version"
|
|
$Target = "x86_64-pc-windows-msvc"
|
|
|
|
Set-Location $RepoRoot
|
|
|
|
Write-Host "==> Building mdrs $Version for Windows ($Target)"
|
|
|
|
rustup target add $Target
|
|
cargo build --release --target $Target
|
|
|
|
$Archive = "mdrs-$Version-$Target.zip"
|
|
Compress-Archive -Force -Path "target\$Target\release\mdrs.exe" -DestinationPath $Archive
|
|
Write-Host " Created: $Archive"
|
|
|
|
# Upload to Gitea if token is provided
|
|
$GiteaToken = [System.Environment]::GetEnvironmentVariable("GITEA_TOKEN")
|
|
if (-not $GiteaToken) {
|
|
Write-Host ""
|
|
Write-Host "GITEA_TOKEN not set -- skipping upload."
|
|
Write-Host "Set GITEA_TOKEN (and GITEA_SERVER_URL, GITEA_REPOSITORY) in scripts\.env to enable upload."
|
|
exit 0
|
|
}
|
|
|
|
$ServerUrl = [System.Environment]::GetEnvironmentVariable("GITEA_SERVER_URL")
|
|
$Repository = [System.Environment]::GetEnvironmentVariable("GITEA_REPOSITORY")
|
|
if (-not $ServerUrl) { Write-Error "GITEA_SERVER_URL is required for upload"; exit 1 }
|
|
if (-not $Repository) { Write-Error "GITEA_REPOSITORY is required for upload"; exit 1 }
|
|
|
|
$Headers = @{ Authorization = "Bearer $GiteaToken"; "Content-Type" = "application/json" }
|
|
|
|
Write-Host ""
|
|
Write-Host "==> Creating Gitea release $Tag ..."
|
|
try {
|
|
Invoke-RestMethod -Method Post -Uri "$ServerUrl/api/v1/repos/$Repository/releases" `
|
|
-Headers $Headers `
|
|
-Body (ConvertTo-Json @{ tag_name = $Tag; name = $Tag }) | Out-Null
|
|
} catch {
|
|
# Release may already exist; continue
|
|
}
|
|
|
|
$Release = Invoke-RestMethod -Method Get -Uri "$ServerUrl/api/v1/repos/$Repository/releases/tags/$Tag" `
|
|
-Headers @{ Authorization = "Bearer $GiteaToken" }
|
|
$ReleaseId = $Release.id
|
|
|
|
Write-Host "==> Uploading $Archive (release id: $ReleaseId) ..."
|
|
$ArchivePath = Join-Path $RepoRoot $Archive
|
|
& curl.exe -sf -X POST `
|
|
-H "Authorization: Bearer $GiteaToken" `
|
|
-F "attachment=@$ArchivePath" `
|
|
"$ServerUrl/api/v1/repos/$Repository/releases/$ReleaseId/assets" | Out-Null
|
|
if ($LASTEXITCODE -ne 0) { Write-Error "Upload failed (exit code $LASTEXITCODE)"; exit 1 }
|
|
Write-Host " Done."
|
|
|
|
Write-Host ""
|
|
Write-Host "==> Upload complete: $ServerUrl/$Repository/releases/tag/$Tag"
|