Aetheria/.forgejo/workflows/release.yml
soul 6ccf5b4e09 Release workflow: fix backslash normalisation in bash preflight
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 20:47:32 +01:00

117 lines
5.6 KiB
YAML

# The one actor that turns .changeset/ files and VERSION into a tag and a forge release (docs/release-checklist.md).
# Dispatch by hand on the branch to release. Runs on the Starfire runner in host mode, as the operator's Windows user,
# because the Unity Personal licence lives there. Every host prerequisite is checked by the first step, before any build or
# push (list: docs/release-checklist.md, One-time setup). Nothing is pushed until both players have built: a failed
# preflight or build leaves the forge untouched. After the push, a failed forge release has a recovery in the checklist.
name: release
on:
workflow_dispatch:
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: starfire
env:
UNITY_EDITOR: ${{ vars.UNITY_EDITOR }}
CULTLIB_ROOT: ${{ vars.CULTLIB_ROOT }}
CULTMATH_ROOT: ${{ vars.CULTMATH_ROOT }}
BUILD_NAME: release-${{ github.run_id }}
defaults:
run:
shell: '"C:/Program Files/Git/bin/bash.exe" -e {0}'
steps:
# The composite forgejo-release action runs its steps with `shell: bash`, resolved through PATH, where System32's WSL
# bash.exe can win. Git's bin goes first for every later step of this job.
- name: Put Git Bash first on PATH
run: printf '%s\n' 'C:\Program Files\Git\bin' >> "$GITHUB_PATH"
- name: Preflight host prerequisites
env:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
set -u
missing=""
first_bash="$(cmd.exe //c where bash 2>/dev/null | head -n 1 | tr -d '\r')"
case "${first_bash//$'\x5c'//}" in
"C:/Program Files/Git/"*) ;;
*) missing="$missing"$'\n'" PATH resolves bash to '$first_bash', not Git Bash (the forgejo-release action would run WSL bash)" ;;
esac
note() { missing="$missing"$'\n'" $1"; }
for tool in jq curl knope git tar dotnet; do
command -v "$tool" >/dev/null || note "$tool is not on PATH"
done
test -x /c/Windows/System32/tar.exe || note "C:/Windows/System32/tar.exe is missing"
test -n "$RELEASE_TOKEN" || note "secret RELEASE_TOKEN is not set"
test -f "$UNITY_EDITOR" || note "repo variable UNITY_EDITOR is unset or not a file: '$UNITY_EDITOR'"
test -d "$CULTLIB_ROOT" || note "repo variable CULTLIB_ROOT is unset or not a directory: '$CULTLIB_ROOT'"
test -d "$CULTMATH_ROOT" || note "repo variable CULTMATH_ROOT is unset or not a directory: '$CULTMATH_ROOT'"
if test -n "$missing"; then echo "release preflight failed, nothing was built or pushed:$missing"; exit 1; fi
- uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Prepare release
id: prepare
run: |
set -euo pipefail
knope prepare-release
version="$(tr -d '\r\n' < VERSION)"
if git rev-parse -q --verify "refs/tags/v$version" >/dev/null; then
echo "v$version already exists: no change file asked for a new version"; exit 1
fi
awk -v heading="## $version " 'index($0, heading) == 1 { found = 1; next } /^## / { if (found) exit } found' CHANGELOG.md > "$RUNNER_TEMP/notes.md"
test -s "$RUNNER_TEMP/notes.md" || { echo "CHANGELOG.md has no section for $version"; exit 1; }
git add VERSION CHANGELOG.md .changeset
git -c user.name="Aetheria release" -c user.email="release@gamecult.invalid" commit -m "Release $version"
git -c user.name="Aetheria release" -c user.email="release@gamecult.invalid" tag -a "v$version" -m "Aetheria $version"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "notes=$RUNNER_TEMP/notes.md" >> "$GITHUB_OUTPUT"
- name: Build and zip players
run: |
set -euo pipefail
version="${{ steps.prepare.outputs.version }}"
build="$(cd .. && pwd)/$BUILD_NAME"
mkdir -p "$build/dist"
project="$(pwd -W)"
for target in win64 linux64; do
name="Aetheria-$version-$target"
"$UNITY_EDITOR" -batchmode -quit -projectPath "$project" -executeMethod AetheriaBuild.Build \
-aetheriaVersion "$version" -aetheriaOut "$(cd "$build" && pwd -W)/$name" -aetheriaTarget "$target" \
-logFile "$(cd "$build" && pwd -W)/$target.log"
/c/Windows/System32/tar.exe -a -c -f "$build/dist/$name.zip" -C "$build" "$name"
size="$(stat -c %s "$build/dist/$name.zip")"
test "$size" -le 2147483648 || { echo "$name.zip is $size bytes: over the forge's 2048 MB attachment limit"; exit 1; }
done
- name: Publish tag and release commit
run: |
set -euo pipefail
git push --atomic origin "HEAD:refs/heads/${{ github.ref_name }}" "refs/tags/v${{ steps.prepare.outputs.version }}"
- name: Forge release
uses: actions/forgejo-release@v2.13.4
with:
direction: upload
tag: v${{ steps.prepare.outputs.version }}
sha: ${{ steps.prepare.outputs.sha }}
title: Aetheria ${{ steps.prepare.outputs.version }}
token: ${{ secrets.RELEASE_TOKEN }}
release-dir: ../${{ env.BUILD_NAME }}/dist
release-notes-file: ${{ steps.prepare.outputs.notes }}
- name: Show build logs on failure
if: failure()
run: tail -n 40 ../"$BUILD_NAME"/*.log || true
- name: Remove build directory
if: success()
run: rm -rf ../"$BUILD_NAME"