Files
uconsole_asw_game/.github/workflows/windows.yml
T

112 lines
4.4 KiB
YAML

# Builds the Windows program (U-Jagd-Windows.exe: starter window + game) on
# every push and pull request. A push to main publishes it as the GitHub
# release "v<APP_VERSION>"; the program's update check reads that release.
name: Windows program
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: write
concurrency:
group: windows-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build:
runs-on: windows-latest
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 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 }
- uses: actions/upload-artifact@v4
with:
name: U-Jagd-Windows-${{ steps.version.outputs.version }}
path: dist/U-Jagd-Windows.exe
- name: Publish release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
shell: bash
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 this asset
# unless it is already there. Never replace a published asset.
tag="v$VERSION"
if ! gh release view "$tag" >/dev/null 2>&1; then
# Release text: this version's CHANGELOG.md entry plus the Windows hint.
{ 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."
} > 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
if gh release view "$tag" --json assets --jq '.assets[].name' | grep -qx "U-Jagd-Windows.exe"; then
echo "U-Jagd-Windows.exe is already published for $tag; bump src/core/version.py for a new build."
else
gh release upload "$tag" dist/U-Jagd-Windows.exe
fi
- name: Remove older releases
# Only the newest release stays on GitHub (Dominik, 2026-09-28). Both
# updaters read releases/latest only; the git tags stay.
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
gh release view "v$VERSION" --json assets --jq '.assets[].name' | grep -qx "U-Jagd-Windows.exe"
gh api --paginate "repos/$GITHUB_REPOSITORY/releases?per_page=100" --jq '.[].tag_name' \
| python tools/prune_releases.py "$VERSION" \
| while read -r old; do
old=${old%$'\r'}
echo "Deleting release $old (tag kept)"
gh release delete "$old" --yes
done