Build and Release APK / Build APK and publish release (push) Canceled after 0s
Import of ProLibertateGames (upstream main, GPL-3.0) rebranded for Wallacenet and repointed at git.wallacenet.ca. - Identity: applicationId ca.wallacenet.pilgrimsofkatan (+ .dev for the dev channel), launcher names "Pilgrims of Katan" / "Pilgrims of Katan DEV", neutral hexagon branding replacing the Wallace tartan. Uncial Antiqua keeps its OFL licence, and the GPL-3.0 LICENSE plus upstream attribution stay. - OTA: Updater.kt now reads this repo's own Gitea releases (/api/v1/repos/devadmin/PilgrimsOfKatan/releases...) and BuildConfig. OTA_ENABLED is on; Gitea answers the same JSON shape the code already parsed. - Build numbers: versionCode = CI run number + plgVersionRunOffset (1000), with the tag and versionName derived from the same figure. The offset is permanent, because Gitea Actions restarts run numbers at 1 and a reset would otherwise make Android reject the next build as a downgrade. - CI: ci.yml publishes a dev prerelease from dev, release.yml a production release from main, both through scripts/publish-release.sh (Gitea REST API, runnable by hand until an Actions runner is registered). - Docs: docs/CI.md records the channel, numbering and runner decisions; docs/README.md seeds the per-game RULES-* conventions; CLAUDE.md carries the agent ground rules. Verified: ./gradlew assembleDebug and testDebugUnitTest green on JDK 17 / compileSdk 34, both variants stamped, installing side by side under the new identity. Co-Authored-By: Paperclip <[email protected]>
97 lines
4.0 KiB
Bash
Executable File
97 lines
4.0 KiB
Bash
Executable File
#!/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/PilgrimsOfKatan
|
|
#
|
|
# 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/PilgrimsOfKatan}}"
|
|
apk_name="$(basename "$apk")"
|
|
|
|
tmp="$(mktemp -d)"
|
|
trap 'rm -rf "$tmp"' EXIT INT TERM
|
|
|
|
# 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":"Pilgrims of Katan ${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; }
|
|
|
|
code="$(curl -sS -o "$tmp/asset.json" -w '%{http_code}' -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@${apk}" \
|
|
"$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
|
|
|
|
echo "publish-release: ${tag} -> release ${id} on ${api#*/repos/}, asset ${apk_name}"
|