Files
minstrel/.gitea/workflows/release.yml
T
bvandeusenandClaude Opus 5.5 7ced019c77
release / web (push) Successful in 1m29s
release / go (push) Successful in 1m54s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 2m44s
release / android (push) Successful in 2m9s
release / Build signed APK (push) Successful in 2m1s
release / Build + push container image (push) Failing after 4s
ci: a merge to main is the public release; every dev push dry-runs it (#8358)
Every push now builds its image from the git archive export, after the
changelog and the leak gate have run on it, so a dev push is the public
release's dry run. A push to main then also commits and tags the export on
github.com/Fabled-Sword/minstrel as AmateurDungeoneer, publishes
ghcr.io/fabled-sword/minstrel :<name> and :latest, and creates the release
page on GitHub (public changelog) and on this forge (private changelog).

The scripts are Librarian's (ci/changelog.sh, ci/leakgate.sh,
ci/releases.mjs, with their tests), with Minstrel's false positives and a
changelog that ignores the forge-only v* tags from before the public
releases, so the first public release is the fixed note.

The tag build, its APK attach and its verify job, and the manual GHCR
dispatch are gone: phones get the app from the server image, and no
release carries a file. The push trigger has no path filter, because the
README, docs and tests ship in the public release too.

The README's image tags now name what GHCR carries: :latest and :<version>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 20:07:36 -05:00

919 lines
42 KiB
YAML

name: release
# Builds and pushes the minstrel container image to the Gitea registry, and on
# main also makes the public release.
#
# push to dev → :dev (freshly-built dev APK bundled), and the
# public release's dry run
# push to main → :latest + :<sha> (freshly-built stable APK bundled), then
# THE PUBLIC RELEASE: one commit and tag v<name> on
# github.com/Fabled-Sword/minstrel, the image
# ghcr.io/fabled-sword/minstrel :<name> + :latest, and a
# release page with its changelog on both forges
# workflow_dispatch → the same as a push to the dispatched branch, private
# half only; force_red checks the gate (see below)
#
# That is the whole tag map. The rest of this header is about the private
# registry; the public release is described at image-release.
#
# :<sha> on main is the ROLLBACK UNIT — every production commit addressable
# without a release ceremony. It is minted only on main, where rollback is
# actually worth having: merges to main are deliberate, so they number in the
# dozens per year, while on dev they would be one per push, forever, for a
# channel whose entire contract is that it moves.
#
# There are NO :<version> image tags. Git and the build's own self-reported
# version answer "which build is this"; a third name for the same thing is
# upkeep for a model we do not run. Only the APK needs version numbers, for
# its update process.
#
# There is no :main either. :latest tracks main's tip with no gate between
# them, so a second name for the same image sends readers looking for a
# distinction that does not exist.
#
# The dev channel exists so testing a build does not require shipping one:
# without it the only way to get an APK onto a phone is to cut a release,
# which makes `main` the staging area. `:dev` carries its own freshly-built
# APK, signed with the SAME key as release builds — a different key cannot
# install over the stable app, so anyone crossing channels would have to
# uninstall and lose their data.
#
# :dev is published ALONE, with no per-commit tag. A rolling channel is
# rolling by definition; a commit-addressable image for it would be a
# rollback target nobody ever pulls, kept forever. Recovery on dev is to fix
# forward.
#
# No cross-repo dispatch is needed to refresh a channel when its bundled APK
# is rebuilt: Minstrel is a monorepo, so one push builds the APK and the
# image in the same run from the same commit, and the channel cannot go
# stale against its own artifact.
#
# Every branch build carries the app built from its own commit, so a merge to
# main is all it takes to put a new app in front of stable phones: `:latest`
# serves it from /api/client/apk and the in-app update offers it. The app is
# never published on its own; it reaches phones only through the server.
#
# Release model: a merge to main IS the release. Its name is v<YYYY.MM.DD.HHMM>
# from the merge commit's UTC time, so every merge has its own. The run makes
# the tag on both forges; nobody tags by hand.
#
# TAGS ARE IMMUTABLE. Never move, retarget or delete a published tag. A re-run
# finds its tag already published: on the same tree it goes on, on another it
# stops. A failed public half is fixed on dev, and the next merge carries a new
# name.
#
# APK pipeline: on every push the android-release job builds + signs the
# Android APK and uploads it as a workflow artifact. The image-release job
# declares `needs: android-release` and requires its success, so the docker
# image cannot start building until the APK is guaranteed-ready — no polling,
# no race, no silent-failure mode, and no image that moves a channel without
# an app inside it.
#
# THE GATE. Every verifying lane lives in this file —
# Go (vet, lint, short tests), the Postgres integration suite, the web app
# (npm audit, svelte-check, vitest), Android (ktlint, detekt, unit tests) and
# govulncheck — and every job that publishes something names each of them in
# `needs:` and requires `success` from each, by name. Nothing publishes on red.
#
# One workflow, because separate workflows cannot see each other's verdict:
# :dev would mean "it built", never "it passed", and a red test run and a
# fresh :dev could carry the same timestamp. One graph is the only place the
# edge can be written.
#
# A skipped lane is NOT a pass. The publishing conditions check
# `result == 'success'` per lane rather than `!failure()`, so a lane that
# never started blocks the publish exactly as a red one does. Lanes carry no
# path filters for the same reason: a web-only push still runs the Go suite,
# because "not run" must never read as "passed".
#
# What publishes, and is therefore gated: everything image-release pushes, the
# private image tags and the whole public release. android-release only BUILDS
# the signed APK into a workflow artifact, which nobody outside this run can
# pull, so it runs in parallel with the lanes instead of after them.
#
# To watch the gate refuse: dispatch this workflow with force_red=true. The go
# lane fails on purpose, and the publishing job must report skipped.
# No path filter. The README, docs and tests ship in the public release too,
# so a merge to main that changes only them must still run, or it would not
# release.
on:
push:
branches: [main, dev]
workflow_dispatch:
inputs:
force_red:
description: Fail the go lane on purpose, to check that nothing publishes on red
type: boolean
default: false
# A rapid re-push to main supersedes the in-flight build: the later commit
# wins. The event name is in the group so a dispatch and a push on the same
# ref never cancel each other.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ---------------------------------------------------------------- lanes --
# Verifying jobs. Each one is named in the `needs:` of every publishing job
# below; add a lane here and it must be added there in the same commit.
go:
runs-on: go-ci
container:
image: git.fabledsword.com/bvandeusen/ci-go:1.26
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Forced failure (gate check)
if: github.event.inputs.force_red == 'true'
run: |
echo "::error::force_red dispatch: failing on purpose so the publishing jobs must skip"
exit 1
- name: Toolchain versions
run: |
go version
golangci-lint --version
- name: Generated code matches queries (sqlc)
run: make verify-generate
- name: go vet
run: go vet ./...
- name: golangci-lint
run: golangci-lint run ./...
# ci/testcount prints what plain go test would, plus how many tests
# ran. The step exits with go test's own status, kept aside in a file
# because the shell has no pipefail. The `|| rc=$?` matters: under
# `-e` a bare failing go test ends the group before its status is
# written, and a missing file fails the step as 1, never as a pass.
- name: go test (short, race)
run: |
go build -o /tmp/testcount ./ci/testcount
{ rc=0; go test -short -race -json ./... || rc=$?; echo "$rc" > /tmp/go-test-rc; } | /tmp/testcount
exit "$(cat /tmp/go-test-rc 2>/dev/null || echo 1)"
# Full `go test -race` against an ephemeral Postgres.
#
# DB wiring follows the act_runner shared-daemon pattern: the runner's Docker
# daemon also runs a dev compose stack, so service containers get NO
# published ports (collision) and no service-name DNS. We discover the
# service container through the mounted docker socket and reach it by bridge
# IP. The exactly-one assertion is a hard guard — pointing tests at the dev
# Postgres would truncate it.
#
# The key stays `integration` with no `name:`: act_runner derives the
# service container's name from the job's display name.
#
# `web/build/` has a committed placeholder index.html so go:embed succeeds
# without the SPA being built first.
integration:
runs-on: go-ci
container:
image: git.fabledsword.com/bvandeusen/ci-go:1.26
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: minstrel
POSTGRES_PASSWORD: minstrel
POSTGRES_DB: minstrel_test
# No `ports:` — the runner shares the dev compose
# Docker daemon; publishing a fixed host port collides.
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Integration suite (discover service by bridge IP, migrate, test)
run: |
set -eux
# Discover THIS job's Postgres service container via the
# mounted docker socket. act_runner attaches the job
# container and its service container(s) to a shared per-job
# network, so scope discovery to a postgres that sits on a
# network THIS job container is also on. A name filter alone
# would match EVERY concurrent integration run's postgres (a dev
# push and a main-merge run overlapping give 2 candidates and a
# false "expected exactly 1" abort). The dev compose
# `minstrel-postgres-*` is never on this job's network; skip it
# explicitly as belt-and-suspenders (a wrong target would
# truncate real data).
SELF=$(cat /etc/hostname)
SELF_NETS=$(docker inspect -f '{{range $k,$v := .NetworkSettings.Networks}}{{$k}} {{end}}' "$SELF")
test -n "$SELF_NETS"
echo "self ($SELF) networks: $SELF_NETS"
PG_ID=""
PG_NAME=""
for cid in $(docker ps --filter "ancestor=postgres:16-alpine" -q); do
nm=$(docker inspect -f '{{.Name}}' "$cid" | sed 's#^/##')
case "$nm" in *minstrel-postgres*|*_postgres_*) continue ;; esac
for net in $(docker inspect -f '{{range $k,$v := .NetworkSettings.Networks}}{{$k}} {{end}}' "$cid"); do
case " $SELF_NETS " in *" $net "*) PG_ID="$cid"; PG_NAME="$nm"; break 2 ;; esac
done
done
test -n "$PG_ID" || { echo "FATAL: no postgres service container on this job's network (self nets: $SELF_NETS)"; exit 1; }
echo "selected postgres: $PG_ID $PG_NAME"
PG_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$PG_ID")
test -n "$PG_IP"
export MINSTREL_TEST_DATABASE_URL="postgres://minstrel:minstrel@${PG_IP}:5432/minstrel_test?sslmode=disable"
# Wait for Postgres to accept connections. Asked of the service
# container itself: the run: shell is dash, where a `/dev/tcp`
# probe never connects and the loop would silently burn its full
# two minutes.
#
# Over TCP (-h 127.0.0.1), not the unix socket. On first
# boot the image's entrypoint runs initdb under a temporary server
# that listens on the socket only, then stops it and starts the
# real one. A socket probe can catch the temporary server, and the
# next step then meets "the database system is shutting down".
# Only the real server listens on TCP.
ready=""
for i in $(seq 1 60); do
if docker exec "$PG_ID" pg_isready -h 127.0.0.1 -U minstrel -d minstrel_test -q; then ready=1; break; fi
sleep 2
done
test -n "$ready" || { echo "FATAL: postgres never became ready"; exit 1; }
# Relax durability on the throwaway CI Postgres. Our test pattern
# is dbtest.ResetDB → TRUNCATE … RESTART IDENTITY CASCADE before
# every test, and the per-TRUNCATE commit fsync is the dominant
# cost of the integration suite. The CI DB is rebuilt every run so
# fsync / full_page_writes / synchronous_commit buy nothing. Apply
# via docker exec because:
# - The act_runner `services:` block can't override the container
# command, so `postgres -c fsync=off` at boot isn't an option.
# - ALTER SYSTEM cannot run inside a transaction; psql -c
# auto-commits each statement, which is what we need.
# - fsync / full_page_writes are sighup GUCs and
# synchronous_commit is user-context, so pg_reload_conf() picks
# all three up with no restart.
# Non-fatal: a failure degrades to "slower", never red CI. But
# slower is ~15x on internal/api, so retry a few times and
# print what took effect.
relaxed=""
for i in 1 2 3 4 5; do
if docker exec -e PGPASSWORD=minstrel "$PG_ID" psql -h 127.0.0.1 -U minstrel -d minstrel_test \
-c "ALTER SYSTEM SET fsync = off" \
-c "ALTER SYSTEM SET synchronous_commit = off" \
-c "ALTER SYSTEM SET full_page_writes = off" \
-c "SELECT pg_reload_conf()"; then relaxed=1; break; fi
sleep 2
done
if [ -n "$relaxed" ]; then
docker exec -e PGPASSWORD=minstrel "$PG_ID" psql -h 127.0.0.1 -U minstrel -d minstrel_test -At \
-c "SELECT 'durability: ' || string_agg(name || '=' || setting, ' ' ORDER BY name) FROM pg_settings WHERE name IN ('fsync','synchronous_commit','full_page_writes')" \
|| true
else
echo "::warning::durability relax failed after 5 tries; the suite will run several times slower"
fi
# Apply embedded migrations to the fresh test DB, then run the
# packages that hold database tests (no -short, so they execute).
# The `go` lane already runs every unit test; packages with no
# database test are left to it (ci/db-test-packages.sh).
#
# -p 1: every database package TRUNCATEs the one shared test DB,
# and concurrent package binaries deadlock on TRUNCATE. -p also
# bounds compiling, so the test binaries are built first with
# full parallelism (-run '^$' runs no test), and the serial pass
# reuses the build cache.
#
# -timeout 20m: internal/api alone takes minutes under -race on a
# busy runner, and a dev and a main run sharing the runner can
# push it past go test's default 10m with nothing hung.
MINSTREL_DATABASE_URL="$MINSTREL_TEST_DATABASE_URL" go run ./cmd/minstrel migrate
PKGS=$(sh ci/db-test-packages.sh)
echo "database test packages: $(echo "$PKGS" | wc -l)"
go test -race -run '^$' $PKGS
# ci/testcount prints the usual go test output plus how many tests
# ran; the step exits with go test's own status (no pipefail, and
# `|| rc=$?` so -e cannot end the group before the status is kept).
go build -o /tmp/testcount ./ci/testcount
{ rc=0; go test -p 1 -race -timeout 20m -json $PKGS || rc=$?; echo "$rc" > /tmp/go-test-rc; } | /tmp/testcount
exit "$(cat /tmp/go-test-rc 2>/dev/null || echo 1)"
web:
runs-on: go-ci
container:
image: git.fabledsword.com/bvandeusen/ci-go:1.26
defaults:
run:
working-directory: web
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install deps
run: npm ci
# The whole tree, build and test tooling included: the tooling that
# builds the shipped bundle is held to the same bar as the bundle.
- name: npm audit (all dependencies)
run: npm audit --audit-level=moderate
- name: Type-check + svelte-check
run: npm run check
- name: Vitest
run: npm test
android:
# The flutter-ci runner label is the only proven-working label with
# docker that can pull our container.image.
runs-on: flutter-ci
container:
image: git.fabledsword.com/bvandeusen/ci-android:36
defaults:
run:
working-directory: android
env:
# Silences the JDK 22+ "restricted method in java.lang.System has been
# called" warning that Gradle's bundled native-platform jar trips at
# launch. Affects the LAUNCHER JVM, not the daemon — that's why
# org.gradle.jvmargs in gradle.properties isn't enough.
JAVA_TOOL_OPTIONS: "--enable-native-access=ALL-UNNAMED"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache Gradle dirs
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
~/.kotlin
key: gradle-${{ runner.os }}-${{ hashFiles('android/gradle/wrapper/gradle-wrapper.properties', 'android/gradle/libs.versions.toml', 'android/**/*.gradle.kts') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Gradle wrapper validation
run: ./gradlew --version
- name: ktlint
run: ./gradlew ktlintCheck
- name: detekt
run: ./gradlew detekt
- name: Unit tests
run: ./gradlew testDebugUnitTest
# How many tests ran, summed from Gradle's JUnit reports. Runs after a
# failure too, so a red run still says how much of the suite it reached.
- name: Test count
if: always()
run: |
set -- app/build/test-results/testDebugUnitTest/*.xml
if [ ! -e "$1" ]; then echo "no unit test reports"; exit 0; fi
awk '/<testsuite / {
for (i = 1; i <= NF; i++)
if (match($i, /^(tests|skipped|failures|errors)="[0-9]+"/)) {
split($i, kv, "\"")
n[substr($i, 1, index($i, "=") - 1)] += kv[2]
}
}
END {
printf "tests: %d passed, %d failed, %d skipped\n",
n["tests"] - n["failures"] - n["errors"] - n["skipped"], n["failures"] + n["errors"], n["skipped"]
}' "$@"
# No debug APK is built or uploaded here: a debug build is signed by a
# key regenerated in every container, which no install can update.
# Phones get builds from android-release, signed with the one release
# key, on dev and on tags.
# Known vulnerabilities in the Go code and the standard library it is built
# with. Runs in the SAME image the Dockerfile's builder stage uses, so the
# standard library it checks is the one that ends up in the shipped binary;
# the ci-go image carries its own Go and would be checking a different
# toolchain. Keep this image and the Dockerfile's builder in step.
#
# govulncheck is fetched at CI time, unpinned: the vulnerability
# database and the tool that reads it should both be current.
govulncheck:
runs-on: go-ci
container:
image: golang:1.26-bookworm
steps:
# Plain git, not actions/checkout: that action runs on node, which the
# golang image does not carry. This step is dash.
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
set -eu
auth=$(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)
git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git -c http.extraHeader="Authorization: Basic ${auth}" fetch -q --depth 1 origin "${{ github.sha }}"
git checkout -q FETCH_HEAD
git log -1 --format='%H %s'
- name: govulncheck
run: |
go version
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
# ------------------------------------------------------------ artifacts --
android-release:
name: Build signed APK
# Builds on both branches, so each channel's image carries the app from
# its own commit: `dev` for the test channel, `main` for stable phones.
if: >-
github.ref == 'refs/heads/dev'
|| github.ref == 'refs/heads/main'
runs-on: flutter-ci
container:
image: git.fabledsword.com/bvandeusen/ci-android:36
defaults:
run:
working-directory: android
env:
JAVA_TOOL_OPTIONS: "--enable-native-access=ALL-UNNAMED"
# PKCS12 keystores collapse store + key password into a single
# value; both env vars map to one secret. build.gradle reads them
# separately to stay format-agnostic.
ANDROID_STORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
# Job outputs propagate the computed release version to image-release
# so the bundled sidecar file matches what's baked into the APK —
# otherwise the server would report a different version string than
# the installed client and the update banner could thrash.
outputs:
version_name: ${{ steps.ver.outputs.name }}
version_code: ${{ steps.ver.outputs.code }}
channel: ${{ steps.ver.outputs.channel }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Full history. The version name reads only the tip commit's
# timestamp, so a shallow clone would technically serve — but this
# job derives a value that ships to devices, and a shallow checkout
# changes what git-derived values resolve to WITHOUT failing. The
# whole failure class here is a green build carrying a wrong
# version, so the cheap guarantee is worth keeping.
fetch-depth: 0
- name: Compute release version
id: ver
shell: bash
working-directory: ${{ github.workspace }}
run: |
set -euo pipefail
# The derivation lives in ci/version.sh, not here, so it can be
# executed by a test on every push. Anything inline in this file is
# unverifiable until a release is already running.
out="$(ci/version.sh --apk HEAD)"
printf '%s\n' "${out}" >> "$GITHUB_OUTPUT"
# The channel is a property of the LANE, not of the commit, which is
# why it is derived here rather than in version.sh. Same commit built
# on dev and on main reports the same NAME and differs only here —
# that is the whole point of separating the two values.
if [ "${GITHUB_REF}" = "refs/heads/dev" ]; then
channel=dev
else
channel=stable
fi
echo "channel=${channel}" >> "$GITHUB_OUTPUT"
echo "::notice::APK $(printf '%s' "${out}" | tr '\n' ' ') channel=${channel}"
- name: Cache Gradle dirs
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
~/.kotlin
key: gradle-${{ runner.os }}-${{ hashFiles('android/gradle/wrapper/gradle-wrapper.properties', 'android/gradle/libs.versions.toml', 'android/**/*.gradle.kts') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Decode signing keystore
env:
ANDROID_KEYSTORE_B64: ${{ secrets.ANDROID_KEYSTORE_B64 }}
shell: bash
run: |
if [ -z "${ANDROID_KEYSTORE_B64}" ]; then
echo "::error::ANDROID_KEYSTORE_B64 missing"; exit 1
fi
KEYSTORE_PATH="${RUNNER_TEMP}/minstrel-release.keystore"
echo "${ANDROID_KEYSTORE_B64}" | base64 -d > "${KEYSTORE_PATH}"
echo "ANDROID_KEYSTORE_PATH=${KEYSTORE_PATH}" >> "${GITHUB_ENV}"
- name: Build release APK
run: |
./gradlew assembleRelease \
-PMINSTREL_VERSION_NAME=${{ steps.ver.outputs.name }} \
-PMINSTREL_VERSION_CODE=${{ steps.ver.outputs.code }}
# The APK every phone updates from must carry THE release key: Android
# updates an app in place only when the signer matches, so an APK
# signed by any other key (debug, a regenerated keystore, a swapped
# secret) reaches no installed phone. The certificate's digest is
# pinned below; it is public, not a secret. Gradle signs with the
# release key or leaves the APK unsigned, and an unsigned build fails
# here too, as there is no app-release.apk to verify. apksigner, not
# keytool: keytool prints nothing for a v2-only APK.
#
# Rotating the key on purpose means every install must be removed and
# reinstalled; change the digest here in the same commit.
- name: The APK carries the release key
shell: bash
env:
# CN=Minstrel, O=FabledSword.
RELEASE_CERT_SHA256: 43d183307bc46b821789d90444a960b137f78f2166ff431efb2406d0fceaf612
run: |
set -euo pipefail
sdk="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-}}"
signer="$(ls "$sdk"/build-tools/*/apksigner 2>/dev/null | sort -V | tail -1 || true)"
test -n "$signer" || { echo "::error::no apksigner under '$sdk/build-tools'"; exit 1; }
certs="$("$signer" verify --print-certs app/build/outputs/apk/release/app-release.apk)"
printf '%s\n' "$certs" | grep -E '^Signer #[0-9]+ certificate (DN|SHA-256 digest)'
# One signer, and it is ours. A second signer would be a lineage or
# a mistake; either way not something to ship unexamined.
digests="$(printf '%s\n' "$certs" | sed -n 's/^Signer #[0-9]* certificate SHA-256 digest: //p')"
if [ "$digests" != "$RELEASE_CERT_SHA256" ]; then
if printf '%s' "$certs" | grep -q 'CN=Android Debug'; then
echo "::error::the release APK is signed with a debug key"
else
echo "::error::the release APK is not signed by the release key: got '${digests//$'\n'/ }', want ${RELEASE_CERT_SHA256}"
fi
exit 1
fi
- name: Upload APK as workflow artifact
# Stock action — never @v3, which uploads something Gitea will never
# serve back. This is the producing half of a pair: image-release
# downloads `minstrel-apk` below. Any upload v4+ pairs with any
# download v4+ on this forge, so the two pins need not move together.
uses: actions/upload-artifact@v7
with:
name: minstrel-apk
path: android/app/build/outputs/apk/release/app-release.apk
# error, not the default warn: image-release hard-depends on this
# artifact existing, so an empty upload must fail here, not there.
if-no-files-found: error
# The image, and on main the public release.
#
# Every push builds its image FROM THE EXPORT, `git archive` of this commit,
# and runs the changelog and the leak gate on it first. So a dev push is the
# public release's dry run: an export that leaks or does not build is red the
# day it lands, not at the merge.
#
# A push to main is also the PUBLIC release, after the private push:
# 1. the export becomes one commit on github.com/Fabled-Sword/minstrel's
# main, tagged v<name>, authored by AmateurDungeoneer and dated in UTC;
# 2. that tree is built into ghcr.io/fabled-sword/minstrel :<name> and
# :latest, labelled with the public repository and commit;
# 3. a GitHub Release with the public changelog, and a release on this forge
# with the private one, both v<name>, both naming the image.
# <name> is YYYY.MM.DD.HHMM from the merge commit's time.
image-release:
name: Build + push container image
# Every lane must have SUCCEEDED, each named here, and so must the APK
# build: every ref bundles the APK built from its own commit, so an
# image without one would move a channel with no app for phones to take.
needs: [go, integration, web, android, govulncheck, android-release]
if: >-
${{
!cancelled()
&& needs.go.result == 'success'
&& needs.integration.result == 'success'
&& needs.web.result == 'success'
&& needs.android.result == 'success'
&& needs.govulncheck.result == 'success'
&& needs.android-release.result == 'success' }}
runs-on: go-ci
container:
image: git.fabledsword.com/bvandeusen/ci-go:1.26
env:
IMAGE: git.fabledsword.com/bvandeusen/minstrel
PUBLIC_REPO: Fabled-Sword/minstrel
PUBLIC_IMAGE: ghcr.io/fabled-sword/minstrel
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Full history and its tags: any job that DERIVES the version name
# needs it, because a shallow clone changes what git-derived values
# resolve to WITHOUT failing — a too-low value, silently, with every
# lane green. The changelog lists the commits since the previous
# release's tag, so it needs them too.
fetch-depth: 0
- name: Compute image tags
id: tags
shell: bash
run: |
set -euo pipefail
# THE VERSION, and it is derived the same way on every ref — the
# branch decides the CHANNEL, never the version.
#
# A per-ref string ("main", "dev") would not order, and "dev" would be
# the same string forever — two dev images eight weeks apart
# indistinguishable in the UI. The server's self-reported version is
# how an admin tells which build a private image is.
#
# `sed -n s///p` rather than `grep`: it exits 0 when nothing matches,
# so the empty check below is actually reachable. A grep here would
# kill the step at the assignment under the runner's pipefail.
VERSION="$(ci/version.sh HEAD | sed -n 's/^name=//p')"
if [ -z "${VERSION}" ]; then
echo "::error::could not derive a build version from ci/version.sh"
exit 1
fi
if [[ "${GITHUB_REF}" == "refs/heads/dev" ]]; then
# The rolling test channel, and :dev ALONE — deliberately no
# per-commit tag. A rolling channel is rolling by definition, so a
# commit-addressable image here would be a rollback target nobody
# has ever pulled, accumulating in the registry forever. Recovery
# on dev is to fix forward.
CHANNEL=dev
echo "args=-t ${IMAGE}:dev" >> "$GITHUB_OUTPUT"
echo "::notice::Dev-branch build ${VERSION}: :dev"
else
# The production line: :latest tracks main's tip and :<sha> is
# the rollback unit. Full 40-char SHA, so a rollback target is
# addressable straight from the commit anyone is reading.
CHANNEL=stable
echo "args=-t ${IMAGE}:latest -t ${IMAGE}:${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
echo "::notice::Main-branch build ${VERSION}: :latest + :${GITHUB_SHA}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "channel=${CHANNEL}" >> "$GITHUB_OUTPUT"
# The public release's name, and whether this run makes the release.
# Only a PUSH to main does: a dispatch on main rebuilds the private
# channel and publishes nothing outside this forge.
{
echo "EXPORT=${RUNNER_TEMP}/export"
echo "NAME=$(date -u -d "@$(git log -1 --format=%ct HEAD)" +%Y.%m.%d.%H%M)"
if [ "${GITHUB_EVENT_NAME}" = "push" ] && [ "${GITHUB_REF}" = "refs/heads/main" ]; then
echo "PUBLIC=true"
else
echo "PUBLIC=false"
fi
} >> "$GITHUB_ENV"
# What a release would publish: the export, and its changelog. Neither
# may carry a banned word or a private record id (ci/leakgate.sh), and the
# export carries no CI file.
- name: Export, changelog and leak gate
shell: bash
run: |
set -euo pipefail
rm -rf "${EXPORT}"
mkdir -p "${EXPORT}"
git archive HEAD | tar -x -C "${EXPORT}"
for private in .gitea .forgejo .github ci ci-requirements.md .gitattributes renovate.json; do
if [ -e "${EXPORT}/${private}" ]; then
echo "::error::the export carries ${private}; .gitattributes export-ignore no longer covers it"
exit 1
fi
done
bash ci/changelog.sh "${RUNNER_TEMP}/changelog"
echo "--- the public changelog of v${NAME} ---"
cat "${RUNNER_TEMP}/changelog/public.md"
echo "---"
bash ci/leakgate.sh "${EXPORT}" "${RUNNER_TEMP}/changelog/public.md"
# The secrets the public half needs, checked before anything is pushed
# anywhere. A dev push warns about one that is missing or refused; a main
# push stops. Nothing here writes: the push token reads the public
# repository, and the forge token updates a release that does not exist.
- name: Public release secrets
shell: bash
env:
PUBLIC_PUSH_TOKEN: ${{ secrets.PUBLIC_PUSH_TOKEN }}
GHCR_USER: ${{ vars.GHCR_USER || secrets.GHCR_USER }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
FORGE_TOKEN: ${{ secrets.CI_TOKEN }}
run: |
set -u
bad=""
say() { bad="yes"; if [ "${PUBLIC}" = "true" ]; then echo "::error::$1"; else echo "::warning::$1"; fi; }
[ -n "${GHCR_USER}" ] || say "GHCR_USER is empty or unset (an Actions variable or secret)"
[ -n "${GHCR_TOKEN}" ] || say "the GHCR_TOKEN secret is empty or unset"
if [ -z "${PUBLIC_PUSH_TOKEN}" ]; then
say "the PUBLIC_PUSH_TOKEN secret is empty or unset"
else
auth="$(printf 'x-access-token:%s' "${PUBLIC_PUSH_TOKEN}" | base64 -w0)"
echo "::add-mask::${auth}"
git -c http.https://github.com/.extraheader="AUTHORIZATION: basic ${auth}" \
ls-remote "https://github.com/${PUBLIC_REPO}.git" >/dev/null \
|| say "PUBLIC_PUSH_TOKEN cannot read github.com/${PUBLIC_REPO}"
fi
node ci/releases.mjs forge-probe || say "CI_TOKEN may not write this repository's releases"
if [ -n "${bad}" ] && [ "${PUBLIC}" = "true" ]; then exit 1; fi
exit 0
- name: Registry login
shell: bash
run: |
echo "${{ secrets.CI_TOKEN }}" \
| docker login git.fabledsword.com -u "${{ github.actor }}" --password-stdin
- name: Download signed APK artifact
# android-release just produced this, on every ref.
# Consuming half of the pair: stock download-artifact, which works here for
# the same reason as the upload (gitea/runner 3.x edits the GHES refusal
# out of the bundle). v8 runs on node24, which every CI-runner image
# carries — the runner uses the image's own node.
uses: actions/download-artifact@v8
with:
name: minstrel-apk
path: client/
# Into the export, which is what the image is built from.
- name: Stage bundled APK + version sidecar
shell: bash
env:
# All three pulled from android-release's outputs so the sidecar the
# server hands clients matches exactly what is baked into the APK
# they are comparing against.
APK_VERSION_NAME: ${{ needs.android-release.outputs.version_name }}
APK_VERSION_CODE: ${{ needs.android-release.outputs.version_code }}
APK_CHANNEL: ${{ needs.android-release.outputs.channel }}
run: |
set -euxo pipefail
# The artifact lands as `app-release.apk` (the original Gradle
# output name). The Dockerfile COPYs client/* into /app/client/
# and the server reads minstrel.apk + minstrel.apk.version.
mv client/app-release.apk "${EXPORT}/client/minstrel.apk"
printf '{"name":"%s","code":%s,"channel":"%s"}\n' \
"${APK_VERSION_NAME}" "${APK_VERSION_CODE}" "${APK_CHANNEL}" \
> "${EXPORT}/client/minstrel.apk.version"
cat "${EXPORT}/client/minstrel.apk.version"
ls -lh "${EXPORT}/client/"
- name: Build and push
shell: bash
# --pull: the Dockerfile's base images are floating tags (golang:1.26,
# debian:bookworm-slim). Without it the runner's daemon reuses
# whatever it cached, and the shipped binary can sit on a Go patch
# release govulncheck already flagged while the lane, which pulls
# fresh, reports clean.
run: |
docker buildx build --pull \
--build-arg MINSTREL_VERSION="${{ steps.tags.outputs.version }}" \
--build-arg MINSTREL_CHANNEL="${{ steps.tags.outputs.channel }}" \
--push ${{ steps.tags.outputs.args }} "${EXPORT}"
# THE PUBLIC RELEASE, a push to main only. The export becomes one commit
# on the public repository's main, replacing its whole tree so removed
# files go too, tagged v<name>. Author, committer and tagger are the
# project's public identity, dated at this commit's time in UTC.
#
# A re-run finds v<name> already there: on the same tree it goes on to the
# image and the releases, on a different tree it stops. A published tag
# is never moved.
- name: Public commit and tag
if: env.PUBLIC == 'true'
shell: bash
env:
PUBLIC_PUSH_TOKEN: ${{ secrets.PUBLIC_PUSH_TOKEN }}
run: |
set -euo pipefail
auth="$(printf 'x-access-token:%s' "${PUBLIC_PUSH_TOKEN}" | base64 -w0)"
echo "::add-mask::${auth}"
pub="${RUNNER_TEMP}/public"
rm -rf "${pub}"
git init -q -b main "${pub}"
cd "${pub}"
git config http.https://github.com/.extraheader "AUTHORIZATION: basic ${auth}"
git remote add origin "https://github.com/${PUBLIC_REPO}.git"
# An empty repository has no main yet, and its first release starts it.
if [ -n "$(git ls-remote --heads origin main)" ]; then
git fetch -q --depth 1 origin main
git checkout -q -B main FETCH_HEAD
fi
find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
# A fresh archive, not the build context, which also holds the app.
git -C "${GITHUB_WORKSPACE}" archive HEAD | tar -xf -
# -f: the export exactly, a tracked file a .gitignore matches
# (the generated token CSS) included.
git add -A -f
tree="$(git write-tree)"
when="@$(git -C "${GITHUB_WORKSPACE}" log -1 --format=%ct HEAD) +0000"
if [ -n "$(git ls-remote --tags origin "refs/tags/v${NAME}")" ]; then
git fetch -q --depth 1 origin "refs/tags/v${NAME}:refs/tags/v${NAME}"
if [ "$(git rev-parse "v${NAME}^{tree}")" != "${tree}" ]; then
echo "::error::the public tag v${NAME} holds another tree; a published tag is never moved"
exit 1
fi
echo "::notice::v${NAME} is already published with this tree"
else
export GIT_AUTHOR_NAME=AmateurDungeoneer GIT_AUTHOR_EMAIL=amateurdungeoneer@fabledsword.com
export GIT_COMMITTER_NAME=AmateurDungeoneer GIT_COMMITTER_EMAIL=amateurdungeoneer@fabledsword.com
export GIT_AUTHOR_DATE="${when}" GIT_COMMITTER_DATE="${when}"
git commit -q -m "Release ${NAME}"
git tag -a "v${NAME}" -m "Release ${NAME}"
git push -q origin main "refs/tags/v${NAME}"
fi
echo "REVISION=$(git rev-parse "v${NAME}^{commit}")" >> "$GITHUB_ENV"
# The same export, built again with the release's name and labels that
# point at the public repository and commit, so nothing in the image
# points back here. Every layer but the stamped binary comes from the
# build above. --provenance=false and no SBOM: an attestation would carry
# this workbench's build details into a public registry.
- name: Public image
if: env.PUBLIC == 'true'
shell: bash
env:
GHCR_USER: ${{ vars.GHCR_USER || secrets.GHCR_USER }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
run: |
set -euo pipefail
docker build --provenance=false \
--build-arg MINSTREL_VERSION="${NAME}" \
--build-arg MINSTREL_CHANNEL=stable \
--label "org.opencontainers.image.source=https://github.com/${PUBLIC_REPO}" \
--label "org.opencontainers.image.revision=${REVISION}" \
--label "org.opencontainers.image.version=${NAME}" \
-t "${PUBLIC_IMAGE}:${NAME}" "${EXPORT}"
labelled="$(docker inspect --format '{{ index .Config.Labels "org.opencontainers.image.revision" }}' "${PUBLIC_IMAGE}:${NAME}")"
test "${labelled}" = "${REVISION}" || { echo "::error::the image names commit ${labelled}, not ${REVISION}"; exit 1; }
printf '%s' "${GHCR_TOKEN}" | docker login ghcr.io -u "${GHCR_USER}" --password-stdin
# :<name> is never re-pushed, so a re-run only moves :latest.
if docker manifest inspect "${PUBLIC_IMAGE}:${NAME}" >/dev/null 2>&1; then
echo "::notice::${PUBLIC_IMAGE}:${NAME} is already published; only :latest moves"
else
docker push "${PUBLIC_IMAGE}:${NAME}"
fi
docker tag "${PUBLIC_IMAGE}:${NAME}" "${PUBLIC_IMAGE}:latest"
docker push "${PUBLIC_IMAGE}:latest"
echo "DIGEST=$(docker inspect --format '{{ index .RepoDigests 0 }}' "${PUBLIC_IMAGE}:${NAME}")" >> "$GITHUB_ENV"
# The release pages, each created or updated in place: GitHub's with the
# public changelog, this forge's with the private one, tagging this
# commit. Both name the image. No files are attached: the app ships
# inside the image.
- name: Public and private releases
if: env.PUBLIC == 'true'
shell: bash
env:
PUBLIC_PUSH_TOKEN: ${{ secrets.PUBLIC_PUSH_TOKEN }}
FORGE_TOKEN: ${{ secrets.CI_TOKEN }}
run: |
set -euo pipefail
cl="${RUNNER_TEMP}/changelog"
for side in public private; do
{
cat "${cl}/${side}.md"
printf '\nImage: `%s:%s`\n' "${PUBLIC_IMAGE}" "${NAME}"
} > "${cl}/${side}-body.md"
done
echo "GITHUB_RELEASE=$(node ci/releases.mjs github "v${NAME}" "${cl}/public-body.md")" >> "$GITHUB_ENV"
echo "FORGE_RELEASE=$(node ci/releases.mjs forge "v${NAME}" "${cl}/private-body.md" "${GITHUB_SHA}")" >> "$GITHUB_ENV"
# The record the release task keeps.
- name: Published
shell: bash
run: |
echo "pushed ${{ steps.tags.outputs.args }}"
if [ "${PUBLIC}" = "true" ]; then
echo "release v${NAME} of workbench ${GITHUB_SHA}"
echo "public commit ${REVISION}"
echo "image ${DIGEST}"
echo "GitHub release ${GITHUB_RELEASE}"
echo "forge release ${FORGE_RELEASE}"
else
echo "dry run of release v${NAME}: export, changelog and leak gate passed, image built from the export"
fi