11 Commits
Author SHA1 Message Date
Claude ad30ab9dea Move CI to Gitea: run-number offset, Cloudflare-only publishing
- plgVersionRunOffset=1000: stamped build number is run number + offset, so
  Gitea's restarted run counter cannot produce a versionCode below an
  installed one (GitHub reached prod 30, dev ~172). Tags and versionName use
  the same number.
- Drop the GitHub release steps; plg.wallacenet.ca is the only channel.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdMNbY5hLR7FjtfEE712xG
2026-10-14 17:00:01 +00:00
Claude 4c603f6d3d Adopt the GitHub lineage; supersede Gitea-only bootstrap commits
Keeps Gitea's history reachable (also preserved as gitea-pre-github-main)
while the tree stays the GitHub one: package org.prolibertate.games, OTA
from plg.wallacenet.ca. Gitea's package rename and Gitea-releases updater
are intentionally not carried over.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdMNbY5hLR7FjtfEE712xG
2026-10-14 16:59:38 +00:00
adrianoftyriel 0927660c15 Merge pull request #43 from adrianoftyriel/dev
Dev
2026-10-14 10:42:42 -06:00
adrianoftyriel 5d0f95361f Merge pull request #42 from adrianoftyriel/cf-real-404
Fix Pages carry-over: real 404 and tolerate 200-with-HTML
2026-10-14 10:18:01 -06:00
Claude 6fbe63f787 Fix carry-over on Pages: add 404.html and tolerate 200-with-HTML
Pages serves index.html with 200 for unknown paths when there is no
404.html, so a never-published channel looked published and jq failed on
the HTML. Add a real 404 page and treat a 200 without a latest.json as
absent.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdMNbY5hLR7FjtfEE712xG
2026-10-14 16:08:28 +00:00
adrianoftyriel 12d20565bd Merge pull request #41 from adrianoftyriel/cf-treat-1014-as-absent
Treat Cloudflare 1014 as 'channel not published yet'
2026-10-14 10:02:26 -06:00
Claude 2df140a3c1 Treat Cloudflare error 1014 as 'channel not published yet'
A push-triggered first deploy cannot set the first_deploy input, and the
domain answers 403/1014 until the Pages project exists. 1014 means nothing
exists to preserve, so handle it like a 404. Other 403s still abort.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdMNbY5hLR7FjtfEE712xG
2026-10-14 15:53:15 +00:00
adrianoftyriel 0b74b1b2b1 Merge pull request #40 from adrianoftyriel/cf-first-deploy-fix
Fix first Cloudflare deploy: add first_deploy dispatch input
2026-10-14 09:39:58 -06:00
Claude 4369d15cec Add first_deploy dispatch input so the first Cloudflare deploy can bootstrap
The domain answers 403 (error 1014) until the Pages project exists, which
made the carry-over fetch abort the very deploy that would create it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdMNbY5hLR7FjtfEE712xG
2026-10-14 15:39:03 +00:00
adrianoftyriel 1e9908569d Merge pull request #39 from adrianoftyriel/cloudflare-pages-deploy
Publish dev and prod builds to plg.wallacenet.ca (Cloudflare Pages)
2026-10-14 09:32:31 -06:00
Claude c0fc4fe7d6 Publish dev and prod builds to plg.wallacenet.ca (Cloudflare Pages)
Both workflows gain a deploy-pages job that stages their channel into one
Pages site, carrying the other channel over from the live site. The in-app
updater now reads /prod|/dev/latest.json from plg.wallacenet.ca instead of
the GitHub API. GitHub releases are still published for one transition
deployment so existing installs can fetch the new updater.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdMNbY5hLR7FjtfEE712xG
2026-10-14 15:20:47 +00:00
20 changed files with 562 additions and 780 deletions
+66
View File
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
# Assembles the Cloudflare Pages site for plg.wallacenet.ca into ./pages-out.
#
# Usage: stage-pages-site.sh <prod|dev> <tag> <apk-path>
#
# A Pages deploy replaces the whole site, and both channels live in one site,
# so this stages the channel being published and then re-fetches the *other*
# channel's current files from the live site so the deploy does not erase them.
set -euo pipefail
channel="$1"; tag="$2"; apk="$3"
base="${PAGES_BASE_URL:-https://plg.wallacenet.ca}"
out="pages-out"
limit=$((25 * 1024 * 1024)) # Cloudflare Pages: 25 MiB per file
case "$channel" in prod) other=dev ;; dev) other=prod ;; *) echo "bad channel: $channel" >&2; exit 2 ;; esac
rm -rf "$out"
mkdir -p "$out/$channel" "$out/$other"
cp site/index.html site/404.html site/_headers "$out/"
name="$(basename "$apk")"
cp "$apk" "$out/$channel/$name"
cp "$apk" "$out/$channel/ProLibertateGames.apk"
jq -n --arg tag "$tag" --arg name "$name" --arg ch "$channel" --arg url "$base/$channel/$name" \
'{tag: $tag, apkName: $name, apkUrl: $url, channel: $ch}' > "$out/$channel/latest.json"
# PLG_SKIP_OTHER=1 is for the very first deploy, when the site does not exist
# yet and the domain answers 403 (Cloudflare error 1014) instead of 404.
if [ -n "${PLG_SKIP_OTHER:-}" ]; then
echo "PLG_SKIP_OTHER set; not carrying over $other."
rm -rf "$out/$other"
find "$out" -type f | sort
exit 0
fi
# Carry the other channel over. 404 means it was never published; any other
# failure must stop the deploy rather than silently dropping that channel.
code="$(curl -sS -o "$out/$other/latest.json" -w '%{http_code}' "$base/$other/latest.json" || true)"
: "${code:=000}"
# Cloudflare error 1014 (403 + "error code: 1014") means the domain's CNAME
# points at a Pages project that does not exist yet, so there is nothing to
# preserve — the same as a 404, and what a push-triggered first deploy sees.
if [ "$code" = 403 ] && grep -q 'error code: 1014' "$out/$other/latest.json" 2>/dev/null; then
code=404
fi
if [ "$code" = 404 ]; then
echo "No $other channel published yet; skipping."
rm -rf "$out/$other"
elif [ "$code" = 200 ] && ! jq -e .apkName "$out/$other/latest.json" >/dev/null 2>&1; then
# A 200 that is not our JSON: Pages without a 404.html answers unknown paths
# with index.html. Nothing is published on that channel.
echo "No $other channel published yet (200 but no latest.json); skipping."
rm -rf "$out/$other"
elif [ "$code" = 200 ]; then
other_name="$(jq -er .apkName "$out/$other/latest.json")"
curl -fsS -o "$out/$other/$other_name" "$base/$other/$other_name"
cp "$out/$other/$other_name" "$out/$other/ProLibertateGames.apk"
else
echo "Fetching $other/latest.json returned HTTP $code; refusing to deploy." >&2
exit 1
fi
find "$out" -name '*.apk' -size +"${limit}c" -print | grep . >&2 && {
echo "APK exceeds Cloudflare Pages' 25 MiB per-file limit." >&2; exit 1; } || true
find "$out" -type f | sort
+75 -34
View File
@@ -1,27 +1,28 @@
name: CI
# Pre-merge checks. Runs on the dev branch and on every pull request aimed at
# dev or main, so breakage is caught before it reaches main.
# dev or main, so breakage is caught before it reaches main and triggers a
# release.
#
# On a push to dev it also publishes the build as a dev-channel prerelease on
# this Gitea instance, so the in-app updater can offer it to anyone on the dev
# channel. Prereleases are used deliberately: the "latest release" endpoint
# skips them, so a production-channel user never sees a dev build. Pull
# requests only build and check — they never publish, which keeps a PR from a
# fork from shipping anything.
#
# These files live in .github/workflows/ on purpose: Gitea Actions reads that
# path as well as .gitea/workflows/, so one file serves both. Publishing goes
# through Gitea's REST API (the same routes the app's updater reads) rather
# than the `gh` CLI, which a runner image need not carry.
# On a push to dev it also publishes the build as a dev-channel prerelease, so
# the in-app updater can offer it to anyone who has switched to that channel.
# Prereleases are used deliberately: GitHub's "latest release" endpoint skips
# them, so a production-channel user never sees a dev build. Pull requests only
# build and check — they never publish, which keeps a PR from a fork from
# shipping anything.
on:
push:
branches: [ dev ]
pull_request:
branches: [ main, dev ]
workflow_dispatch:
inputs:
first_deploy:
description: "First Cloudflare deploy: skip carrying over the other channel (the site does not exist yet)"
type: boolean
default: false
# Needed by the job token to create the release and attach the APK.
# Needed to publish the dev-channel prerelease below.
permissions:
contents: write
@@ -34,6 +35,8 @@ jobs:
build:
name: Build and check
runs-on: ubuntu-latest
outputs:
version: ${{ steps.stage.outputs.version }}
env:
# Stamp the APK as a dev-channel build exactly when it is a build of the
# dev branch, which is exactly when it can be published below. Pull
@@ -41,7 +44,10 @@ jobs:
# <series>.0-dev: they are never published and must not claim a channel
# version.
#
# This condition has to stay in step with the publish steps' own.
# This condition has to stay in step with the publish steps' own. Stamping
# a build the publish steps would ship, or shipping one this left
# unstamped, both end the same way — an APK claiming versionCode 1, which
# the updater can never see as an upgrade over anything.
PLG_CHANNEL: ${{ github.ref == 'refs/heads/dev' && 'dev' || '' }}
steps:
- name: Checkout
@@ -89,39 +95,74 @@ jobs:
# branch itself, after it has built, tested and linted clean above.
#
# Gated on the branch alone rather than on the event, which is how
# release.yml gates main. A pull request is still excluded without
# needing to name it: a PR build runs against refs/pull/N/merge, never
# refs/heads/dev, so a fork still cannot ship anything.
# release.yml has always gated main. A pull request is still excluded
# without needing to name it: a PR build runs against refs/pull/N/merge,
# never refs/heads/dev, so a fork still cannot ship anything.
- name: Stage dev APK
id: stage
if: github.ref == 'refs/heads/dev'
run: |
set -euo pipefail
# The series and the offset come from gradle.properties, which is
# the same file the build read when it stamped the APK — so the tag
# and what is inside it cannot name different versions. The number
# is run number + offset, exactly the arithmetic build.gradle.kts
# did for versionCode.
# The series comes from gradle.properties, which is the same file the
# build read when it stamped the APK — so the tag and what is inside
# it cannot name different versions.
series="$(sed -n 's/^plgVersionSeries=//p' gradle.properties)"
offset="$(sed -n 's/^plgVersionRunOffset=//p' gradle.properties)"
test -n "$series"
offset="$(sed -n 's/^plgVersionRunOffset=//p' gradle.properties)"
test -n "$offset"
stamp="$(( ${{ github.run_number }} + offset ))"
version="v${series}.${stamp}-dev"
# Same arithmetic as build.gradle.kts, so the tag names the APK's own number.
version="v${series}.$(( ${{ github.run_number }} + offset ))-dev"
src="app/build/outputs/apk/debug/app-debug.apk"
dest="ProLibertateGames-${version}.apk"
cp "$src" "$dest"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "apk=$dest" >> "$GITHUB_OUTPUT"
- name: Publish dev channel prerelease
- name: Upload staged dev APK for the Pages deploy
if: github.ref == 'refs/heads/dev'
uses: actions/upload-artifact@v4
with:
name: plg-dev-staged
path: ${{ steps.stage.outputs.apk }}
if-no-files-found: error
retention-days: 1
# Publishes the build to https://plg.wallacenet.ca (Cloudflare Pages), which is
# the only release channel: the in-app updater reads latest.json from there.
#
# Both workflows deploy into one Pages site, and a deploy replaces the whole
# site, so they share a concurrency group and never run at the same time.
deploy-pages:
name: Deploy to Cloudflare Pages
needs: build
if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
concurrency:
group: plg-pages-deploy
cancel-in-progress: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download staged APK
uses: actions/download-artifact@v4
with:
name: plg-dev-staged
path: staged
- name: Assemble site
env:
# The job's built-in token: contents: write is declared above.
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
RELEASE_TAG: ${{ steps.stage.outputs.version }}
RELEASE_APK: ${{ steps.stage.outputs.apk }}
RELEASE_KIND: prerelease
RELEASE_TARGET: ${{ github.sha }}
# One script, also runnable by hand — see docs/CI.md.
run: ./scripts/publish-release.sh
PLG_SKIP_OTHER: ${{ inputs.first_deploy && '1' || '' }}
run: .github/scripts/stage-pages-site.sh dev "${{ needs.build.outputs.version }}" "staged/ProLibertateGames-${{ needs.build.outputs.version }}.apk"
- name: Deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
set -euo pipefail
# Creates the project on first run; fails harmlessly if it exists.
npx --yes wrangler@3 pages project create plg --production-branch main || true
# --branch main makes this the production deployment, which is what
# plg.wallacenet.ca serves, whichever branch the workflow ran on.
npx --yes wrangler@3 pages deploy pages-out --project-name plg --branch main --commit-dirty=true
+67 -31
View File
@@ -1,17 +1,18 @@
name: Build and Release APK
# Production-channel build. Runs on a push to main, or by hand
# (workflow_dispatch), and publishes to this Gitea instance's releases — which
# is the channel the in-app updater reads. See docs/CI.md.
#
# Publishing goes through Gitea's REST API rather than the `gh` CLI, which a
# runner image need not carry.
# Build an APK and publish it as a GitHub Release whenever commits land on main
# (for example when a pull request is merged). Can also be run manually.
on:
push:
branches: [ main ]
workflow_dispatch:
inputs:
first_deploy:
description: "First Cloudflare deploy: skip carrying over the other channel (the site does not exist yet)"
type: boolean
default: false
# Needed by the job token to create the release and attach the APK.
# Allow the built-in token to create releases and upload the APK.
permissions:
contents: write
@@ -23,13 +24,16 @@ concurrency:
jobs:
build:
name: Build APK and publish release
# workflow_dispatch can be aimed at any branch from the Actions UI. The
# production stamp belongs to main alone — anything else is a no-op rather
# than shipping unreviewed code to everybody.
# workflow_dispatch can be aimed at any branch from the Actions UI. Releases
# are what the in-app updater installs, so only main may produce one —
# anything else is a no-op rather than shipping unreviewed code to everyone.
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.stage.outputs.version }}
env:
# Stamps the APK as a production-channel build.
# Stamps the APK as a production-channel build, versioned with the run
# number that matches the tag published below.
PLG_CHANNEL: production
steps:
- name: Checkout
@@ -45,44 +49,76 @@ jobs:
- name: Set up Android SDK
uses: android-actions/setup-android@v4
- name: Build production APK
- name: Build debug APK
run: ./gradlew assembleDebug --no-daemon --stacktrace
- name: Stage APK
- name: Stage APK for release
id: stage
run: |
set -euo pipefail
# The series and the offset come from gradle.properties, which is
# the same file the build read when it stamped the APK — so the tag
# and what is inside it cannot name different versions. The number
# is run number + offset, exactly the arithmetic build.gradle.kts
# did for versionCode.
# The series comes from gradle.properties, which is the same file the
# build read when it stamped the APK — so the tag and what is inside
# it cannot name different versions.
series="$(sed -n 's/^plgVersionSeries=//p' gradle.properties)"
offset="$(sed -n 's/^plgVersionRunOffset=//p' gradle.properties)"
test -n "$series"
offset="$(sed -n 's/^plgVersionRunOffset=//p' gradle.properties)"
test -n "$offset"
stamp="$(( ${{ github.run_number }} + offset ))"
version="v${series}.${stamp}"
# Same arithmetic as build.gradle.kts, so the tag names the APK's own number.
version="v${series}.$(( ${{ github.run_number }} + offset ))"
src="app/build/outputs/apk/debug/app-debug.apk"
dest="ProLibertateGames-${version}.apk"
cp "$src" "$dest"
# The same build again under a name that never changes. GitHub's
# /releases/latest/download/<name> redirect needs a constant file
# name, so this second copy is what makes a permanent download link
# possible — the versioned copy stays as the traceable one.
cp "$src" "ProLibertateGames.apk"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "apk=$dest" >> "$GITHUB_OUTPUT"
- name: Upload APK as workflow artifact
uses: actions/upload-artifact@v4
with:
name: ProLibertateGames-apk
name: plg-prod-staged
path: ${{ steps.stage.outputs.apk }}
if-no-files-found: error
- name: Publish production release
# Publishes the build to https://plg.wallacenet.ca (Cloudflare Pages), which is
# the only release channel: the in-app updater reads latest.json from there.
#
# Both workflows deploy into one Pages site, and a deploy replaces the whole
# site, so they share a concurrency group and never run at the same time.
deploy-pages:
name: Deploy to Cloudflare Pages
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
concurrency:
group: plg-pages-deploy
cancel-in-progress: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download staged APK
uses: actions/download-artifact@v4
with:
name: plg-prod-staged
path: staged
- name: Assemble site
env:
# The job's built-in token: contents: write is declared above.
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
RELEASE_TAG: ${{ steps.stage.outputs.version }}
RELEASE_APK: ${{ steps.stage.outputs.apk }}
RELEASE_KIND: release
RELEASE_TARGET: ${{ github.sha }}
# One script, also runnable by hand — see docs/CI.md.
run: ./scripts/publish-release.sh
PLG_SKIP_OTHER: ${{ inputs.first_deploy && '1' || '' }}
run: .github/scripts/stage-pages-site.sh prod "${{ needs.build.outputs.version }}" "staged/ProLibertateGames-${{ needs.build.outputs.version }}.apk"
- name: Deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
set -euo pipefail
# Creates the project on first run; fails harmlessly if it exists.
npx --yes wrangler@3 pages project create plg --production-branch main || true
# --branch main makes this the production deployment, which is what
# plg.wallacenet.ca serves, whichever branch the workflow ran on.
npx --yes wrangler@3 pages deploy pages-out --project-name plg --branch main --commit-dirty=true
+101 -76
View File
@@ -1,95 +1,120 @@
# Working on this repo (agent notes)
> **Moved to Gitea.** CI now runs on Gitea Actions at
> `git.wallacenet.ca/devadmin/ProLibertateGames`, publishing to Cloudflare Pages
> (`plg.wallacenet.ca`) only. The sandbox notes below describe the earlier GitHub
> setup (no CI run from session pushes, `workflow_dispatch` as the workaround);
> re-verify them against Gitea before relying on them.
ProLibertateGames — Wallacenet's build of an Android collection of card and
board games, playable against AI or over Wi-Fi (LAN). Upstream:
[adrianoftyriel/ProLibertateGames](https://github.com/adrianoftyriel/ProLibertateGames)
(GPL-3.0, kept as the `upstream` remote). Canonical repo:
<https://git.wallacenet.ca/devadmin/ProLibertateGames>.
# Working on this repo with Claude
## Ground rules
## Nothing a session does triggers CI. Dispatch it explicitly.
- **Licences travel.** `LICENSE` is GPL-3.0 and must stay. The Uncial Antiqua
font ships with its OFL licence at `docs/licenses/UncialAntiqua-OFL.txt`;
never delete or edit either. Attribution to the upstream lives in the README.
- **No Catan trademarks or brand assets** — the one hard line. The app's own
branding is the upstream's, restored (see README → Branding): tartan launcher
icon and splash, Wallace clan red on production and hunting green on dev,
launcher names *Pro Libertate Games* / *Pro Libertate Games DEV*. The
installed identity is `ca.wallacenet.prolibertategames` (+ `.dev`).
- **The existing catalogue is the regression safety net.** Keep every game
green; new games (Katan) arrive as separate tasks, not edits to old ones.
The 22 reference games are `available = true`; Katan is listed with
`available = false` (*Coming soon*) until its game task lands.
- **Docs conventions**: every game gets `docs/RULES-<id>.md` (index and gaps in
`docs/README.md`); build/CI/release decisions go in `docs/CI.md`. Update the
docs when behaviour changes — they are the check against the rules code.
GitHub creates **no workflow run** for anything this sandbox does — pushing a
branch, opening a pull request, or merging one. All of it goes through the same
integration, and GitHub suppresses event-triggered runs from it. The pull
request will say it was opened by the repo owner; that is only how the UI
attributes it, and it does not change the suppression.
## Build
This was measured, not assumed:
```sh
export JAVA_HOME=... # JDK 17
export ANDROID_HOME=... # SDK with platform 34, build-tools 34
./gradlew assembleDebug # dev-channel APK (default)
PLG_CHANNEL=production ./gradlew assembleDebug # production APK
./gradlew testDebugUnitTest # JVM unit tests (rules/AI/net/score)
./gradlew lintDebug # Android lint (CI runs it)
```
| Action | Result |
| --- | --- |
| Human pushes a Claude-authored commit (`d165e5ef`, `469c900e`) | CI runs |
| Session pushes `dev` / `main` (`43394b8`, `742add4`) | no run |
| Session opens a PR against `dev` (#1) | no run |
| Session calls `workflow_dispatch` | **runs** |
On the Wallacenet project workspace a ready toolchain sits at
`../.toolchain/` (`jdk17/`, `android-sdk/`) — export `JAVA_HOME` and
`ANDROID_HOME` to it rather than installing again. Both variants must build:
they install side by side (different applicationId, launcher name, colour).
`workflow_dispatch` works because it creates a run directly instead of relying
on an event. It is the only mechanism available from a session, so every build
has to be asked for by hand.
## Channels and OTA
## Verify before merging, without publishing
One flag — `isDevBuild` in `app/build.gradle.kts` — drives applicationId,
launcher name and brand colour together. Never set them individually.
`ci.yml` builds, tests and lints on any ref, but its staging and publishing
steps are gated on `github.ref == 'refs/heads/dev'`. Dispatching it on a
**feature branch** therefore gives the full check — build, unit tests, Android
lint — and publishes nothing.
In-app OTA points at this repo's own Gitea releases
(`/api/v1/repos/devadmin/ProLibertateGames/releases…`) and is **on**:
`BuildConfig.OTA_ENABLED` is `true`. The channel is a decision already made and
recorded — `docs/CI.md` documents the endpoints, the build-number scheme, and
what publishing requires. Setting the flag to `false` is the kill switch.
So the working loop is:
## CI
1. Commit and push the feature branch.
2. Dispatch `ci.yml` on that branch. Wait for green. This is the real review
gate, and it is the only verification that exists (see below).
3. Open the PR through the API and merge it there, so the change is reviewable
and the merge commit is honest about what happened. Neither step builds
anything.
4. Dispatch the target branch's workflow to actually build and publish:
`ci.yml` on `dev`, `release.yml` on `main`.
`.github/workflows/` — Actions-compatible so the Gitea instance runs them.
`ci.yml`: build + test + lint + artifact, and a dev prerelease from `dev`.
`release.yml`: production release from `main`. Both publish through
`scripts/publish-release.sh` (Gitea REST API), which is also runnable by hand.
Skipping step 4 leaves a branch whose head was never built and no release.
**No Actions runner is registered on the instance yet**, so the workflows are
idle until one is — the local gradle commands above are the source of truth,
and CI green means those plus lint. Do not treat a workflow that has never run
as evidence.
## Merging is a shipping action
## Code map
Both long-lived branches publish, so a merge is a release, not just an
integration:
- `game/` — rules engines and AI, **pure Kotlin, no Android types**, unit
tested. `Catalog.kt` is the registry (id, title, blurb, options, `available`).
- `net/` — wire protocol, LAN transport (mDNS + TCP), lobby, host-authoritative
match driver; `score/` the scorekeeper sheet, also pure.
- `ui/` — Compose screens; `ui/theme/Theme.kt` holds the brand palette
(`BrandField`/`BrandDeep`/`BrandAccent`) and table accents.
- `update/` — OTA policy (`UpdatePolicy.kt`, pure and tested) and the gated
fetch (`Updater.kt`).
- `settings/` — DataStore preferences.
- **`dev`** → `ci.yml` publishes a `v<series>.N-dev` **prerelease**, offered by the
in-app updater to anyone on the Dev channel.
- **`main`** → `release.yml` publishes a **production** release, which the
updater installs for everyone on the Production channel.
Host is authoritative over the wire; clients send intents, host re-validates
against the rules. Keep `game/` free of Android imports — the JVM tests depend
on it.
Confirm before shipping to `main`. Note that `release.yml` runs `assembleDebug`
only — no tests, no lint — so a `main` release is only as verified as the `dev`
build it replays.
## Git
## Gradle does not run in the sandbox
- Branches: `main` (production), `dev` (integration). Feature branches → PR
into `dev`.
- Commits by Paperclip agents end with
`Co-Authored-By: Paperclip <[email protected]>`.
- Pull upstream fixes with `git pull upstream` (the GitHub source); do not
point `origin` anywhere but this repo's Gitea URL.
`./gradlew` cannot resolve the Android plugin here: the proxy blocks
`dl.google.com` with a 403. No local build, no local test run, no local lint. A
dispatched CI run is the only way to find out whether a change compiles.
## Legacy files
## A permanent fix, if you want one
`.claude/` and `.rtk/` are the upstream author's assistant tooling, harmless
and left as inherited. This file supersedes the upstream's CLAUDE.md (which
documented their GitHub sandbox; that history is still in git).
The suppression is a property of the sandbox's credential, so it cannot be
fixed from inside a session. Giving the environment a personal access token to
push with would make pushes and PRs behave normally for everyone. Until then,
the dispatch step above is the workaround.
## Bash output is filtered before it reaches the model
`.claude/settings.json` registers a `PreToolUse` hook on `Bash` that rewrites
each command through [rtk](https://github.com/rtk-ai/rtk): `git status` runs as
`rtk git status`, and rtk compresses the output. Write commands normally — the
rewrite is transparent and costs nothing to invoke.
Measured on this repo rather than quoted from rtk's README:
| Command | Raw | Filtered | Saved |
| --- | --- | --- | --- |
| `git diff HEAD~3` | 521 KB | 28 KB | 95% |
| `grep -rn "fun " app/src/main` | 117 KB | 19 KB | 84% |
| `find . -name "*.kt"` | 7.7 KB | 1.7 KB | 79% |
| `git log -20` | 20 KB | 5.3 KB | 74% |
| `git diff --stat` | 4.0 KB | 4.0 KB | 1% |
| `ls` of a single package | 50 B | 62 B | −24% |
The saving is all in the large outputs, which is the point — a full diff of a
few commits is otherwise most of a context window. Already-compact output grows
slightly, because rtk adds a header; at those sizes it does not matter. `rtk
gain` reports what the current session has actually saved.
Two limits are worth knowing. The `Read`, `Grep` and `Glob` tools are not
`Bash`, so they never reach the hook and are unaffected; a deliberate `rg` or
`find` in a shell *is* filtered. And filtering never truncates a file: `cat`
becomes `rtk read`, which was checked byte-for-byte against this repo's longest
Kotlin source (`GameSetupScreen.kt`, 946 lines) and came back identical. Commit
messages survive the rewrite intact, quotes and colons included. To bypass
filtering for one command, run `rtk proxy <cmd>`.
## rtk is reinstalled at the start of every session
The container starts empty, so `.claude/hooks/session-start.sh` installs rtk
before the session does anything. It pins `RTK_VERSION`, because the installer
otherwise asks `api.github.com` for the latest tag and the proxy answers 403 for
every repository except this one — the lookup fails and takes the install with
it. Bump that variable by hand.
The hook is written not to matter when it fails. Outside the sandbox it installs
nothing and just prints the command to run, since dropping a binary into
someone's `~/.local/bin` uninvited is not its business; if the download fails it
says so and exits clean. With rtk absent the rewrite hook no-ops, and the only
consequence is verbose output.
+151 -106
View File
@@ -1,32 +1,24 @@
# ProLibertateGames
# Pro Libertate Games
A collection of card and board games for Android, playable against the computer
or against other people over Wi-Fi (LAN).
Wallacenet's build of [ProLibertateGames](https://github.com/adrianoftyriel/ProLibertateGames)
by adrianoftyriel (GNU GPL v3 — see [LICENSE](LICENSE)), hosted at
<https://git.wallacenet.ca/devadmin/ProLibertateGames>. Game rules documentation
lives under [docs/](docs/README.md); build, CI and release decisions live in
[docs/CI.md](docs/CI.md). Katan itself arrives in later work — it is listed under
Board Games as *Coming soon* — and this app ships the reference catalogue
unchanged as the regression safety net.
## What works today
The app shell is complete and every game in the catalogue is playable end to end:
| | |
| --- | --- |
| **Cards** | Euchre, Kaiser, President, Golf, Wizard, Crazy 8s, Cribbage, Hearts, Klondike, FreeCell, Spider, Pyramid |
| **Table** | Sequence, Chess, Checkers, Backgammon, Mastermind, Nine Men's Morris, Peg Solitaire, Yahtzee, Pirates and Bulgars, Ta Yü, Katan *(coming soon)* |
| **Cards** | Euchre, Kaiser, President, Golf, Wizard, Crazy 8s, Cribbage |
| **Board** | Sequence, Chess, Checkers, Backgammon, Mastermind, Nine Men's Morris, Pirates and Bulgars, Ta Yü |
One entry is marked *Coming soon*: Katan, the island game, whose engine and
screen land with their own task. The machinery is still there and still tested:
a game listed in `GameCatalog` with `available = false` appears in the menu
marked *Coming soon* **on dev builds only**, so a production release lists just
what can actually be played and nobody installs it and taps into a dead end. The
menu decides this from the installed APK's own version name — the same source
the updater uses to know which channel it is on.
Nothing is marked *Coming soon* at the moment, because nothing is waiting. The
machinery for it is still there and still tested: a game listed in `GameCatalog`
with `available = false` appears in the menu marked *Coming soon* **on dev builds
only**, so a production release lists just what can actually be played and nobody
installs it and taps into a dead end. The menu decides this from the installed
APK's own version name — the same source the updater uses to know which channel
it is on.
Adding a game means writing a `GameRules` implementation, a `GameAi` and a
screen, then flipping `available` — the menu, lobby, networking, settings and OTA
@@ -119,53 +111,55 @@ it: every rule above is a pure function and unit-tested on the JVM.
- **Sound** on/off.
- **Animation speed**, 0.5×–2×. One multiplier drives card movement and how long
the computer appears to think.
- **Updates** — check on launch, or check on demand. The channel is this
project's own Gitea releases ([docs/CI.md](docs/CI.md)), and **there is no
channel to choose**: a build updates from its own channel and no other. The
settings screen states which one is running rather than offering a switch.
`BuildConfig.OTA_ENABLED` is the kill switch, not a preference.
- **Updates** — check on launch, or check on demand. **There is no channel to
choose**: a build updates from its own channel and no other. A production
install is offered production builds from `main`; a dev install is offered dev
builds from `dev`. The settings screen states which one is running rather than
offering a switch.
The check on launch **only ever speaks when there is a build to install**. It
runs behind the splash and waits for it to clear, and an app that is already
current — or a phone that cannot reach the release server — says nothing,
because opening the app was not a question. The button in Settings is a
question, so it answers every time, including "you're on the latest" and
whatever went wrong.
current — or a phone that cannot reach GitHub — says nothing, because opening
the app was not a question. The button in Settings is a question, so it
answers every time, including "you're on the latest" and whatever went wrong.
Wanting both means installing both — they are separate apps and each updates
itself, see [Both channels on one device](#both-channels-on-one-device).
## Branding
The app wears the upstream's own branding, restored (WALA-118 review): the
Wallace tartan is the launcher icon and the splash, drawn as vector drawables and
Compose code so it stays sharp at every density and needs no PNGs. The app opens
on the tartan held under the name, set in a Celtic uncial hand for two seconds
before it fades into the menu.
The launcher icon is a single square of the Wallace tartan set on the bias, and
the app opens on the same cloth carrying the name in a Celtic uncial hand for two
seconds before fading into the menu.
A dev build wears the **hunting green** sett where production wears the **clan
red**, and installs as *Pro Libertate Games DEV*. That is what tells the two
copies apart when both are on the phone; see
[Both channels on one device](#both-channels-on-one-device). The tartan is drawn
by `ui/theme/Tartan.kt` (`TartanBackground`, `threadWidthFor`) off
`BuildConfig.DEV_BUILD`; the matching vector colours are generated per build by
`resValue` in `app/build.gradle.kts` — the icon vectors reference
`@color/tartan_field` rather than a literal, which is how one set of vectors
serves both colourways.
A dev build wears **Wallace Hunting** instead — the same threadcount with green
where the clan sett has red — and installs as *Pro Libertate Games DEV*. That is
what tells the two copies apart when both are on the phone; see
[Both channels on one device](#both-channels-on-one-device).
The tartan is drawn, not an image: `ui/theme/Tartan.kt` lays the sett down as
warp and then as weft at half opacity, which is what produces the blended
squares instead of a flat grid. The icon is the same construction as a vector
drawable, so it stays sharp at every density and needs no PNGs.
Two honest caveats:
- **The sett is the published threadcount: `K/4 R32 K32 Y/4`.** The slashes are
pivots, so `WallaceSett` holds the half-sett and reflects it out to
`K4 R32 K32 Y4 K32 R32` — 136 threads, about half black, half red, with a
yellow line worth 3%. Two details define the pattern and are easy to get
backwards: the yellow overstripe runs down the *centre of a wide black band*,
and the narrow black guard sits *between two red blocks*. The icon is
generated from the same numbers, so the icon and the splash cannot drift.
Weave scale is derived from the sett rather than fixed, so changing the
threadcount rescales both instead of silently zooming in. The hunting
colourway is the same threadcount passed a different field colour, not a
second copy of the numbers, so it cannot fall out of step either.
- **The typeface is bundled under a licence.** Uncial Antiqua, © 2011 Brian J.
Bonislawsky DBA Astigmatic, Reserved Font Name "Uncial Antiqua", used under
the SIL Open Font License 1.1. The full licence is at
[docs/licenses/UncialAntiqua-OFL.txt](docs/licenses/UncialAntiqua-OFL.txt) and
must stay with the font — the OFL requires it to be distributed alongside.
- **Katan is the one place this app deliberately diverges.** No Catan
trademarks or brand assets ship anywhere in it; the island game is listed
under its own name with original art only. The GPL-licensed history that
produced this app remains in git, and the source stays at
[adrianoftyriel/ProLibertateGames](https://github.com/adrianoftyriel/ProLibertateGames)
as the `upstream` remote.
## Screen sizes
@@ -189,70 +183,122 @@ smaller than a fingertip.
Requires JDK 17 and the Android SDK (compileSdk 34).
A local build is a dev build: it installs as
`ca.wallacenet.prolibertategames.dev` under the name *Pro Libertate Games DEV* on
the hunting-green sett, so it goes on beside a production copy rather than over
it. Set `PLG_CHANNEL=production` to build the production package
(`ca.wallacenet.prolibertategames`, clan red).
A local build is a dev build: it installs as `org.prolibertate.games.dev` under
the name *Pro Libertate Games DEV* in the hunting sett, so it goes on beside an
installed release rather than over it. Set `PLG_CHANNEL=production` to build the
production package instead.
## CI
Full decision record: [docs/CI.md](docs/CI.md).
- `.github/workflows/ci.yml` — builds, tests and lints on `dev` and on pull
requests into `dev` or `main`, and publishes a dev prerelease from `dev`.
- `.github/workflows/release.yml` — builds and publishes the production release
on push to `main`, or by hand (`workflow_dispatch`).
- Both publish through [scripts/publish-release.sh](scripts/publish-release.sh)
against Gitea's REST API, which is also runnable by hand. **No Actions runner
is registered on the instance yet**, so until one is, the local build is the
guaranteed path (`./gradlew assembleDebug && ./gradlew testDebugUnitTest`)
and releases go out via the script.
requests into `dev` or `main`. Its APK artifact is a dev build, versioned
`<series>.0-dev` — the series being whatever `plgVersionSeries` says in
`gradle.properties`, currently **1.3**.
- `.github/workflows/release.yml` — on push to `main`, builds the APK and
publishes it as a GitHub Release tagged `v<series>.<run-number>`. The in-app updater
reads that tag, which is why the APK's `versionCode` is the same run number.
### Hosting: plg.wallacenet.ca
Both channels are also deployed to one Cloudflare Pages project (`plg`), served at
`https://plg.wallacenet.ca`:
```
/ landing page (reads both latest.json files)
/prod/latest.json {tag, apkName, apkUrl, channel} — what the updater reads
/prod/ProLibertateGames.apk, /prod/ProLibertateGames-v<series>.<n>.apk
/dev/... same, for the dev channel
```
Each workflow's `deploy-pages` job runs `.github/scripts/stage-pages-site.sh`,
which stages its own channel and re-fetches the other channel from the live site,
because a Pages deploy replaces everything. The two share a concurrency group so
they cannot race. Needs repo secrets `CLOUDFLARE_API_TOKEN` (Account → Cloudflare
Pages → Edit) and `CLOUDFLARE_ACCOUNT_ID`. Pages caps files at 25 MiB.
**First deploy:** the site does not exist yet, so the domain answers 403 (Cloudflare error 1014) and the carry-over fetch would abort. Dispatch the workflow once with `first_deploy` ticked, then attach `plg.wallacenet.ca` as a custom domain on the new `plg` Pages project. Later runs need no input.
The in-app updater reads these `latest.json` files, and this is the only release
channel: the workflows no longer create GitHub or Gitea releases. They run on
Gitea Actions (`https://git.wallacenet.ca/devadmin/ProLibertateGames`); the GitHub
repository is frozen and should stay public with its last releases, because
installs that predate the Cloudflare updater still read them to reach it.
Build numbers are `run number + plgVersionRunOffset` (1000, in `gradle.properties`),
so moving CI hosts, which restarts run numbers, can never publish a `versionCode`
lower than one already installed.
### Installing without the app
The newest production build is always at **https://plg.wallacenet.ca/prod/ProLibertateGames.apk** (dev: `/dev/ProLibertateGames.apk`). The GitHub link below is the frozen pre-migration release:
**https://github.com/adrianoftyriel/ProLibertateGames/releases/latest/download/ProLibertateGames.apk**
Every release carries the same APK twice — once named for its version, and once
as plain `ProLibertateGames.apk`, because GitHub's `/releases/latest/download/`
redirect needs a file name that stays put. The in-app updater deliberately picks
the versioned copy, so an installed build can always be traced back to its tag.
There is no equivalent link for the dev channel: `/releases/latest` skips
prereleases by design, and that is exactly what keeps a production install from
being handed a dev build. A dev build is reached by the in-app updater of a dev
install — which looks at the prerelease list rather than that endpoint — or from
the releases page.
### The version series
A version is **`<series>.<build number>`**. Both values are set by hand, once,
in `gradle.properties`:
A version is **`<series>.<run number>`**. The series is set by hand, once, in
`gradle.properties`:
```properties
plgVersionSeries=1.4
plgVersionRunOffset=1000
plgVersionSeries=1.3
```
Both workflows read those same properties when they name a release tag, and the
build reads them when it stamps the APK, so the tag and what is inside it cannot
name different versions. Changing either is a one-line change to that file and
nothing else — but they are not equivalent:
Both workflows read that same property when they name a release tag, and the
build reads it when it stamps the APK, so the tag and what is inside it cannot
name different versions. Bumping a series is a one-line change to that file and
nothing else.
- The **series** is a name for people. Bumping it changes nothing about
ordering.
- The **build number** is what the machines compare: `versionCode`, the tag's
trailing number, and the number in `versionName`, all the same figure —
`CI run number + plgVersionRunOffset`. Because the offset never changes and
the run number only climbs, going from 1.4 to 1.5 never looks like a downgrade
to Android and never interrupts an OTA update.
The offset exists because Gitea Actions restarts run numbers at 1 for each
workflow: without a floor, the first release of a fresh instance would collide
with the `versionCode 1` every unstamped local build carries, and a counter
reset would make Android refuse the next build outright. Full reasoning in
[docs/CI.md](docs/CI.md).
The number after it is the CI run number and keeps climbing on its own, which is
what makes a series bump safe: `versionCode` is the run number *alone*, so
going from 1.0 to 1.1 never looks like a downgrade to Android and never
interrupts an OTA update. The series is a name for people; the run number is
what the machines compare.
### Update channels
`ci.yml` stamps builds of `dev` as dev-channel, `release.yml` stamps `main` as
production, so an APK's identity is decided where it is built. Publishing goes
to this project's Gitea releases, and the rules it keeps:
Both pipelines publish, to two separate channels:
- production comes only from `main` (`release.yml` refuses any other branch);
- dev prereleases are marked so the "latest release" endpoint can never hand one
to a production install;
- pull requests build and check but never publish.
| Channel | Published by | Tag | Marked |
| --- | --- | --- | --- |
| Production | `release.yml`, push to `main` | `v<series>.<n>` | release |
| Dev | `ci.yml`, any build of `dev` | `v<series>.<n>-dev` | prerelease |
Dev builds are published as **prereleases** deliberately: GitHub's "latest
release" endpoint skips prereleases, so a production-channel install can never
be handed a dev build even by accident. Pull requests build and check but never
publish, so a PR from a fork cannot ship anything.
**Both pipelines gate publishing on the branch rather than on what triggered
the build**, so a manual run from the Actions tab publishes exactly as a push
does — useful when a push cannot fire the workflow itself, which is the case
for anything pushed by an automation token. The safety property is unchanged,
because publishing still happens only after that same job has built, tested and
linted clean. A pull request is still excluded without having to be named: a PR
build runs against `refs/pull/<n>/merge`, never `refs/heads/dev`.
In `ci.yml` the `PLG_CHANNEL` stamp is gated on the same condition as the
publish steps, and the two have to stay in step. Stamping a build that then
ships, or shipping one that was left unstamped, both end with an APK claiming
`versionCode` 1 — which the updater can never see as an upgrade over anything.
`release.yml` refuses to run off any branch but `main`, so a manual dispatch
aimed elsewhere does nothing rather than shipping unreviewed code.
**The two channels have independent version sequences** — a build's `versionCode`
is the build number of the workflow that produced it (run number + offset), and
the two workflows count separately, so the numbers say nothing across the
divide.
is the run number of the workflow that produced it, and the two workflows count
separately. Dev is on 69 while production is on 40, so the numbers say nothing
across the divide.
That is why **an install only ever updates within its own channel**, and why
there is no setting for it. The app reads the `-dev` suffix in its own
@@ -264,18 +310,18 @@ unit-tested on the JVM like the rules engines are.
### Both channels on one device
A dev build installs under its own `applicationId`,
`ca.wallacenet.prolibertategames.dev`, so it is a separate app as far as Android
is concerned and can sit beside the production copy rather than replacing it. Each channel still updates itself
A dev build installs under its own `applicationId`, `org.prolibertate.games.dev`,
so it is a separate app as far as Android is concerned and can sit beside the
production copy rather than replacing it. Each channel still updates itself
normally, because an update within a channel keeps the same package.
Three things move together, all off `isDevBuild` in `app/build.gradle.kts`:
| | Production | Dev |
| --- | --- | --- |
| `applicationId` | `ca.wallacenet.prolibertategames` | `ca.wallacenet.prolibertategames.dev` |
| `applicationId` | `org.prolibertate.games` | `org.prolibertate.games.dev` |
| Launcher name | Pro Libertate Games | Pro Libertate Games DEV |
| Tartan sett | clan red | hunting green |
| Sett | Wallace (red) | Wallace Hunting (green) |
Anything that is not an explicit `PLG_CHANNEL=production` build is a dev build,
so a local `assembleDebug` is a dev build too and installs alongside a release
@@ -285,11 +331,11 @@ They have to move together. A dev package wearing the production name and
colours is precisely the mix-up that having both installed is meant to prevent,
which is why one flag drives all three rather than each being set by hand. The
name and the colours reach the resources through `resValue`, so `app_name`,
`brand_field` and `splash_background` are generated by the build and are
deliberately *not* in `res/values/` — the icon vectors reference
`@color/brand_field` rather than a literal, which is how one set of vectors
serves both colourways. `BuildConfig.DEV_BUILD` carries the same flag into
Kotlin, where `BrandField` picks the matching Compose colour for the splash.
`tartan_field`, `splash_background` and `ic_launcher_background` are generated
by the build and are deliberately *not* in `res/values/` — the icon vectors
reference `@color/tartan_field` rather than a literal, which is how one set of
vectors serves both colourways. `BuildConfig.DEV_BUILD` carries the same flag
into Kotlin, where `AppSett` picks the matching Compose sett for the splash.
Because they are separate apps, having both is a matter of installing both, and
each then updates itself down its own line. Nothing in the app moves a phone
@@ -303,7 +349,7 @@ for a signature mismatch.
## Rules
The exact rules implemented, and the options that vary them, are documented per
game (index: [docs/README.md](docs/README.md)):
game:
- [Euchre](docs/RULES-euchre.md)
- [Sequence](docs/RULES-sequence.md) — **note the caveat about the board layout**
@@ -351,8 +397,7 @@ game/ rules engines and AI — pure Kotlin, no Android, unit-tested
net/ wire protocol, LAN transport, lobby, match driver
score/ scorekeeper sheet — pure Kotlin, unit-tested — and its store
settings/ DataStore-backed preferences
update/ OTA updater against this repo's Gitea releases, and the
channel rule — pure, tested
update/ Cloudflare Pages OTA updater, and the channel rule — pure, tested
ui/ Compose screens
```
+9 -28
View File
@@ -16,18 +16,10 @@ val buildChannel = System.getenv("PLG_CHANNEL").orEmpty()
val runNumber = (System.getenv("GITHUB_RUN_NUMBER") ?: "").toIntOrNull() ?: 0
val stampVersion = buildChannel.isNotEmpty() && runNumber > 0
// The fixed floor every stamped build number is measured from, in
// gradle.properties. Gitea Actions restarts its run numbers at 1 for each
// workflow, so an unstamped build (versionCode 1) and the first release of a
// fresh instance would otherwise collide — and once a phone has installed
// versionCode N, Android refuses anything smaller as a downgrade. Adding a
// permanent offset is what makes "the counter never resets" true by
// construction: it is read from one place, it never changes, and the tag,
// versionName and versionCode all get the same number (see docs/CI.md).
// See plgVersionRunOffset in gradle.properties: the stamped build number is the
// CI run number plus a permanent floor, so a counter that restarts on a new CI
// host can never produce a lower versionCode than one already installed.
val runOffset = (project.findProperty("plgVersionRunOffset") as String?)?.toIntOrNull() ?: 0
// The stamped build number: what the release tag, the versionName and the
// versionCode are all named after.
val buildNumber = runNumber + runOffset
// The version series, from gradle.properties. Both workflows read the same
@@ -46,30 +38,25 @@ val versionSeries = (project.findProperty("plgVersionSeries") as String?) ?: "1.
val isDevBuild = buildChannel != "production"
android {
// Deliberately left at the upstream source package: R and BuildConfig stay
// in org.prolibertate.games for both channels, so no source file has to
// care which applicationId it ended up installed as. The *installed*
// identity is the applicationId below — that is what the rebrand changes
// (WALA-118), not the JVM package names.
namespace = "org.prolibertate.games"
compileSdk = 34
defaultConfig {
// A dev build installs under its own package, so a dev copy and a
// production copy can sit side by side on one device instead of one
// replacing the other.
applicationId = if (isDevBuild) "ca.wallacenet.prolibertategames.dev" else "ca.wallacenet.prolibertategames"
// replacing the other. The namespace above is deliberately left alone:
// R and BuildConfig stay in org.prolibertate.games for both, so no
// source has to care which package it ended up installed as.
applicationId = if (isDevBuild) "org.prolibertate.games.dev" else "org.prolibertate.games"
minSdk = 24
targetSdk = 34
// The -dev suffix in versionName is what the installed app reads to
// know its own channel, so it must survive into the shipped APK. It
// tracks isDevBuild rather than the stamp alone, so an unstamped local
// build cannot end up claiming a channel its applicationId contradicts.
// versionCode is the stamped build number and nothing else, so it keeps
// versionCode stays the run number and nothing else, so it keeps
// climbing across a change of series: bumping 1.0 to 1.1 must not make
// an update look like a downgrade to Android. An unstamped build is 1,
// below every release, which is the honest answer for a build nobody
// stamped.
// an update look like a downgrade to Android.
versionCode = if (stampVersion) buildNumber else 1
versionName = when {
stampVersion && buildChannel == "production" -> "$versionSeries.$buildNumber"
@@ -100,12 +87,6 @@ android {
resValue("color", "ic_launcher_background", if (isDevBuild) "#145C2D" else "#B3121B")
buildConfigField("boolean", "DEV_BUILD", isDevBuild.toString())
// In-app OTA updates, pointed at this project's own Gitea releases
// (docs/CI.md). True in this build — the channel exists. Flipping it
// false is the kill switch: every check then reports that and fetches
// nothing, with the machinery and its tests still compiled.
buildConfigField("boolean", "OTA_ENABLED", "true")
}
signingConfigs {
+1 -3
View File
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- LAN play over TCP sockets, plus hand-a-down permission for in-app
installs — the OTA updater installs releases published on this repo's
Gitea; see docs/CI.md. -->
<!-- OTA updates from plg.wallacenet.ca, plus LAN play over TCP sockets. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Network Service Discovery needs multicast to see hosts on the LAN. -->
@@ -94,13 +94,6 @@ object GameCatalog {
const val MORRIS = "morris"
const val PIRATES = "pirates"
/**
* The island game the collection is named for. Listed under Board Games
* and marked *Coming soon*; the engine and its screen land with the game
* task, and `available` flips on once two-device play is verified.
*/
const val CATAN = "catan"
val all: List<GameDescriptor> = listOf(
GameDescriptor(
id = EUCHRE,
@@ -340,19 +333,6 @@ object GameCatalog {
"because your score multiplies them.",
available = true,
),
GameDescriptor(
id = CATAN,
title = "Katan",
menus = setOf(GameMenu.BOARD),
minPlayers = 3,
maxPlayers = 4,
teamBased = false,
blurb = "Trade, build, and settle the island.",
// Listed, not playable: the engine and screen land with the Katan
// game task. Dev builds show the entry as *Coming soon*; a
// production build lists only what can actually be played.
available = false,
),
)
fun byId(id: String): GameDescriptor? = all.firstOrNull { it.id == id }
@@ -49,7 +49,7 @@ fun LaunchUpdateCheck(env: AppEnv, visible: Boolean) {
}
// Held back behind the splash, so an update prompt cannot appear over the
// splash before the app itself has.
// tartan before the app itself has.
val pending = release
if (pending == null || dismissed || !visible) return
@@ -1,19 +1,17 @@
package org.prolibertate.games.update
import java.net.URI
/**
* Which line of builds an APK belongs to.
*
* This is a property of the build, never a preference. The two channels are
* published by different workflows and have entirely separate version
* sequences — a dev build's versionCode is its CI build number, a production
* build's is its release build number, and the two are unrelated. There is no
* sequences — a dev build's versionCode is its CI run number, a production
* build's is its release run number, and the two are unrelated. There is no
* meaning to be had from comparing across them, so nothing does.
*
* They also carry different applicationIds — a dev build installs as
* `…prolibertategames.dev` — so both can sit on one device, each updating
* itself down its own line and leaving the other alone.
* `…games.dev` — so both can sit on one device, each updating itself down its
* own line and leaving the other alone.
*/
enum class UpdateChannel(val label: String, val blurb: String) {
PRODUCTION("Production", "Stable builds released from main"),
@@ -23,7 +21,7 @@ enum class UpdateChannel(val label: String, val blurb: String) {
/** Marks a tag or a version name as belonging to the dev channel. */
const val DEV_SUFFIX = "-dev"
/** One published build, as read off a repository release. */
/** One published build, as read off a channel's `latest.json`. */
data class Release(
val tag: String,
val versionCode: Int,
@@ -51,14 +49,14 @@ fun channelOfVersionName(versionName: String): UpdateChannel =
* The channel a release belongs to.
*
* Two independent marks, and either is enough: the `-dev` suffix the workflow
* puts on the tag, and the release's own prerelease flag. A release would have
* to lose both to be mistaken for the other channel.
* puts on the tag, and GitHub's own prerelease flag. A release would have to
* lose both to be mistaken for the other channel.
*/
fun channelOfTag(tag: String, prerelease: Boolean): UpdateChannel =
if (tag.endsWith(DEV_SUFFIX) || prerelease) UpdateChannel.DEV else UpdateChannel.PRODUCTION
/**
* The build number out of a `v<series>.<n>` tag, which is what an APK's
* The run number out of a `v<series>.<n>` tag, which is what an APK's
* versionCode is.
*
* Only the trailing number is read. The series is a name for people, and
@@ -67,37 +65,15 @@ fun channelOfTag(tag: String, prerelease: Boolean): UpdateChannel =
fun versionCodeOfTag(tag: String): Int? =
tag.substringAfterLast('.').removeSuffix(DEV_SUFFIX).toIntOrNull()
/**
* Rewrites a download URL onto [host], keeping its scheme, path and query.
*
* A release server can answer for more than one host name, and it hands out
* asset URLs on whichever one it treats as canonical — which need not be the
* one the app was told to talk to. Fetching the release list from one host and
* the APK from another is a single DNS change away from a channel that half
* works, so the app stays on the host it decided to trust and takes only the
* path from what the server reported.
*
* Anything that cannot be parsed is returned unchanged: a broken URL fails
* loudly at download time, while a swallowed one would fail as a silent
* "something went wrong".
*/
fun onReportedHost(url: String, host: String): String = try {
val reported = URI(url)
val scheme = reported.scheme ?: "https"
URI(scheme, null, host, -1, reported.path, reported.query, null).toString()
} catch (e: Exception) {
url
}
/**
* The build a check on launch should interrupt somebody for, or null to say
* nothing at all.
*
* Only an actual update is worth a word. Opening the app is not asking a
* question, so a check that finds nothing — or that cannot reach the release
* server at all — stays quiet; a phone on a train would otherwise be told off
* for it every single launch. The button in Settings *is* asking a question, and
* reports every answer including those two.
* question, so a check that finds nothing — or that cannot reach the update server at all
* — stays quiet; a phone on a train would otherwise be told off for it every
* single launch. The button in Settings *is* asking a question, and reports
* every answer including those two.
*/
fun launchOffer(verdict: UpdateVerdict): Release? =
(verdict as? UpdateVerdict.Install)?.release
@@ -8,36 +8,17 @@ import android.provider.Settings
import androidx.core.content.FileProvider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.json.JSONArray
import org.json.JSONObject
import org.prolibertate.games.BuildConfig
import java.io.File
import java.net.HttpURLConnection
import java.net.URL
/**
* Over-the-air updates from the repository's releases.
* Over-the-air updates from plg.wallacenet.ca (Cloudflare Pages).
*
* The channel is the Gitea instance this app ships from
* (`git.wallacenet.ca`), not GitHub. Gitea's release API answers with the
* same shape the updater reads — `tag_name`, `prerelease`, `draft`, and
* assets carrying `browser_download_url` — so this is the same code the
* upstream ran, pointed at `/api/v1/repos/...` routes instead of
* `api.github.com`, with `limit` where GitHub says `per_page`.
*
* Release tags are v<series>.<n>, where **n is the stamped build number the
* APK's versionCode was built from** (the CI run number plus the fixed
* `plgVersionRunOffset` — see docs/CI.md), so comparing the two is enough to
* tell whether a newer build exists.
*
* The repository and its releases are public: no token is embedded in the
* app, and every download is anonymous by design. If the repo were ever made
* private, every check would simply start failing rather than leaking
* anything.
*
* `BuildConfig.OTA_ENABLED` is a kill switch, not a channel decision — it is
* true in this build; setting it false makes every check report that and
* fetch nothing.
* Release tags are v<series>.<run-number> and the APK's versionCode is that same run
* number, so comparing the two is enough to tell whether a newer build exists.
* Everything there is public — no token is embedded in the app.
*
* There is nothing to choose here. The channel comes from the running APK, so
* a dev install looks only at dev builds and a production install only at
@@ -52,11 +33,6 @@ class Updater(private val activity: Activity) {
* this phone is on, and the phone already knows.
*/
suspend fun check(): UpdateVerdict = withContext(Dispatchers.IO) {
if (!BuildConfig.OTA_ENABLED) {
return@withContext UpdateVerdict.Refused(
"In-app updates are not enabled for this build yet."
)
}
try {
val channel = installedChannel()
verdictFor(
@@ -70,70 +46,37 @@ class Updater(private val activity: Activity) {
}
/**
* Production reads the "latest release", which by definition skips
* prereleases — Gitea implements it as the most recent non-prerelease,
* non-draft release, so the rule holds on this instance too.
*
* Dev walks the release list for the newest prerelease, which is what the
* CI pipeline publishes from the dev branch. The list is taken as the
* highest versionCode among the dev releases rather than the first one
* returned, so the answer does not depend on how the server chose to
* order the page.
* Each channel publishes a `latest.json` next to its APK on Cloudflare
* Pages: `/prod/latest.json` and `/dev/latest.json`. The two live in one
* site but separate paths, so a build can only ever look down its own line.
*/
private fun fetchLatestRelease(channel: UpdateChannel): Release? = when (channel) {
UpdateChannel.PRODUCTION ->
getJsonObject("$API/releases/latest")
?.let { toRelease(it) }
UpdateChannel.DEV ->
getJsonArray("$API/releases?limit=30")
?.let { releases ->
(0 until releases.length())
.mapNotNull { toRelease(releases.getJSONObject(it)) }
.filter { it.channel == UpdateChannel.DEV }
.maxByOrNull { it.versionCode }
}
private fun fetchLatestRelease(channel: UpdateChannel): Release? {
val path = if (channel == UpdateChannel.DEV) "dev" else "prod"
return getJsonObject("$BASE_URL/$path/latest.json")?.let { toRelease(it) }
}
private fun toRelease(json: JSONObject): Release? {
val tag = json.optString("tag_name").ifBlank { return null }
val tag = json.optString("tag").ifBlank { return null }
val versionCode = versionCodeOfTag(tag) ?: return null
val channel = channelOfTag(tag, json.optBoolean("prerelease"))
val assets = json.optJSONArray("assets") ?: return null
val apks = (0 until assets.length())
.map { assets.getJSONObject(it) }
.filter { it.optString("name").endsWith(".apk") }
// A production release may carry the same build twice: once named for
// its version, and once under a fixed name so a permanent download link
// exists. Pick the versioned one explicitly rather than whichever was
// uploaded first, so what gets installed is traceable to its tag.
val chosen = apks.firstOrNull { it.optString("name").contains(tag) }
?: apks.firstOrNull()
?: return null
val apkUrl = json.optString("apkUrl").ifBlank { return null }
return Release(
tag = tag,
versionCode = versionCode,
apkUrl = onReportedHost(chosen.getString("browser_download_url"), SERVER_HOST),
apkName = chosen.optString("name"),
channel = channel,
apkUrl = apkUrl,
apkName = json.optString("apkName"),
channel = channelOfTag(tag, prerelease = false),
)
}
private fun openConnection(url: String): HttpURLConnection =
(URL(url).openConnection() as HttpURLConnection).apply {
private fun getJsonObject(url: String): JSONObject? {
val connection = (URL(url).openConnection() as HttpURLConnection).apply {
requestMethod = "GET"
setRequestProperty("Accept", "application/json")
setRequestProperty("User-Agent", "ProLibertateGames-Updater")
connectTimeout = 15_000
readTimeout = 15_000
}
private fun getJsonObject(url: String): JSONObject? {
val connection = openConnection(url)
try {
// 404 means the channel has nothing published yet.
if (connection.responseCode != 200) return null
return JSONObject(connection.inputStream.bufferedReader().use { it.readText() })
} finally {
@@ -141,16 +84,6 @@ class Updater(private val activity: Activity) {
}
}
private fun getJsonArray(url: String): JSONArray? {
val connection = openConnection(url)
try {
if (connection.responseCode != 200) return null
return JSONArray(connection.inputStream.bufferedReader().use { it.readText() })
} finally {
connection.disconnect()
}
}
/** Read back from the installed APK's own version name. */
fun installedChannel(): UpdateChannel = channelOfVersionName(installedVersionName())
@@ -202,13 +135,6 @@ class Updater(private val activity: Activity) {
activity.packageManager.getPackageInfo(activity.packageName, 0).versionName ?: "unknown"
private companion object {
/** The Gitea instance that publishes this app's releases. */
const val SERVER = "https://git.wallacenet.ca"
const val SERVER_HOST = "git.wallacenet.ca"
const val OWNER = "devadmin"
const val REPO = "ProLibertateGames"
/** Release routes, Gitea's `/api/v1` spelling of GitHub's API. */
const val API = "$SERVER/api/v1/repos/$OWNER/$REPO"
const val BASE_URL = "https://plg.wallacenet.ca"
}
}
@@ -106,19 +106,17 @@ class CatalogTest {
}
@Test
fun `every reference game in the catalogue can be played`() {
// Every game the app ships is playable. The one exception is Katan,
// listed so the slot exists and marked *Coming soon* until its engine
// and screen land — `available = false` is what keeps an unfinished
// game out of a production build while leaving it visible on a dev one.
fun `every game in the catalogue can be played`() {
// There is nothing left marked "coming soon". The machinery that hides
// unfinished games from a production build is still there and still
// tested above — it simply has nothing to hide at the moment, and this
// is what will fail the day something is added to the list before its
// engine is written.
assertTrue(GameCatalog.all.all { it.available })
assertEquals(
listOf(GameCatalog.CATAN),
GameCatalog.all.filterNot { it.available }.map { it.id },
GameCatalog.inMenu(GameMenu.BOARD, includeComingSoon = false),
GameCatalog.inMenu(GameMenu.BOARD, includeComingSoon = true),
)
// It is also the only difference the two channels see in a menu.
val hiddenFromProduction = GameCatalog.inMenu(GameMenu.BOARD, includeComingSoon = true) -
GameCatalog.inMenu(GameMenu.BOARD, includeComingSoon = false)
assertEquals(listOf(GameCatalog.byId(GameCatalog.CATAN)!!), hiddenFromProduction)
}
@Test
@@ -53,28 +53,6 @@ class UpdatePolicyTest {
assertNull(versionCodeOfTag("nightly"))
}
// -- Where the download happens ----------------------------------------
@Test
fun `a release asset is fetched from this app's host, keeping its path`() {
// The instance reports its canonical host; the app was told to trust
// another. Same bytes, one host, whatever the server names itself.
assertEquals(
"https://git.wallacenet.ca/devadmin/ProLibertateGames/releases/download/" +
"v1.4.1001-dev/ProLibertateGames-v1.4.1001-dev.apk",
onReportedHost(
"https://git.saskvalleytech.com/devadmin/ProLibertateGames/releases/download/" +
"v1.4.1001-dev/ProLibertateGames-v1.4.1001-dev.apk",
"git.wallacenet.ca",
),
)
// A URL that already says the right host is left exactly as it is.
val already = "https://git.wallacenet.ca/devadmin/ProLibertateGames/releases/download/v1.4.1/a.apk"
assertEquals(already, onReportedHost(already, "git.wallacenet.ca"))
// Anything unparseable survives untouched rather than being dropped.
assertEquals("not a url", onReportedHost("not a url", "git.wallacenet.ca"))
}
// -- The wall -----------------------------------------------------------
@Test
@@ -151,7 +129,7 @@ class UpdatePolicyTest {
assertNull("an up-to-date app has no business interrupting", launchOffer(UpdateVerdict.UpToDate))
assertNull(
"a phone with no network has nothing to apologise for",
launchOffer(UpdateVerdict.Refused("Unable to resolve host git.wallacenet.ca")),
launchOffer(UpdateVerdict.Refused("Unable to resolve host api.github.com")),
)
// Including the refusal that this whole change exists to produce: being
// shown the other channel's build is not a thing to be told about.
-141
View File
@@ -1,141 +0,0 @@
# CI, releases, and OTA — decisions and how to build
Status as of the ProLibertateGames bootstrap (WALA-118).
## Decisions
1. **The release channel is this instance's own releases.** The app ships from
<https://git.wallacenet.ca/devadmin/ProLibertateGames>, and the in-app updater
reads that repo's releases over Gitea's REST API. GitHub is not a channel for
this project; the only GitHub URLs left are the `upstream` remote and the
attribution link in the README.
The repo is **public on purpose**: the updater downloads anonymously, with no
token embedded in the APK. A private repo would make every check fail
(the API answers 404 to anonymous callers), not leak anything — but it would
also stop updates dead.
2. **CI lives in Actions-compatible workflows in `.github/workflows/`.**
Gitea Actions runs workflows from `.github/workflows/` (or `.gitea/workflows/`),
so these files serve both a GitHub-style runner and the Gitea instance.
Publishing goes through `scripts/publish-release.sh` — Gitea's REST API, the
same routes the app's updater reads — rather than the `gh` CLI, which a runner
image need not carry.
| Workflow | Trigger | Publishes |
| --- | --- | --- |
| `ci.yml` | push to `dev`, PRs into `dev`/`main`, manual | dev prerelease, from `dev` only |
| `release.yml` | push to `main`, manual | production release, from `main` only |
Pull requests build and check but never publish. Prereleases are marked so
the "latest release" endpoint — which skips them — can never hand a dev build
to a production install.
3. **A runner has to be registered before any of that executes.** As of the
bootstrap the instance has **no Actions runner**, so the workflows are
correct but idle: a Gitea runner (Docker or host) must be registered against
the instance and able to resolve `actions/checkout`,
`actions/setup-java`, `android-actions/setup-android` and
`actions/upload-artifact`. Until then the manual build below and the manual
publish script are the working paths.
4. **The local build is the guaranteed path.** Workflows need a runner that may
not exist yet; `./gradlew assembleDebug` + `./gradlew testDebugUnitTest`
work on any machine with JDK 17 and the Android SDK (compileSdk 34), and CI's
green means exactly these two commands plus lint.
## Build numbers, tags, and why updates never downgrade
An APK is **`<series>.<build number>`**, the release tag is **`v<series>.<build
number>`**, and the build number is what Android sees as `versionCode`:
```
build number = CI run number + plgVersionRunOffset (gradle.properties)
```
- `plgVersionSeries` (currently `1.4`) is the human-facing series, set by hand
in `gradle.properties`.
- `plgVersionRunOffset` (currently `1000`) is a **permanent floor**, also set by
hand in `gradle.properties`, set once at bootstrap and never changed.
Why the offset exists: Gitea Actions restarts run numbers at 1 for each
workflow, so without it the first release of a fresh instance would be build
`1` — the number an unstamped local build already carries — and any reset of
the counter would hand Android a *lower* `versionCode`, which it refuses as a
downgrade. With the offset, every stamped build starts at 1001 and only ever
climbs, because the run number is monotonic and the offset never moves. The
gradle build and both workflows read the same two properties, so the tag and
the APK inside it cannot name different versions.
The series is a name for people: bumping it changes nothing about ordering,
because `versionCode` never includes the series.
Unstamped builds (local, or a PR build) are `versionCode 1`, below every
release — the honest answer for a build nobody stamped.
## Manual build (works today, no runner needed)
```sh
# JDK 17, Android SDK with platform 34 + build-tools 34
export JAVA_HOME=... # a JDK 17 install
export ANDROID_HOME=... # SDK root (or set sdk.dir in local.properties)
./gradlew assembleDebug # dev-channel app (default: ca.wallacenet.prolibertategames.dev)
PLG_CHANNEL=production ./gradlew assembleDebug # production app (ca.wallacenet.prolibertategames)
./gradlew testDebugUnitTest # JVM unit tests
./gradlew lintDebug # Android lint (CI runs this too)
```
The two variants install side by side: different applicationId, different
launcher name (`Pro Libertate Games DEV` vs `Pro Libertate Games`), different
tartan sett.
## Manual release (works today, no runner needed)
```sh
GITEA_TOKEN=… ./scripts/publish-release.sh v1.4.1001 app/build/outputs/apk/debug/app-debug.apk release "$(git rev-parse HEAD)"
```
The script takes `<tag> <apk> <prerelease|release> [target-sha]`, creates the
release through `POST /api/v1/repos/{owner}/{repo}/releases`, attaches the APK
through `POST …/releases/{id}/assets` — which is the upload route Gitea's
Swagger declares for this instance (1.27.3) — and then reads the release back
and corrects its state if it did not stick. That last step is not decoration:
this instance has been observed to accept `draft: false` at create time and
store the release as a draft after the attachment lands, and a draft is
invisible to the updater, so the script verifies rather than assumes. If the
tag already exists it publishes into the existing release instead of failing,
so a retry is safe.
## What the in-app updater reads
`app/src/main/java/org/prolibertate/games/update/Updater.kt`:
| Channel | Endpoint |
| --- | --- |
| production | `GET /api/v1/repos/devadmin/ProLibertateGames/releases/latest` |
| dev | `GET /api/v1/repos/devadmin/ProLibertateGames/releases?limit=30` |
- `/releases/latest` is documented by Gitea as *the most recent non-prerelease,
non-draft release* — the same rule GitHub implements, so the production
channel keeps skipping dev builds.
- The dev path takes the highest `versionCode` among the prereleases rather
than whatever came first on the page, so it does not depend on server
ordering.
- The JSON shape is the one the code already parsed from GitHub: `tag_name`,
`prerelease`, `draft`, and assets carrying `browser_download_url`. Gitea says
`limit` where GitHub says `per_page`.
- Each asset must be named so it contains its tag —
`ProLibertateGames-v1.4.1001.apk` for tag `v1.4.1001` — because the updater
picks the versioned APK out of the release's assets by that rule.
`BuildConfig.OTA_ENABLED` is a kill switch, not a channel decision: it is
`true`, and setting it `false` makes every check report that and fetch nothing.
`UpdatePolicy.kt` — channel rules, tag parsing, verdicts — is pure and stays
under test either way.
## Keystore
`app/debug.keystore` is committed deliberately and must never be rotated:
every build — local, CI, release — signs with it, so an OTA update installs
over the previous build instead of being rejected for a signature mismatch.
-45
View File
@@ -1,45 +0,0 @@
# docs/
Conventions for this repo's documentation. Seeded at bootstrap (WALA-118).
## Per-game rules: `RULES-<game>.md`
Every game in `GameCatalog` gets one file describing how *this app* implements
it — not a generic rule dump. The rules code
(`app/src/main/java/org/prolibertate/games/game/<game>/`) is the source of
truth; the doc exists so a human or an agent can check intent against
behaviour without reading Kotlin first.
Naming: the catalogue id, lowercase, e.g. `crazy8s` → `RULES-crazy8s.md`.
| Game (catalogue id) | Rules doc |
| --- | --- |
| Backgammon | [RULES-backgammon.md](RULES-backgammon.md) |
| Checkers | [RULES-checkers.md](RULES-checkers.md) |
| Chess | [RULES-chess.md](RULES-chess.md) |
| Crazy 8s | [RULES-crazy8s.md](RULES-crazy8s.md) |
| Cribbage | [RULES-cribbage.md](RULES-cribbage.md) |
| Euchre | [RULES-euchre.md](RULES-euchre.md) |
| FreeCell | — (TODO) |
| Golf | [RULES-golf.md](RULES-golf.md) |
| Hearts | — (TODO) |
| Kaiser | [RULES-kaiser.md](RULES-kaiser.md) |
| Klondike | — (TODO) |
| Mastermind | [RULES-mastermind.md](RULES-mastermind.md) |
| Morris | [RULES-morris.md](RULES-morris.md) |
| Peg solitaire | — (TODO) |
| Pirates | [RULES-pirates.md](RULES-pirates.md) |
| President | [RULES-president.md](RULES-president.md) |
| Pyramid | — (TODO) |
| Sequence | [RULES-sequence.md](RULES-sequence.md) |
| Spider | — (TODO) |
| Ta Yü | [RULES-tayu.md](RULES-tayu.md) |
| Wizard | [RULES-wizard.md](RULES-wizard.md) |
| Yahtzee | — (TODO) |
## Other docs
- [CI.md](CI.md) — build, CI, releases, OTA decisions.
- `licenses/` — third-party licences that must travel with the app
(Uncial Antiqua under the SIL OFL; the app itself is GPL-3.0, see `/LICENSE`).
- Repo-level agent notes live in [`CLAUDE.md`](../CLAUDE.md) at the root.
+6 -6
View File
@@ -24,10 +24,10 @@ android.nonTransitiveRClass=true
# when this changes.
plgVersionSeries=1.4
# The permanent floor under every stamped build number: versionCode (and the
# release tag, and versionName) are `run number + this`. Gitea Actions starts
# run numbers at 1 for each workflow, so without it the first Gitea-era release
# would be build 1 — the same number an unstamped local build already carries —
# and any later reset would make Android reject the next build as a downgrade.
# Set once, at bootstrap, and never changed again: see docs/CI.md.
# The permanent floor under every stamped build number: versionCode, versionName
# and the release tag are all `run number + this`. Run numbers restart at 1 on a
# new CI host (Gitea Actions), and Android refuses any versionCode lower than the
# one installed, so without a floor the first build after a move would look like
# a downgrade. 1000 sits above every number GitHub reached (prod 30, dev ~172).
# Set once and never changed.
plgVersionRunOffset=1000
-126
View File
@@ -1,126 +0,0 @@
#!/bin/sh
# Publish a built APK to this repository's Gitea releases — the channel the
# in-app updater reads (docs/CI.md).
#
# The workflows call this, and so can a person: it is the whole release step,
# runnable by hand on any machine with curl, which matters because a Gitea
# Actions runner has to exist before the workflows can run at all.
#
# scripts/publish-release.sh <tag> <apk> <prerelease|release> [target-sha]
#
# Environment:
# GITEA_TOKEN required — a token that may create releases on the repo.
# GITEA_API API base, default https://git.wallacenet.ca/api/v1
# GITEA_REPO owner/name, default devadmin/ProLibertateGames
#
# The four arguments can also arrive as RELEASE_TAG, RELEASE_APK,
# RELEASE_KIND and RELEASE_TARGET, which is how the workflows pass them.
set -eu
usage() {
sed -n '2,17p' "$0" | sed 's/^# \{0,1\}//' >&2
}
tag="${1:-${RELEASE_TAG:-}}"
apk="${2:-${RELEASE_APK:-}}"
kind="${3:-${RELEASE_KIND:-}}"
target="${4:-${RELEASE_TARGET:-${GITHUB_SHA:-HEAD}}}"
case "$kind" in
prerelease|release) ;;
*) usage; exit 2 ;;
esac
[ -n "$tag" ] || { usage; exit 2; }
[ -f "$apk" ] || { echo "publish-release: no such APK: ${apk:-<unset>}" >&2; exit 2; }
[ -n "${GITEA_TOKEN:-}" ] || { echo "publish-release: GITEA_TOKEN is not set" >&2; exit 2; }
api="${GITEA_API:-${GITHUB_API_URL:-https://git.wallacenet.ca/api/v1}}/repos/${GITEA_REPO:-${GITHUB_REPOSITORY:-devadmin/ProLibertateGames}}"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT INT TERM
# Named for its tag, not for whatever the build happened to call it: the
# updater picks the versioned APK out of a release's assets by finding the one
# whose name contains the tag, so an asset called app-debug.apk would only be
# found by the fallback rule.
apk_name="ProLibertateGames-${tag}.apk"
# The tag and the file name are both derived from gradle.properties and a run
# number, so neither can carry a quote or a backslash into this JSON.
if [ "$kind" = "prerelease" ]; then
prerelease=true
note="Automated dev-channel build of ${target}. Newer than production and less tested — switch to the Dev update channel in Settings to be offered these. Published as a prerelease so production-channel installs never see it."
else
prerelease=false
note="Production-channel build of ${target}. Download ${apk_name} below and install it on an Android device (you may need to allow installs from unknown apps). It is signed with the repo's fixed keystore, which is what lets the in-app updater install over it."
fi
cat > "$tmp/release.json" <<JSON
{"tag_name":"${tag}","target_commitish":"${target}","name":"Pro Libertate Games ${tag}","body":"${note}","prerelease":${prerelease},"draft":false}
JSON
code="$(curl -sS -o "$tmp/create.json" -w '%{http_code}' -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
--data @"$tmp/release.json" \
"$api/releases")"
# 422 is the usual answer when the tag already exists — a re-run of a
# workflow, or a second attempt by hand. Publishing into the release that is
# already there is the right thing to do, not a failure.
if [ "$code" != "201" ] && [ "$code" != "200" ]; then
code="$(curl -sS -o "$tmp/create.json" -w '%{http_code}' \
-H "Authorization: token ${GITEA_TOKEN}" \
"$api/releases/tags/${tag}")"
fi
if [ "$code" != "201" ] && [ "$code" != "200" ]; then
echo "publish-release: creating release ${tag} failed (HTTP ${code})" >&2
cat "$tmp/create.json" >&2
echo >&2
exit 1
fi
# Gitea answers compact JSON, and the release's own id is the first "id" in
# it — the author's object comes later in the document.
id="$(grep -o '"id":[0-9]*' "$tmp/create.json" | head -n1 | tr -dc '0-9' || true)"
[ -n "$id" ] || { echo "publish-release: no release id in response" >&2; cat "$tmp/create.json" >&2; echo >&2; exit 1; }
# Attach the APK first, then check the stored state: uploading has been
# observed to leave a freshly created release as a draft, whatever the create
# response said, so the check has to be the last thing that happens rather
# than a step in the middle.
code="$(curl -sS -o "$tmp/asset.json" -w '%{http_code}' -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-F "attachment=@${apk};filename=${apk_name}" \
"$api/releases/${id}/assets")"
if [ "$code" != "201" ] && [ "$code" != "200" ]; then
echo "publish-release: attaching ${apk_name} to release ${id} failed (HTTP ${code})" >&2
cat "$tmp/asset.json" >&2
echo >&2
exit 1
fi
# Read back what the database actually stored before declaring success. A draft
# is invisible to the updater — exactly what a channel must not silently become
# — and this instance has been seen to report one as published at create time
# and store it as a draft by the time it is read.
curl -sS -o "$tmp/stored.json" -H "Authorization: token ${GITEA_TOKEN}" "$api/releases/${id}"
if grep -q '"draft":true' "$tmp/stored.json" ||
! grep -q "\"prerelease\":${prerelease}" "$tmp/stored.json"; then
state="$(curl -sS -o "$tmp/fix.json" -w '%{http_code}' -X PATCH \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"draft\":false,\"prerelease\":${prerelease}}" \
"$api/releases/${id}")"
if [ "$state" != "200" ]; then
echo "publish-release: release ${tag} is stored with the wrong state (HTTP ${state})" >&2
cat "$tmp/fix.json" >&2
echo >&2
exit 1
fi
echo "publish-release: corrected the stored state of ${tag} (it was saved as a draft)"
fi
echo "publish-release: ${tag} -> release ${id} on ${api#*/repos/}, asset ${apk_name}"
+3
View File
@@ -0,0 +1,3 @@
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><title>Not found</title></head>
<body><h1>404</h1><p>Not found. <a href="/">Pro Libertate Games downloads</a></p></body></html>
+7
View File
@@ -0,0 +1,7 @@
/*/latest.json
Cache-Control: no-cache
Access-Control-Allow-Origin: *
/*.apk
Content-Type: application/vnd.android.package-archive
Cache-Control: public, max-age=300
+34
View File
@@ -0,0 +1,34 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pro Libertate Games</title>
<style>
:root { color-scheme: light dark; font-family: system-ui, sans-serif; }
body { max-width: 32rem; margin: 3rem auto; padding: 0 1rem; line-height: 1.5; }
.card { border: 1px solid #8884; border-radius: .5rem; padding: 1rem; margin: 1rem 0; }
a.dl { display: inline-block; padding: .5rem 1rem; border-radius: .4rem; background: #2563eb; color: #fff; text-decoration: none; }
small { opacity: .7; }
</style>
</head>
<body>
<h1>Pro Libertate Games</h1>
<p>Android builds. Allow <em>Install unknown apps</em> for your browser to sideload.</p>
<div class="card" id="production"><h2>Production</h2><p>Loading…</p></div>
<div class="card" id="dev"><h2>Dev</h2><p>Loading…</p></div>
<script>
for (const [channel, path] of [["production", "prod"], ["dev", "dev"]]) {
const box = document.getElementById(channel);
const title = box.querySelector("h2").outerHTML;
fetch(`/${path}/latest.json`, { cache: "no-cache" })
.then(r => r.ok ? r.json() : Promise.reject())
.then(j => {
box.innerHTML = `${title}<p><a class="dl" href="${j.apkUrl}">Download ${j.tag}</a></p>` +
`<small>Always newest: <a href="/${path}/ProLibertateGames.apk">/${path}/ProLibertateGames.apk</a></small>`;
})
.catch(() => { box.innerHTML = `${title}<p>No build published yet.</p>`; });
}
</script>
</body>
</html>