Files
source/.github/workflows/build.yml
T
1e2ce70315 Stamp the build's identity into GameVersion.cpp from CMake
GameVersion.cpp becomes a configure_file template, so the version strings are a
build input rather than something a CI step seds into the working tree mid-run.
That is what lets a crash report be matched to its exact build's PDB for offline
symbolization.

The two strings get distinct jobs. czVersionString is the machine-readable build
identity: the bare short commit SHA and nothing else. A `git describe` string
cannot serve here -- czVersionString is 16 bytes because it is stored in the
savegame header as SAVED_GAME_HEADER::zGameVersionNumber and strcmp'd on load,
and describe puts the SHA last, so truncation ate exactly the discriminating part
and could make two different commits compare equal. CI passes 9 hex; anything
that would not fit is now a configure error rather than a silent clip.

zBuildInformation is the display string, untruncated, and it is no longer printed
beside czVersionString: that drops the duplication in the version line ("JA2 1.13
V4-555-G6A941C0 2026-07-25 V4-555-G6A941C06") and stops showing a token that is
now machine-only. CI's copy leads with GAME_VERSION, because the version line is
now the only place a player reads which release they are running.

Finish what the sed step's TODO asked for: the workflow pins GAME_BUILD_INFORMATION
and GIT_SHA once, next to the gamedir SHAs it already pins, and hands them to CMake
with -D. Every parallel build job therefore stamps one agreed identity, and the
compile checkout needs no git history at all.

A build nobody identifies is a local build and says so -- czVersionString reads
"local" -- rather than deriving a SHA from HEAD. A derived SHA could not stay
true: nothing re-runs configure once HEAD moves, so an incremental build would
keep whatever it was configured with, and keeping it honest would mean
reconfiguring on every commit. It would also buy nothing, because only packaged
builds are archived with their PDBs; a local build's crash reports are symbolized
against the PDB sitting next to the exe.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-28 10:25:47 -03:00

200 lines
7.5 KiB
YAML

name: build
on:
pull_request:
# release.yml calls this workflow, which is how master, tags and manual runs
# build. Keeping the release jobs out of here keeps them off the pull request
# check list, where they would only ever show up as skipped.
workflow_call:
jobs:
workflow_setup:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v7
with:
path: source
filter: 'tree:0'
fetch-depth: 0
- name: Clone gamedir metadata
run: |
set -eux
GAMEDIR_REPOSITORY=1dot13/gamedir
GAMEDIR_LANGUAGES_REPOSITORY=1dot13/gamedir-languages
# filter tree is what makes this fast
git clone --config transfer.fsckobjects=false --no-checkout --filter=tree:0 \
https://github.com/$GAMEDIR_REPOSITORY \
gamedir
git clone --config transfer.fsckobjects=false --no-checkout --filter=tree:0 \
https://github.com/$GAMEDIR_LANGUAGES_REPOSITORY \
gamedir-languages
mkdir dist/
echo -n "
GAMEDIR_REPOSITORY=$GAMEDIR_REPOSITORY
GAMEDIR_LANGUAGES_REPOSITORY=$GAMEDIR_LANGUAGES_REPOSITORY
" > dist/versions.env
- name: Generate source version information
working-directory: source
run: |
set -eux
SOURCE_COMMIT_DATETIME=$(TZ=UTC0 git log -1 --date=iso-strict-local --format=%cd $GITHUB_SHA)
SOURCE_COMMIT_DATE=$(TZ=UTC0 git log -1 --date=short-local --format=%cd $GITHUB_SHA)
# GAME_VERSION is the release's name: it labels the dist archives and leads
# the in-game version line. Outdated save games are detected with GIT_SHA
# below, which is what czVersionString holds.
if [[ "$GITHUB_REF_TYPE" == 'tag' ]]
then
# if we build for a specific tag, use that as the game version
# examples:
# - v1.13.1
# - v1.13.2-rc2
GAME_VERSION="$GITHUB_REF_NAME"
else
# uses `git describe`, which tries to find a tag in the commit hierarchy. or fall back to a v1.13 version
# example five (5) commits after v1.13:
# - v1.13-5-7g7ffa
GAME_VERSION="$(git describe --tags --match='v[0-9]*' $GITHUB_SHA || echo v0-$(git rev-list --skip 1 --count $GITHUB_SHA)-g${GITHUB_SHA:0:8})"
fi
# keeps archive names bounded; nothing binary depends on this any more
GAME_VERSION="${GAME_VERSION:0:15}"
# the version line shown in game. It leads with GAME_VERSION because
# czVersionString is no longer displayed beside it: this is the only
# place a player can read which release they are running.
GAME_BUILD_INFORMATION="$GAME_VERSION $SOURCE_COMMIT_DATE GitHub $GITHUB_REPOSITORY"
# in case of a branch or if the tag is truncated
if [[ "$GAME_VERSION" != *"$GITHUB_REF_NAME"* ]]
then
GAME_BUILD_INFORMATION="$GAME_BUILD_INFORMATION $GITHUB_REF_TYPE $GITHUB_REF_NAME"
fi
# max 255 CHAR16
GAME_BUILD_INFORMATION="${GAME_BUILD_INFORMATION:0:255}"
# the machine-readable build identity stamped into czVersionString, which
# is both the savegame compatibility key and the crash-report key. Pinned
# here rather than derived per job, so the parallel builds cannot disagree,
# and left unsuffixed: this names a commit whose tree we really built.
# See Ja2/CMakeLists.txt for why it is 9 hex and nothing else.
GIT_SHA="${GITHUB_SHA:0:9}"
echo -n "
SOURCE_COMMIT_DATETIME=$SOURCE_COMMIT_DATETIME
GAME_VERSION=$GAME_VERSION
GAME_BUILD_INFORMATION=$GAME_BUILD_INFORMATION
GIT_SHA=$GIT_SHA
" >> ../dist/versions.env
# due to building everything in parallel, versions should be pinned at the start so everything builds based on the same versions
- name: Generate gamedir version information
working-directory: gamedir
run: |
set -eux
GAMEDIR_COMMIT_SHA=$(git rev-parse HEAD)
GAMEDIR_COMMIT_DATETIME=$(TZ=UTC0 git log -1 --date=iso-strict-local --format=%cd $GAMEDIR_COMMIT_SHA)
echo -n "
GAMEDIR_COMMIT_SHA=$GAMEDIR_COMMIT_SHA
GAMEDIR_COMMIT_DATETIME=$GAMEDIR_COMMIT_DATETIME
" >> ../dist/versions.env
# due to building everything in parallel, versions should be pinned at the start so everything builds based on the same versions
- name: Generate gamedir-languages version information
working-directory: gamedir-languages
run: |
set -eux
GAMEDIR_LANGUAGES_COMMIT_SHA=$(git rev-parse HEAD)
GAMEDIR_LANGUAGES_COMMIT_DATETIME=$(TZ=UTC0 git log -1 --date=iso-strict-local --format=%cd $GAMEDIR_LANGUAGES_COMMIT_SHA)
echo -n "
GAMEDIR_LANGUAGES_COMMIT_SHA=$GAMEDIR_LANGUAGES_COMMIT_SHA
GAMEDIR_LANGUAGES_COMMIT_DATETIME=$GAMEDIR_LANGUAGES_COMMIT_DATETIME
" >> ../dist/versions.env
- name: Show version information summary
run: |
set -eux
cat dist/versions.env
- name: Upload
uses: actions/upload-artifact@v7
with:
name: versions.env
path: dist/
# every executable contains all languages and picks one at runtime, so one build serves every package
compile:
needs: [ workflow_setup ]
runs-on: windows-latest # required for the MSVC toolchain
strategy:
fail-fast: false
matrix:
application: [ja2, ja2mapeditor, ja2ub, ja2ubmapeditor]
env:
# store the compiler cache in the GitHub Actions cache
SCCACHE_GHA_ENABLED: 'true'
steps:
- name: Checkout source
uses: actions/checkout@v7
- name: Download versions.env
uses: actions/download-artifact@v8
with:
name: versions.env
path: artifacts
- name: Restore versions.env
shell: bash
run: cat artifacts/versions.env >> $GITHUB_ENV
- name: Prepare build properties
shell: bash
run: |
set -eux
touch CMakePresets.json
JA2Application=$(echo '${{ matrix.application }}' | tr '[:lower:]' '[:upper:]')
echo "
JA2Application=$JA2Application
" >> $GITHUB_ENV
- uses: egor-tensin/vs-shell@v2
with:
arch: x86
- uses: mozilla-actions/sccache-action@v0.0.10
- name: Prepare build
run: |
# sccache can only cache MSVC objects when the debug information is embedded
# in them (/Z7) instead of collected in a shared PDB (/Zi, the CMake default)
#
# The build identity comes from versions.env, pinned once for the whole
# workflow. Handing it over is what makes this a packaged build rather
# than a local one; CMake never asks git who we are.
cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DApplications="$Env:JA2Application" -DGAME_BUILD_INFORMATION="$Env:GAME_BUILD_INFORMATION" -DGIT_SHA="$Env:GIT_SHA"
- name: Build
run: |
cmake --build build/ -- -v
- name: List build artifacts
shell: bash
run: |
find build/
sccache --show-stats
- name: Upload
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.application }}
path: build/*.exe