373 lines
14 KiB
YAML
373 lines
14 KiB
YAML
# Magic Civilization — release pipeline on tag push.
|
|
#
|
|
# Implements objective p2-06 (`.project/objectives/p2-06-export-pipeline.md`):
|
|
# pushing a `v*` tag builds Linux/macOS/Windows game archives plus the WASM
|
|
# guide bundle and publishes them as Forgejo release assets on the tag's
|
|
# release page.
|
|
#
|
|
# Runner prerequisites (see `.forgejo/RUNNER_SETUP.md`):
|
|
# - linux_build → self-hosted apricot (labels: linux, apricot, gdext) — EXISTS
|
|
# - wasm_build → self-hosted apricot (same labels) — EXISTS
|
|
# - macos_build → self-hosted mac (labels: macos, arm64) — TODO
|
|
# - windows_build→ self-hosted win (labels: windows, x86_64) — TODO
|
|
#
|
|
# The macOS + Windows jobs are authored completely; they will simply sit
|
|
# queued on Forgejo until a runner with the matching labels registers.
|
|
|
|
name: release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
|
|
# A tag push is one release — do not allow a second invocation to race.
|
|
concurrency:
|
|
group: release-${{ github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
RUST_BACKTRACE: 1
|
|
|
|
jobs:
|
|
# ──────────────────────────────────────────────────────────────────
|
|
# LINUX
|
|
# Builds the GDExtension .so, runs the Godot export, and archives
|
|
# the Linux binary + addons directory into a tar.gz.
|
|
# ──────────────────────────────────────────────────────────────────
|
|
linux_build:
|
|
name: linux build
|
|
runs-on: [self-hosted, linux, apricot]
|
|
timeout-minutes: 30
|
|
outputs:
|
|
archive: ${{ steps.package.outputs.archive }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # full history so CHANGELOG range-since-prior-tag works
|
|
|
|
- name: Resolve version
|
|
id: version
|
|
run: |
|
|
set -euo pipefail
|
|
version="${GITHUB_REF_NAME#v}"
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
echo "Building version $version from tag $GITHUB_REF_NAME"
|
|
|
|
- name: Build GDExtension (.so)
|
|
working-directory: src/simulator
|
|
run: bash build-gdext.sh
|
|
|
|
- name: Godot export — linux
|
|
run: |
|
|
set -euo pipefail
|
|
bash tools/export-single.sh linux "${{ steps.version.outputs.version }}"
|
|
|
|
- name: Package linux archive
|
|
id: package
|
|
run: |
|
|
set -euo pipefail
|
|
version="${{ steps.version.outputs.version }}"
|
|
build_dir=".local/build/godot/$version/linux"
|
|
archive_name="magic-civilization-$version-linux.tar.gz"
|
|
archive_path=".local/build/godot/$version/$archive_name"
|
|
# Bundle the exported binary alongside the compiled GDExtension.
|
|
tar -C "$build_dir" -czf "$archive_path" .
|
|
echo "archive=$archive_path" >> "$GITHUB_OUTPUT"
|
|
ls -lh "$archive_path"
|
|
|
|
- name: Upload linux artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: linux-${{ steps.version.outputs.version }}
|
|
path: ${{ steps.package.outputs.archive }}
|
|
retention-days: 14
|
|
|
|
# ──────────────────────────────────────────────────────────────────
|
|
# MACOS
|
|
# TODO(prerequisite): no macos,arm64 runner is registered yet. See
|
|
# .forgejo/RUNNER_SETUP.md § "macOS runner" for the expected labels and
|
|
# the `rustup target add aarch64-apple-darwin` / Godot editor install
|
|
# prerequisites. Until a runner registers, this job queues indefinitely.
|
|
# ──────────────────────────────────────────────────────────────────
|
|
macos_build:
|
|
name: macos build
|
|
runs-on: [self-hosted, macos, arm64]
|
|
timeout-minutes: 45
|
|
outputs:
|
|
archive: ${{ steps.package.outputs.archive }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Resolve version
|
|
id: version
|
|
run: |
|
|
set -euo pipefail
|
|
version="${GITHUB_REF_NAME#v}"
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build GDExtension (.dylib)
|
|
working-directory: src/simulator
|
|
# build-gdext.sh detects $(uname -s) and outputs .dylib on Darwin.
|
|
run: bash build-gdext.sh
|
|
|
|
- name: Godot export — macos
|
|
run: |
|
|
set -euo pipefail
|
|
bash tools/export-single.sh macos "${{ steps.version.outputs.version }}"
|
|
|
|
- name: Package macos archive
|
|
id: package
|
|
run: |
|
|
set -euo pipefail
|
|
version="${{ steps.version.outputs.version }}"
|
|
build_dir=".local/build/godot/$version/macos"
|
|
archive_name="magic-civilization-$version-macos.zip"
|
|
archive_path=".local/build/godot/$version/$archive_name"
|
|
# Godot's macOS export emits a .zip containing the .app bundle;
|
|
# we wrap that together with the .dylib + any loose metadata.
|
|
(cd "$build_dir" && zip -r "../$archive_name" .)
|
|
echo "archive=$archive_path" >> "$GITHUB_OUTPUT"
|
|
ls -lh "$archive_path"
|
|
|
|
- name: Upload macos artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: macos-${{ steps.version.outputs.version }}
|
|
path: ${{ steps.package.outputs.archive }}
|
|
retention-days: 14
|
|
|
|
# ──────────────────────────────────────────────────────────────────
|
|
# WINDOWS
|
|
# TODO(prerequisite): no windows,x86_64 runner is registered yet. See
|
|
# .forgejo/RUNNER_SETUP.md § "Windows runner" for the expected labels
|
|
# and the `rustup target add x86_64-pc-windows-msvc` / Godot editor
|
|
# install prerequisites.
|
|
# ──────────────────────────────────────────────────────────────────
|
|
windows_build:
|
|
name: windows build
|
|
runs-on: [self-hosted, windows, x86_64]
|
|
timeout-minutes: 45
|
|
outputs:
|
|
archive: ${{ steps.package.outputs.archive }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Resolve version
|
|
id: version
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
version="${GITHUB_REF_NAME#v}"
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build GDExtension (.dll)
|
|
working-directory: src/simulator
|
|
shell: bash
|
|
run: bash build-gdext.sh
|
|
|
|
- name: Godot export — windows
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
bash tools/export-single.sh windows "${{ steps.version.outputs.version }}"
|
|
|
|
- name: Package windows archive
|
|
id: package
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
version="${{ steps.version.outputs.version }}"
|
|
build_dir=".local/build/godot/$version/windows"
|
|
archive_name="magic-civilization-$version-windows.zip"
|
|
archive_path=".local/build/godot/$version/$archive_name"
|
|
(cd "$build_dir" && 7z a "../$archive_name" .)
|
|
echo "archive=$archive_path" >> "$GITHUB_OUTPUT"
|
|
ls -lh "$archive_path"
|
|
|
|
- name: Upload windows artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: windows-${{ steps.version.outputs.version }}
|
|
path: ${{ steps.package.outputs.archive }}
|
|
retention-days: 14
|
|
|
|
# ──────────────────────────────────────────────────────────────────
|
|
# WASM guide
|
|
# Builds the wasm-pack output plus the built guide bundle and ships
|
|
# them together as a single tarball.
|
|
# ──────────────────────────────────────────────────────────────────
|
|
wasm_build:
|
|
name: wasm guide build
|
|
runs-on: [self-hosted, linux, apricot]
|
|
timeout-minutes: 25
|
|
outputs:
|
|
archive: ${{ steps.package.outputs.archive }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Resolve version
|
|
id: version
|
|
run: |
|
|
set -euo pipefail
|
|
version="${GITHUB_REF_NAME#v}"
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build WASM (wasm-pack)
|
|
working-directory: src/simulator
|
|
run: bash build-wasm.sh
|
|
|
|
- name: Build guide
|
|
working-directory: public/games/age-of-dwarves/guide
|
|
run: |
|
|
set -euo pipefail
|
|
pnpm install --frozen-lockfile
|
|
pnpm build
|
|
|
|
- name: Package wasm archive
|
|
id: package
|
|
run: |
|
|
set -euo pipefail
|
|
version="${{ steps.version.outputs.version }}"
|
|
out_dir=".local/build/wasm/$version"
|
|
archive_name="magic-civilization-$version-wasm.tar.gz"
|
|
archive_path="$out_dir/$archive_name"
|
|
mkdir -p "$out_dir/staging/pkg" "$out_dir/staging/guide"
|
|
cp -r .local/build/wasm/. "$out_dir/staging/pkg/"
|
|
cp -r public/games/age-of-dwarves/guide/dist/. "$out_dir/staging/guide/"
|
|
tar -C "$out_dir/staging" -czf "$archive_path" .
|
|
rm -rf "$out_dir/staging"
|
|
echo "archive=$archive_path" >> "$GITHUB_OUTPUT"
|
|
ls -lh "$archive_path"
|
|
|
|
- name: Upload wasm artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: wasm-${{ steps.version.outputs.version }}
|
|
path: ${{ steps.package.outputs.archive }}
|
|
retention-days: 14
|
|
|
|
# ──────────────────────────────────────────────────────────────────
|
|
# RELEASE
|
|
# Downloads all build artifacts and creates a Forgejo release on the
|
|
# tag, attaching each archive as a release asset. Notes are derived
|
|
# from .project/CHANGELOG.md entries since the prior tag.
|
|
# ──────────────────────────────────────────────────────────────────
|
|
release:
|
|
name: publish forgejo release
|
|
needs: [linux_build, macos_build, windows_build, wasm_build]
|
|
runs-on: [self-hosted, linux, apricot]
|
|
timeout-minutes: 15
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Resolve version
|
|
id: version
|
|
run: |
|
|
set -euo pipefail
|
|
version="${GITHUB_REF_NAME#v}"
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
echo "tag=$GITHUB_REF_NAME" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Download all build artifacts
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
path: .local/release-staging
|
|
|
|
- name: Generate release notes
|
|
id: notes
|
|
run: |
|
|
set -euo pipefail
|
|
notes_file=".local/release-staging/RELEASE_NOTES.md"
|
|
mkdir -p "$(dirname "$notes_file")"
|
|
bash tools/release-notes.sh "$GITHUB_REF_NAME" > "$notes_file"
|
|
echo "notes_file=$notes_file" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Collect release assets
|
|
id: assets
|
|
run: |
|
|
set -euo pipefail
|
|
staging=".local/release-staging"
|
|
assets_dir=".local/release-assets"
|
|
mkdir -p "$assets_dir"
|
|
# actions/download-artifact v3 puts each artifact in a subdir
|
|
# named after the artifact (e.g. linux-1.2.3/foo.tar.gz).
|
|
find "$staging" -type f \( -name '*.tar.gz' -o -name '*.zip' \) \
|
|
-exec cp {} "$assets_dir/" \;
|
|
echo "Staged release assets:"
|
|
ls -lh "$assets_dir"
|
|
|
|
- name: Create Forgejo release
|
|
env:
|
|
# Supplied by the runner environment / org secrets — see RUNNER_SETUP.md.
|
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_RELEASE_TOKEN }}
|
|
FORGEJO_HOST: http://10.0.0.11:3000
|
|
FORGEJO_REPO: magicciv/magicciv
|
|
run: |
|
|
set -euo pipefail
|
|
tag="${{ steps.version.outputs.tag }}"
|
|
version="${{ steps.version.outputs.version }}"
|
|
notes_file="${{ steps.notes.outputs.notes_file }}"
|
|
|
|
if [ -z "${FORGEJO_TOKEN:-}" ]; then
|
|
echo "::error::FORGEJO_RELEASE_TOKEN secret is not set; see RUNNER_SETUP.md"
|
|
exit 1
|
|
fi
|
|
|
|
# Create the release (idempotent-ish: if it exists, capture the ID via GET).
|
|
create_payload="$(jq -n \
|
|
--arg tag "$tag" \
|
|
--arg name "Magic Civilization $version" \
|
|
--rawfile body "$notes_file" \
|
|
'{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')"
|
|
|
|
release_json="$(curl -sS -X POST \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$create_payload" \
|
|
"${FORGEJO_HOST}/api/v1/repos/${FORGEJO_REPO}/releases" || true)"
|
|
|
|
release_id="$(echo "$release_json" | jq -r '.id // empty')"
|
|
if [ -z "$release_id" ]; then
|
|
# Release already exists — fetch its id.
|
|
release_id="$(curl -sS \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
"${FORGEJO_HOST}/api/v1/repos/${FORGEJO_REPO}/releases/tags/${tag}" \
|
|
| jq -r '.id')"
|
|
fi
|
|
|
|
if [ -z "$release_id" ] || [ "$release_id" = "null" ]; then
|
|
echo "::error::Failed to create or locate release for tag ${tag}"
|
|
echo "API response: $release_json"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Release id: $release_id"
|
|
|
|
# Upload each asset.
|
|
for asset in .local/release-assets/*; do
|
|
[ -f "$asset" ] || continue
|
|
name="$(basename "$asset")"
|
|
echo "Uploading $name ..."
|
|
curl -sS -X POST \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-F "attachment=@${asset}" \
|
|
"${FORGEJO_HOST}/api/v1/repos/${FORGEJO_REPO}/releases/${release_id}/assets?name=${name}" \
|
|
> /dev/null
|
|
done
|
|
|
|
echo "Release ${tag} published with $(ls .local/release-assets | wc -l) assets."
|