Files
uconsole_asw_game/.github/workflows/windows.yml
T
Claude 33311ac3a4 Publish job waits up to 100 min for the tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 17:56:34 +00:00

333 lines
14 KiB
YAML

# Builds the Windows program (U-Jagd-Windows.exe) and the macOS app (U-Jagd.app,
# zipped per processor as U-Jagd-macOS-<arch>.zip; packaging/macos) on every
# push and pull request and self-tests them; both start straight into the
# game. A push to main then publishes them, from the one final job, as the
# GitHub release "v<APP_VERSION>"; the programs' update checks read that release.
name: Windows and macOS programs
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: write
actions: read # the publish job waits for the "Tests" run of its commit
concurrency:
group: windows-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build:
name: Windows
runs-on: windows-latest
# A hung self-test must not hold the release queue for the 6 h default.
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: python -m pip install -e ".[windows]"
- name: Read version
id: version
shell: bash
run: echo "version=$(python -c 'from src.core.version import APP_VERSION; print(APP_VERSION)')" >> "$GITHUB_OUTPUT"
- name: Build U-Jagd-Windows.exe
run: pyinstaller --noconfirm packaging/windows/u-jagd-windows.spec
- name: Self-test the built program
shell: pwsh
run: |
$report = Join-Path $env:RUNNER_TEMP "selftest.json"
$p = Start-Process -FilePath dist\U-Jagd-Windows.exe -ArgumentList "--self-test", "`"$report`"" -Wait -PassThru
Get-Content $report
if ($p.ExitCode -ne 0) { exit 1 }
- name: Self-test HTTPS to GitHub
# The update check must verify GitHub's certificate with the bundled
# root certificates (certifi), as on a player's PC.
shell: pwsh
run: |
$report = Join-Path $env:RUNNER_TEMP "selftest-tls.json"
$p = Start-Process -FilePath dist\U-Jagd-Windows.exe -ArgumentList "--tls-self-test", "`"$report`"" -Wait -PassThru
Get-Content $report
if ($p.ExitCode -ne 0) { exit 1 }
- name: Self-test a restart after a self-update
# The update restarts the swapped exe from a process that carries the
# old one's extraction variables; it must unpack afresh (1.3.17 fix).
shell: pwsh
run: |
$exe = (Resolve-Path dist\U-Jagd-Windows.exe).Path
$report = Join-Path $env:RUNNER_TEMP "selftest-update.json"
$env:_PYI_APPLICATION_HOME_DIR = Join-Path $env:TEMP "_MEI000gone"
$env:_PYI_ARCHIVE_FILE = $exe
$env:_PYI_PARENT_PROCESS_LEVEL = "1"
$env:PYINSTALLER_RESET_ENVIRONMENT = "1"
$p = Start-Process -FilePath $exe -ArgumentList "--self-test", "`"$report`"" -Wait -PassThru
Get-Content $report
if ($p.ExitCode -ne 0) { exit 1 }
- name: Self-test the update swap
# "Install update" end to end: the running exe starts the install
# script and exits; the script must replace it with <exe>.new and start
# the new file (1.3.73 fix: it used to leave .new and restart the old).
shell: pwsh
run: |
$dir = Join-Path $env:RUNNER_TEMP "update-test"
New-Item -ItemType Directory -Force $dir | Out-Null
$exe = Join-Path $dir "U-Jagd-Windows.exe"
Copy-Item dist\U-Jagd-Windows.exe $exe
Copy-Item dist\U-Jagd-Windows.exe "$exe.new"
$report = Join-Path $env:RUNNER_TEMP "selftest-swap.json"
$p = Start-Process -FilePath $exe -ArgumentList "--update-self-test", "`"$report`"" -Wait -PassThru
if ($p.ExitCode -ne 0) { Write-Error "update self-test exited with $($p.ExitCode)"; exit 1 }
$deadline = (Get-Date).AddMinutes(5)
$result = $null
while ($null -eq $result -and (Get-Date) -lt $deadline) {
try { $result = Get-Content $report -Raw -ErrorAction Stop | ConvertFrom-Json } catch { Start-Sleep 2 }
}
if ($null -eq $result) { Write-Error "the swapped program did not start"; exit 1 }
Get-Content $report
if (Test-Path "$exe.new") { Write-Error "the update was left as .new"; exit 1 }
if (-not $result.ok) { exit 1 }
- uses: actions/upload-artifact@v4
with:
name: U-Jagd-Windows-${{ steps.version.outputs.version }}
path: dist/U-Jagd-Windows.exe
macos:
name: macOS ${{ matrix.arch }}
# Apple silicon only (Dominik, 2026-10-04: no Intel build any more).
# pygame and NumPy publish no universal2 wheels, so the bundle is built
# natively on an arm64 runner.
strategy:
fail-fast: false
matrix:
include:
- arch: arm64
runner: macos-latest
runs-on: ${{ matrix.runner }}
# A hung self-test must not hold the release queue for the 6 h default.
timeout-minutes: 30
env:
ZIP: U-Jagd-macOS-${{ matrix.arch }}.zip
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Check the processor
run: |
machine=$(python -c 'import platform; print(platform.machine())')
echo "runner $(uname -m), Python $machine"
test "$machine" = "${{ matrix.arch }}"
- name: Install dependencies
run: python -m pip install -e ".[macos]"
- name: Read version
id: version
run: echo "version=$(python -c 'from src.core.version import APP_VERSION; print(APP_VERSION)')" >> "$GITHUB_OUTPUT"
- name: Build U-Jagd.app
run: pyinstaller --noconfirm packaging/macos/u-jagd-macos.spec
- name: Self-test the built app
run: |
report="$RUNNER_TEMP/selftest.json"
code=0
dist/U-Jagd.app/Contents/MacOS/U-Jagd --self-test "$report" || code=$?
cat "$report"
test "$code" -eq 0
- name: Self-test HTTPS to GitHub
# A player's Mac has no certificate folder of the Python the app was
# built with (before 1.3.173 every update check failed verification, so no
# notice appeared). Point OpenSSL's defaults nowhere, as there: the
# app must still verify GitHub with its bundled certificates.
run: |
report="$RUNNER_TEMP/selftest-tls.json"
code=0
SSL_CERT_FILE=/nonexistent/cert.pem SSL_CERT_DIR=/nonexistent \
dist/U-Jagd.app/Contents/MacOS/U-Jagd --tls-self-test "$report" || code=$?
cat "$report"
test "$code" -eq 0
- name: Self-test the update swap
# "Update now" end to end: the running app starts the swap script and
# exits; the script must move <app>.update/U-Jagd.app into place,
# remove the old bundle and the staging folder, and open the new app.
run: |
dir="$RUNNER_TEMP/update-test"
mkdir -p "$dir/U-Jagd.app.update"
ditto dist/U-Jagd.app "$dir/U-Jagd.app"
ditto dist/U-Jagd.app "$dir/U-Jagd.app.update/U-Jagd.app"
report="$RUNNER_TEMP/selftest-swap.json"
"$dir/U-Jagd.app/Contents/MacOS/U-Jagd" --update-self-test "$report"
for _ in $(seq 150); do
python -c 'import json, sys; json.load(open(sys.argv[1]))' "$report" 2>/dev/null && break
sleep 2
done
test -s "$report" || { echo "the swapped app did not start"; exit 1; }
cat "$report"
test ! -e "$dir/U-Jagd.app.update" || { echo "the update was left in staging"; exit 1; }
test ! -e "$dir/U-Jagd.app.old" || { echo "the old bundle was left behind"; exit 1; }
test -x "$dir/U-Jagd.app/Contents/MacOS/U-Jagd"
python -c 'import json, sys; sys.exit(0 if json.load(open(sys.argv[1]))["ok"] else 1)' "$report"
- name: Zip U-Jagd.app
run: ditto -c -k --norsrc --noextattr --keepParent dist/U-Jagd.app "dist/$ZIP"
- name: Self-test the zip as the updater unpacks it
timeout-minutes: 10
# The in-game update unpacks the zip with Python (src/launcher/update.py),
# not with ditto: the unpacked bundle (links, modes, ad-hoc signature)
# must still run.
run: |
dir="$RUNNER_TEMP/unpack-test"
mkdir -p "$dir"
python - "$dir" "dist/$ZIP" <<'PY'
import os, sys
from src.launcher import update
bundle = update.MacBundle(os.path.join(sys.argv[1], "U-Jagd.app"))
print(update.unpack_app(sys.argv[2], bundle))
PY
app="$dir/U-Jagd.app.update/U-Jagd.app"
codesign --verify --deep --strict --verbose=2 "$app" || echo "::warning::codesign does not verify the unpacked bundle"
report="$RUNNER_TEMP/selftest-unpacked.json"
code=0
"$app/Contents/MacOS/U-Jagd" --self-test "$report" || code=$?
cat "$report"
test "$code" -eq 0
- uses: actions/upload-artifact@v4
with:
name: U-Jagd-macOS-${{ matrix.arch }}-${{ steps.version.outputs.version }}
path: dist/${{ env.ZIP }}
publish:
name: Publish release
# One job creates the release and uploads every asset, so the builds never
# race. It publishes only after the "Tests" workflow passed on the same
# commit: a red main never reaches the updaters. A failed Windows or macOS
# build does not hold back the release (the uConsole updater needs only
# the tag); the missing file stays missing until the failed job is re-run,
# which re-runs this job and adds it.
needs: [build, macos]
if: >-
always() && github.event_name == 'push' && github.ref == 'refs/heads/main'
&& (needs.build.result == 'success' || needs.build.result == 'failure')
runs-on: ubuntu-latest
timeout-minutes: 110
steps:
- uses: actions/checkout@v4
- name: Wait for the tests of this commit
env:
GH_TOKEN: ${{ github.token }}
run: |
# Poll the "Tests" workflow run of this push (tests.yml); publish only
# on success. Gives up after about 100 minutes.
for attempt in $(seq 1 200); do
run=$(gh api "repos/$GITHUB_REPOSITORY/actions/workflows/tests.yml/runs?head_sha=$GITHUB_SHA&event=push&per_page=1" \
--jq '.workflow_runs[0] | "\(.status) \(.conclusion)"' || true)
echo "Tests run: ${run:-not started}"
case "$run" in
"completed success") exit 0 ;;
completed*) echo "::error::Tests failed on $GITHUB_SHA; no release."; exit 1 ;;
esac
sleep 30
done
echo "::error::Tests did not finish in time; no release."
exit 1
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Read version
id: version
run: echo "version=$(python -c 'from src.core.version import APP_VERSION; print(APP_VERSION)')" >> "$GITHUB_OUTPUT"
- uses: actions/download-artifact@v4
# Nothing to download when both builds failed; the release then
# carries only the tag for the uConsole updater.
continue-on-error: true
with:
pattern: U-Jagd-*-${{ steps.version.outputs.version }}
path: release-assets
merge-multiple: true
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
# One release per version, shared with other build jobs (for example
# the uConsole package): create it if missing, then add each asset
# unless it is already there. Never replace a published asset.
tag="v$VERSION"
mkdir -p release-assets
ls -l release-assets
if ! gh release view "$tag" >/dev/null 2>&1; then
# Release text: this version's CHANGELOG.md entry plus the install hints.
{ python tools/changelog_notes.py "$VERSION" || echo "U-Jagd $VERSION."
echo
echo "Windows: download U-Jagd-Windows.exe and run it; it offers later versions itself."
echo
echo "macOS (Apple silicon): download U-Jagd-macOS-arm64.zip, unzip it, move U-Jagd.app to Applications and open it the first time with right-click > Open (the app is not notarized); it offers later versions itself."
} > release-notes.md
gh release create "$tag" --target "$GITHUB_SHA" --title "U-Jagd $VERSION" \
--notes-file release-notes.md \
|| gh release view "$tag" >/dev/null
fi
published=$(gh release view "$tag" --json assets --jq '.assets[].name')
for name in U-Jagd-Windows.exe U-Jagd-macOS-arm64.zip; do
if printf '%s\n' "$published" | grep -qx "$name"; then
echo "$name is already published for $tag; bump src/core/version.py for a new build."
elif [ -f "release-assets/$name" ]; then
gh release upload "$tag" "release-assets/$name"
else
echo "::warning::$name was not built; $tag has no $name."
fi
done
- name: Remove older releases and tags
# Only the newest release and its tag stay on GitHub (Dominik,
# 2026-09-28/29). All updaters read releases/latest only; the uConsole
# updater fetches just that tag. Tags not named vX.Y.Z are kept.
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
# Keep the older releases while this one lacks the Windows program:
# Windows players would otherwise have no release to update from.
if ! gh release view "v$VERSION" --json assets --jq '.assets[].name' | grep -qx "U-Jagd-Windows.exe"; then
echo "::warning::v$VERSION has no U-Jagd-Windows.exe yet; older releases kept."
exit 0
fi
gh api --paginate "repos/$GITHUB_REPOSITORY/releases?per_page=100" --jq '.[].tag_name' \
| python tools/prune_releases.py "$VERSION" \
| while read -r old; do
echo "Deleting release $old"
gh release delete "$old" --yes
done
gh api --paginate "repos/$GITHUB_REPOSITORY/tags?per_page=100" --jq '.[].name' \
| python tools/prune_releases.py "$VERSION" \
| while read -r old; do
echo "Deleting tag $old"
gh api -X DELETE "repos/$GITHUB_REPOSITORY/git/refs/tags/$old"
done