Automate Windows and Linux releases with Forgejo Actions
Some checks are pending
Release AstroFrame / packages (push) Waiting to run

This commit is contained in:
Elijah 2026-10-03 19:31:43 -07:00
parent f971c374f8
commit 4e6d21de5a
9 changed files with 277 additions and 24 deletions

View file

@ -0,0 +1,63 @@
name: Release AstroFrame
on:
push:
branches: [main]
tags: ['v*']
workflow_dispatch:
jobs:
packages:
# Same Docker label/container family as Decky's existing validation workflow.
runs-on: docker
container:
image: node:22-bookworm
timeout-minutes: 45
env:
DOTNET_CLI_TELEMETRY_OPTOUT: '1'
DOTNET_NOLOGO: '1'
RELEASE_REF: ${{ github.ref }}
steps:
- name: Check out release source
uses: https://data.forgejo.org/actions/checkout@v6
with:
fetch-depth: 0
- name: Install build tools and Linux desktop dependencies
run: |
set -eu
apt-get update
apt-get install -y --no-install-recommends curl ca-certificates zip libicu72 libssl3 libx11-6 libice6 libsm6 libfontconfig1 libxrandr2 libxi6 libxcursor1 libxrender1 libxext6 xvfb xauth
mkdir -p .tools/ci-dotnet
curl -fsSL https://dot.net/v1/dotnet-install.sh -o .tools/dotnet-install-ci.sh
bash .tools/dotnet-install-ci.sh --channel 10.0 --quality GA --install-dir "$PWD/.tools/ci-dotnet" --no-path
bash .tools/dotnet-install-ci.sh --channel 8.0 --runtime dotnet --install-dir "$PWD/.tools/ci-dotnet" --no-path
export PATH="$PWD/.tools/ci-dotnet:$PATH"
export DOTNET_ROOT="$PWD/.tools/ci-dotnet"
dotnet tool install powershell --tool-path "$PWD/.tools/pwsh-ci" --version 7.4.20
- name: Validate and build Windows and Linux packages
run: |
set -eu
export PATH="$PWD/.tools/ci-dotnet:$PATH"
export DOTNET_ROOT="$PWD/.tools/ci-dotnet"
.tools/pwsh-ci/pwsh -NoProfile -File packaging/Build-ServerRelease.ps1 -Ref "$RELEASE_REF"
- name: Check packaged Linux settings page
run: |
set -eu
mkdir -p artifacts/server-release/qa
chmod +x artifacts/server-release/packages/linux-x64/AstroFrame-linux-x64.AppImage
APPIMAGE_EXTRACT_AND_RUN=1 xvfb-run -a artifacts/server-release/packages/linux-x64/AstroFrame-linux-x64.AppImage --capture-settings "$PWD/artifacts/server-release/qa/settings.png" 620 144
test -s artifacts/server-release/qa/settings.png
- name: Publish completed tagged release
if: startsWith(github.ref, 'refs/tags/v')
env:
# Forgejo supplies a repository-scoped token; no personal token is needed.
ASTROFRAME_RELEASE_TOKEN: ${{ github.token }}
run: |
set -eu
export PATH="$PWD/.tools/ci-dotnet:$PATH"
export DOTNET_ROOT="$PWD/.tools/ci-dotnet"
.tools/pwsh-ci/pwsh -NoProfile -File packaging/Publish.ps1 -Directory artifacts/server-release/packages -Publish -RequireTag

View file

@ -6,7 +6,7 @@ $env:NUGET_PACKAGES=Join-Path $PSScriptRoot '.tools/packages'
$env:DOTNET_CLI_TELEMETRY_OPTOUT='1'
New-Item -ItemType Directory -Force '.tools/feed' | Out-Null
$sdk=Join-Path $PSScriptRoot '.tools/dotnet/dotnet.exe'
if (!(Test-Path $sdk)) { $sdk='dotnet' }
if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT -or !(Test-Path $sdk)) { $sdk='dotnet' }
& $sdk build src/AstroFrame.Desktop -c Release
if ($LASTEXITCODE) { throw 'Build failed' }
& $sdk build tests/AstroFrame.Validation -c Release

View file

@ -42,6 +42,8 @@ Exports include `accepted.txt` with accepted output paths and `decisions.csv` wi
## Build and validate
The [server release workflow](.forgejo/workflows/release.yml) builds and publishes both platforms when a stable version tag such as `v1.0.1` is pushed. Set the matching version with `./packaging/Set-Version.ps1 -Version 1.0.1`, commit/push the source, then push the tag. It uses the existing Docker runner and automatically supplied Forgejo token. Pushes and manual Actions runs on `main` check the build without publishing. See [automatic releases](docs/releases.md#automatic-server-releases).
Requires a .NET 8 SDK. `Build.ps1` uses the workspace-local SDK if present, otherwise `dotnet` from PATH:
```powershell

View file

@ -50,7 +50,32 @@ The source is the repository's public Gitea releases API:
Only published stable release assets are consumed. Git commits by themselves do not trigger an update. End-user installations contain no repository write token. Packages use separate `win-x64` and `linux-x64` channels. Versions never downgrade automatically.
## Build release packages
## Automatic server releases
`.forgejo/workflows/release.yml` uses the same `docker` runner label and `node:22-bookworm` container family as Decky's validation workflow. The job installs a .NET 10 SDK, the .NET 8 runtime used by the tests, and PowerShell 7.4.20 inside its disposable container. The Linux runner builds **both** the Windows Setup executable and Linux AppImage using Velopack's cross-platform packager; a Windows runner is not required for these unsigned installers.
Once this workflow is committed and pushed, enable Actions for the AstroFrame repository and ensure its Docker runner is available. No separate personal token is needed for the workflow: the publish step uses Forgejo's built-in repository-scoped Actions token. The server must allow that token to create releases. The existing personal-token publisher remains available for local use.
To release a new version:
```powershell
./packaging/Set-Version.ps1 -Version 1.0.1
git add Directory.Build.props
git commit -m "Release 1.0.1"
git push origin main
git tag v1.0.1
git push origin v1.0.1
```
Include all intended source changes in the release commit before tagging. The pushed tag is the publication trigger; ordinary commits to `main` run the build and checks without publishing. The version in `Directory.Build.props` must exactly match the tag. For the first release, use `v1.0.0` after pushing this workflow and the finalized source.
The job runs the engine and updater validation suites, builds both packages, renders the Linux settings page under Xvfb, then uploads everything into one draft release. Only after all uploads succeed does it make the release public, so users cannot discover an incomplete update. No local installer build or manual asset attachment is needed.
Use **Actions → Release AstroFrame → Run workflow** on `main` to verify runner setup without publishing. A manual run on a version tag publishes that version. Existing published releases cannot be overwritten. Interrupted uploads remain draft releases and can resume when matching build files are reused. If a fresh rebuild generates different bytes, the publisher reports the conflicting draft asset; remove the incomplete draft explicitly before rerunning. Do not delete an already published version.
The workflow tests Linux execution in Debian Bookworm; it creates Windows packages but cannot exercise their Windows UI. Windows desktop acceptance still needs a Windows machine. Upload/package failures appear in the Actions job log. Builds require outbound access to the Forgejo checkout action, Microsoft's SDK download endpoints and NuGet, plus enough disk space for both self-contained builds.
## Local package builds
Set the next stable version in `Directory.Build.props`. `-Version` can override it for a build. The application and package versions must match. A .NET 10 SDK/runtime is needed for the pinned Velopack CLI; the application itself targets .NET 8 and is published self-contained. Use PowerShell 7 for the release scripts.
@ -73,13 +98,13 @@ That script builds the Linux channel. The tool manifest pins Velopack CLI 1.2.16
Commit and push the versioned source first. The initial release has **not** been uploaded by this implementation. To make update discovery live, create a public stable release tagged `v1.0.0` and attach the files described below.
The helper script reads a Gitea repository-write token from `ASTROFRAME_RELEASE_TOKEN` in the process environment. It uploads both platforms into one draft, including the Linux installation helpers. It does not store the token or embed it in the application:
The helper script reads a repository-write token from `ASTROFRAME_RELEASE_TOKEN` in the process environment. On the server this is supplied automatically by the workflow. For local publication, set your own Gitea/Forgejo repository-write token. The script uploads both platforms into one draft, including the Linux installation helpers. It does not store the token or embed it in the application:
```powershell
./packaging/Publish.ps1
```
Review the draft in Gitea and publish it there. For a deliberately immediate publication use `./packaging/Publish.ps1 -Publish`. The script refuses to modify an already published version. If a partial upload fails, delete the incomplete draft and retry, or attach the remaining files manually. Do not put the token in a script, commit, or command history.
Review the draft in Gitea and publish it there. For a deliberately immediate publication use `./packaging/Publish.ps1 -Publish`. The script refuses to modify an already published version. A partial upload can be resumed by rerunning with the same packages: existing assets are downloaded and compared by SHA256 before skipping them. Conflicting bytes require explicitly removing the draft asset or the incomplete draft. Do not put the token in a script, commit, or command history.
For manual publication attach, from **both** channel folders:
@ -90,10 +115,12 @@ For manual publication attach, from **both** channel folders:
Keep older published releases available. The CLI can produce delta packages when previous packages are in the output folder. Full packages always support upgrading from older installs, even without a delta.
For later releases: change the version, validate, build, push the corresponding source, and publish a new stable tagged release with both channels. Existing installations then receive the notification and can update without reinstalling.
For later releases, use the automatic tag workflow above, or validate/build/publish locally. Existing installations then receive the notification and can update without reinstalling.
## Verification
`./tools/Verify-ReleaseAutomation.ps1` exercises version/tag mismatch, upload failure, draft resumption, conflicting assets, immutable published releases and package integrity with a mocked release API. It never publishes a real release.
`tests/AstroFrame.Updates.Validation` covers settings recovery, network failures, concurrent checks, restart safety, save failure, real package checksums, corruption rejection and downgrade prevention. An optional release-feed argument adds real-package checks:
```powershell

View file

@ -0,0 +1,16 @@
#requires -Version 7.0
param([string]$Ref = $env:RELEASE_REF)
$ErrorActionPreference = 'Stop'
Set-Location (Split-Path $PSScriptRoot)
[xml]$props = Get-Content Directory.Build.props
$version = [string]$props.Project.PropertyGroup.Version
if ($version -notmatch '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$') { throw 'Directory.Build.props must contain a stable version such as 1.0.0.' }
if ($Ref -like 'refs/tags/*' -and $Ref -cne "refs/tags/v$version") {
throw "Release tag $Ref does not match version $version in Directory.Build.props."
}
if (!$Ref) { throw 'Supply the source ref, for example -Ref refs/tags/v1.0.0 or -Ref refs/heads/main for a build-only run.' }
Write-Output "Validating AstroFrame $version from $Ref"
& ./Build.ps1 -Test
if ($LASTEXITCODE) { throw 'Release validation failed.' }
& ./packaging/Release.ps1 -Version $version -Platform Both -PublishRoot artifacts/server-release/publish -Output artifacts/server-release/packages
Write-Output "Windows and Linux packages ready for AstroFrame $version."

View file

@ -1,30 +1,55 @@
param([string]$Version = '', [string]$Directory = 'artifacts/releases', [switch]$Publish)
#requires -Version 7.0
param([string]$Version = '', [string]$Directory = 'artifacts/releases', [switch]$Publish, [switch]$RequireTag)
$ErrorActionPreference = 'Stop'
Set-Location (Split-Path $PSScriptRoot)
if (!$Version) { [xml]$props = Get-Content Directory.Build.props; $Version = $props.Project.PropertyGroup.Version }
if ($Version -notmatch '^\d+\.\d+\.\d+$') { throw 'Use a stable version such as 1.0.0.' }
if (!$env:ASTROFRAME_RELEASE_TOKEN) { throw 'Set ASTROFRAME_RELEASE_TOKEN to a Gitea token with repository write permission. Never put it in source control.' }
[xml]$props = Get-Content Directory.Build.props
$sourceVersion = [string]$props.Project.PropertyGroup.Version
if (!$Version) { $Version = $sourceVersion }
if ($Version -notmatch '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$') { throw 'Use a stable version such as 1.0.0.' }
if ($Version -ne $sourceVersion) { throw "Package version $Version does not match source version $sourceVersion. Commit the matching version before releasing." }
if (!$env:ASTROFRAME_RELEASE_TOKEN) { throw 'Set ASTROFRAME_RELEASE_TOKEN to the Forgejo Actions token or a repository-write personal token.' }
$headers = @{ Authorization = "token $env:ASTROFRAME_RELEASE_TOKEN" }
$api = 'https://git.elijahkuntz.com/api/v1/repos/Elijah/AstroFrame'
$files = @()
foreach ($channel in @('win-x64','linux-x64')) {
$folder = Join-Path $Directory $channel
$feedPath = Join-Path $folder "releases.$channel.json"
if (!(Test-Path $feedPath)) { throw "Missing release feed: $feedPath" }
if (!(Test-Path -LiteralPath $feedPath)) { throw "Missing release feed: $feedPath" }
$feed = Get-Content $feedPath -Raw | ConvertFrom-Json
$latest = @($feed.Assets | Where-Object { $_.Type -eq 'Full' -and $_.Version -eq $Version })
$latest = @($feed.Assets | Where-Object { $_.Type -eq 'Full' -and $_.Version -eq $Version -and $_.PackageId -eq 'AstroFrame' })
if ($latest.Count -ne 1) { throw "No full $Version release for $channel" }
$files += @(Get-ChildItem -LiteralPath $folder -File | Where-Object { $_.Extension -in @('.exe','.AppImage','.nupkg','.json','.sh','.png','.zip') -or $_.Name -like 'RELEASES-*' })
}
foreach ($file in $files) {
if ($file.Extension -eq '.nupkg' -and $file.Name -notlike "AstroFrame-$Version-*") { continue }
if ($file.Length -eq 0) { throw "Empty release asset: $($file.Name)" }
if (@($feed.Assets | Where-Object { $_.Type -eq 'Full' -and [version]$_.Version -gt [version]$Version }).Count) { throw "Feed $channel contains a newer release than $Version." }
$names = @("releases.$channel.json", "RELEASES-$channel", "assets.$channel.json")
foreach ($asset in @($feed.Assets | Where-Object { $_.Version -eq $Version })) {
if ($asset.FileName -notmatch "^AstroFrame-$([regex]::Escape($Version))-$channel-(full|delta)\.nupkg$") { throw "Unexpected package name in $channel feed." }
$path = Join-Path $folder $asset.FileName
if (!(Test-Path -LiteralPath $path)) { throw "Missing package: $path" }
if ((Get-Item -LiteralPath $path).Length -ne $asset.Size -or (Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash -ne $asset.SHA256) { throw "Package does not match its feed checksum: $path" }
$names += $asset.FileName
}
if ($channel -eq 'win-x64') { $names += 'AstroFrame-win-x64-Setup.exe' }
else {
$names += @('AstroFrame-linux-x64.AppImage', 'install-linux.sh', 'astroframe.png')
if (Test-Path -LiteralPath (Join-Path $folder "AstroFrame-$Version-linux-x64.zip")) { $names += "AstroFrame-$Version-linux-x64.zip" }
}
foreach ($name in $names) {
$file = Get-Item -LiteralPath (Join-Path $folder $name)
if ($file.Length -eq 0) { throw "Empty release asset: $name" }
$files += $file
}
}
$commit = (& git rev-parse HEAD).Trim()
if ($LASTEXITCODE) { throw 'Cannot identify the release commit.' }
if (@(& git status --porcelain).Count -gt 0) { throw 'Commit the release source and push it before publishing.' }
$status = @(& git status --porcelain)
if ($LASTEXITCODE) { throw 'Cannot check release source status.' }
if ($status.Count -gt 0) { throw 'Commit the release source and push it before publishing.' }
Invoke-RestMethod "$api/commits/$commit" -Headers $headers | Out-Null
$tag = "v$Version"
$remoteTag = $null
try { $remoteTag = Invoke-RestMethod "$api/tags/$tag" -Headers $headers }
catch { if ([int]$_.Exception.Response.StatusCode -ne 404) { throw } }
if ($RequireTag -and !$remoteTag) { throw "Push tag $tag before running the server release publisher." }
if ($remoteTag -and $remoteTag.commit.sha -ne $commit) { throw "Tag $tag points to another commit. Use the tagged source to publish." }
$release = $null
try { $release = Invoke-RestMethod "$api/releases/tags/$tag" -Headers $headers }
catch { if ([int]$_.Exception.Response.StatusCode -ne 404) { throw } }
@ -35,13 +60,26 @@ if (!$release) {
}
$attached = @(Invoke-RestMethod "$api/releases/$($release.id)/assets" -Headers $headers)
foreach ($file in $files) {
if ($file.Extension -eq '.nupkg' -and $file.Name -notlike "AstroFrame-$Version-*") { continue }
if ($attached.name -contains $file.Name) { throw "Draft already contains $($file.Name). Remove the conflicting asset explicitly before retrying." }
$existing = @($attached | Where-Object name -EQ $file.Name)
if ($existing.Count) {
# Resume partial drafts only when the existing upload is byte-for-byte identical.
$downloadUrl = [uri]$existing[0].browser_download_url
if ($downloadUrl.Scheme -ne 'https' -or $downloadUrl.Host -ne 'git.elijahkuntz.com') { throw 'Unexpected release asset download host.' }
$temporary = Join-Path ([IO.Path]::GetTempPath()) ("AstroFrame-asset-check-" + [guid]::NewGuid())
try {
Invoke-WebRequest -Uri $downloadUrl -Headers $headers -OutFile $temporary
if ((Get-FileHash -LiteralPath $temporary -Algorithm SHA256).Hash -ne (Get-FileHash -LiteralPath $file.FullName -Algorithm SHA256).Hash) { throw "Draft contains different bytes for $($file.Name). Remove that draft asset explicitly before retrying." }
} finally { if (Test-Path -LiteralPath $temporary) { Remove-Item -LiteralPath $temporary } }
Write-Output "Already attached: $($file.Name)"
continue
}
$name = [Uri]::EscapeDataString($file.Name)
Invoke-RestMethod "$api/releases/$($release.id)/assets?name=$name" -Method Post -Headers $headers -Form @{ attachment=$file } | Out-Null
$uploaded = Invoke-RestMethod "$api/releases/$($release.id)/assets?name=$name" -Method Post -Headers $headers -Form @{ attachment=$file }
if ($uploaded.name -ne $file.Name -or $uploaded.size -ne $file.Length) { throw "Incomplete upload: $($file.Name). Release remains a draft." }
Write-Output "Attached $($file.Name)"
}
# A failed upload never makes a partial version visible to installed applications.
if ($Publish) {
Invoke-RestMethod "$api/releases/$($release.id)" -Method Patch -Headers $headers -ContentType 'application/json' -Body '{"draft":false}' | Out-Null
Write-Output "Published $($release.html_url)"
} else { Write-Output "Draft release ready: $($release.html_url). Review it, then publish in Gitea." }
} else { Write-Output "Draft release ready: $($release.html_url). Review it, then publish in Forgejo." }

View file

@ -1,3 +1,4 @@
#requires -Version 7.0
param(
[string]$Version = '',
[ValidateSet('Both','Windows','Linux')][string]$Platform = 'Both',
@ -14,14 +15,15 @@ $env:NUGET_PACKAGES = Join-Path $root '.tools/packages'
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
New-Item -ItemType Directory -Force '.tools/feed' | Out-Null
$sdk = Join-Path $root '.tools/dotnet/dotnet.exe'
if (!(Test-Path $sdk)) { $sdk = 'dotnet' }
if (!$IsWindows -or !(Test-Path $sdk)) { $sdk = 'dotnet' }
$localVpk = Join-Path $root '.tools/vpk/vpk.exe'
if (!(Test-Path $localVpk)) {
$useLocalVpk = $IsWindows -and (Test-Path $localVpk)
if (!$useLocalVpk) {
& dotnet tool restore
if ($LASTEXITCODE) { throw 'Velopack restore failed. Its CLI requires a .NET 10 SDK/runtime.' }
}
function Invoke-Vpk([string[]]$Arguments) {
if (Test-Path $localVpk) { & $localVpk @Arguments } else { & dotnet tool run vpk -- @Arguments }
if ($useLocalVpk) { & $localVpk @Arguments } else { & dotnet tool run vpk -- @Arguments }
if ($LASTEXITCODE) { throw 'Velopack packaging failed.' }
}
foreach ($rid in @('win-x64','linux-x64')) {

View file

@ -0,0 +1,8 @@
param([Parameter(Mandatory)][ValidatePattern('^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$')][string]$Version)
$ErrorActionPreference = 'Stop'
$path = Join-Path (Split-Path $PSScriptRoot) 'Directory.Build.props'
$content = Get-Content -LiteralPath $path -Raw
if ([regex]::Matches($content, '<Version>[^<]+</Version>').Count -ne 1) { throw 'Expected one Version in Directory.Build.props.' }
$content = [regex]::Replace($content, '<Version>[^<]+</Version>', "<Version>$Version</Version>")
[IO.File]::WriteAllText($path, $content)
Write-Output "AstroFrame version set to $Version. Commit and push the source, then push tag v$Version to build and publish automatically."

View file

@ -0,0 +1,97 @@
#requires -Version 7.0
$ErrorActionPreference = 'Stop'
$root = Split-Path $PSScriptRoot
Set-Location $root
[xml]$props = Get-Content Directory.Build.props
$version = [string]$props.Project.PropertyGroup.Version
$fixture = Join-Path $root ('artifacts/release-automation-tests/' + [guid]::NewGuid())
$state = @{ Draft=$true; Created=$false; Published=$false; FailName=''; TagCommit=('a'*40); Dirty=$false; Calls=0; Assets=[Collections.Generic.List[object]]::new(); CorruptExisting=$false }
$savedToken = $env:ASTROFRAME_RELEASE_TOKEN
$env:ASTROFRAME_RELEASE_TOKEN = 'fixture-token'
$passed = 0
function Check($condition, [string]$label) { if (!$condition) { throw $label }; $script:passed++; Write-Output "PASS $label" }
function Reject([scriptblock]$operation, [string]$message) {
try { & $operation | Out-Null } catch { if ($_.Exception.Message -like "*$message*") { return }; throw }
throw "Expected failure: $message"
}
# Mock only remote operations and Git state; asset validation uses real files and hashes.
function git {
$global:LASTEXITCODE = 0
if ($args[0] -eq 'rev-parse') { return ('a'*40) }
if ($args[0] -eq 'status' -and $state.Dirty) { return ' M source.cs' }
}
function Invoke-RestMethod {
param([string]$Uri, [string]$Method='Get', $Headers, [string]$ContentType, [string]$Body, $Form)
$state.Calls++
if ($Uri -match '/commits/') { return @{ sha=('a'*40) } }
if ($Uri -match '/tags/' -and $Uri -notmatch '/releases/tags/') { return @{ commit=@{sha=$state.TagCommit} } }
if ($Uri -match '/releases/tags/') {
if (!$state.Created) { throw [Microsoft.PowerShell.Commands.HttpResponseException]::new('Not found', [Net.Http.HttpResponseMessage]::new([Net.HttpStatusCode]::NotFound)) }
return @{ id=1; draft=$state.Draft; html_url='https://git.elijahkuntz.com/Elijah/AstroFrame/releases' }
}
if ($Method -eq 'Post' -and $Uri.EndsWith('/releases')) {
$data = $Body | ConvertFrom-Json
if (!$data.draft) { throw 'Release must start as a draft.' }
$state.Created = $true
return @{ id=1; draft=$true; html_url='https://git.elijahkuntz.com/Elijah/AstroFrame/releases' }
}
if ($Method -eq 'Get' -and $Uri.EndsWith('/assets')) { return $state.Assets.ToArray() }
if ($Method -eq 'Post' -and $Uri -match '/assets\?') {
$file = $Form.attachment
if ($file.Name -eq $state.FailName) { throw 'Simulated upload failure.' }
$asset = @{ name=$file.Name; size=$file.Length; browser_download_url=('https://git.elijahkuntz.com/test-assets/' + [uri]::EscapeDataString($file.Name)); LocalPath=$file.FullName }
$state.Assets.Add($asset)
return $asset
}
if ($Method -eq 'Patch') { $state.Published=$true; return @{} }
throw "Unexpected mocked request: $Method $Uri"
}
function Invoke-WebRequest {
param([uri]$Uri, $Headers, [string]$OutFile)
$name = [uri]::UnescapeDataString($Uri.Segments[-1])
$asset = $state.Assets | Where-Object name -EQ $name | Select-Object -First 1
if ($state.CorruptExisting) { [IO.File]::WriteAllText($OutFile, 'different bytes') }
else { Copy-Item -LiteralPath $asset.LocalPath -Destination $OutFile }
}
try {
foreach ($channel in @('win-x64','linux-x64')) {
$folder = Join-Path $fixture $channel
New-Item -ItemType Directory -Force $folder | Out-Null
$package = "AstroFrame-$version-$channel-full.nupkg"
[IO.File]::WriteAllText((Join-Path $folder $package), 'test-package-bytes')
$asset = @{ PackageId='AstroFrame';Version=$version;Type='Full';FileName=$package;SHA256=(Get-FileHash (Join-Path $folder $package)).Hash;Size=(Get-Item (Join-Path $folder $package)).Length }
@{Assets=@($asset)} | ConvertTo-Json -Depth 4 | Set-Content (Join-Path $folder "releases.$channel.json")
$names = @("RELEASES-$channel", "assets.$channel.json")
if ($channel -eq 'win-x64') { $names += 'AstroFrame-win-x64-Setup.exe' }
else { $names += @('AstroFrame-linux-x64.AppImage','install-linux.sh','astroframe.png',"AstroFrame-$version-linux-x64.zip",'AstroFrame-0.0.1-linux-x64.zip') }
foreach ($name in $names) { [IO.File]::WriteAllText((Join-Path $folder $name), "fixture-$name") }
}
Reject { & ./packaging/Build-ServerRelease.ps1 -Ref refs/tags/v999.0.0 } 'does not match'
Check ($state.Calls -eq 0) 'mismatched version tag fails before build or release requests'
$state.FailName='AstroFrame-win-x64-Setup.exe'
Reject { & ./packaging/Publish.ps1 -Directory $fixture -Publish -RequireTag } 'Simulated upload failure'
Check ($state.Created -and !$state.Published) 'upload failure leaves the release unpublished as a draft'
$uploadedBeforeRetry = $state.Assets.Count
$state.FailName=''
& ./packaging/Publish.ps1 -Directory $fixture -Publish -RequireTag | Out-Null
Check ($state.Published -and $uploadedBeforeRetry -gt 0) 'interrupted draft resumes and publishes after all uploads succeed'
Check (($state.Assets.name | Select-Object -Unique).Count -eq $state.Assets.Count) 'resuming identical files does not create duplicate attachments'
Check ($state.Assets.name -notcontains 'AstroFrame-0.0.1-linux-x64.zip') 'older build archives are excluded from a new release'
$state.Published=$false; $state.CorruptExisting=$true
Reject { & ./packaging/Publish.ps1 -Directory $fixture -Publish -RequireTag } 'different bytes'
Check (!$state.Published) 'conflicting draft assets prevent publication'
$state.CorruptExisting=$false; $state.Draft=$false
Reject { & ./packaging/Publish.ps1 -Directory $fixture -Publish -RequireTag } 'already published'
Check (!$state.Published) 'published releases cannot be overwritten'
$state.Draft=$true; $state.TagCommit=('b'*40)
Reject { & ./packaging/Publish.ps1 -Directory $fixture -Publish -RequireTag } 'another commit'
Check (!$state.Published) 'a tag pointing to different source cannot be released'
$state.TagCommit=('a'*40); $state.Dirty=$true
Reject { & ./packaging/Publish.ps1 -Directory $fixture -Publish -RequireTag } 'Commit the release source'
Check (!$state.Published) 'uncommitted source cannot be released'
$state.Dirty=$false; $state.Calls=0
[IO.File]::WriteAllText((Join-Path $fixture "win-x64/AstroFrame-$version-win-x64-full.nupkg"), 'corrupt')
Reject { & ./packaging/Publish.ps1 -Directory $fixture -Publish -RequireTag } 'checksum'
Check ($state.Calls -eq 0) 'corrupt packages fail before any remote mutation'
Write-Output "$passed release automation checks passed. No real release API calls were made."
} finally { $env:ASTROFRAME_RELEASE_TOKEN = $savedToken }