chore(mobile): add one-command APK release script
This commit is contained in:
1 parent
a8b175132a
commit
c607b73d94
3 files changed
+89
No files matched your search
@@ -0,0 +1,13 @@
|
||||
# Copy this file to .env.release. .env.release is gitignored.
|
||||
T3CODE_APK_REPOSITORY_URL=https://git.molberg.cloud/alex/t3code
|
||||
ANDROID_HOME=/path/to/Android/sdk
|
||||
ANDROID_NDK_HOME=/path/to/Android/sdk/ndk/<version>
|
||||
ANDROID_BUILD_TOOLS_VERSION=36.0.0
|
||||
APK_KEYSTORE_BASE64=
|
||||
APK_KEYSTORE_PASSWORD=
|
||||
APK_KEY_ALIAS=
|
||||
APK_KEY_PASSWORD=
|
||||
APK_RELEASE_TOKEN=
|
||||
# Optional overrides:
|
||||
# APK_VERSION_CODE=1001
|
||||
# APK_RELEASE_BODY=Release notes
|
||||
@@ -40,6 +40,7 @@ node_modules/
|
||||
*.log
|
||||
.env*
|
||||
!.env.example
|
||||
!.env.release.example
|
||||
|
||||
# pnpm content-addressable store; never belongs in the repo.
|
||||
.pnpm-store/
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
CONFIG_FILE="${CONFIG_FILE:-.env.release}"
|
||||
if [[ ! -f "$CONFIG_FILE" ]]; then
|
||||
echo "Missing $CONFIG_FILE. Copy .env.release.example and fill it in." >&2
|
||||
exit 1
|
||||
fi
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$CONFIG_FILE"
|
||||
set +a
|
||||
|
||||
required=(T3CODE_APK_REPOSITORY_URL ANDROID_HOME ANDROID_NDK_HOME APK_KEYSTORE_BASE64 APK_KEYSTORE_PASSWORD APK_KEY_ALIAS APK_KEY_PASSWORD APK_RELEASE_TOKEN)
|
||||
for name in "${required[@]}"; do
|
||||
[[ -n "${!name:-}" ]] || { echo "$name must be set in $CONFIG_FILE" >&2; exit 1; }
|
||||
done
|
||||
|
||||
if ! git diff --quiet HEAD; then
|
||||
echo "Working tree has changes. Commit them before releasing." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
highest=0
|
||||
while IFS= read -r tag; do
|
||||
if [[ "$tag" =~ ^apk-([1-9][0-9]*)$ ]] && (( BASH_REMATCH[1] > highest )); then
|
||||
highest=${BASH_REMATCH[1]}
|
||||
fi
|
||||
done < <(git ls-remote --tags --refs "$T3CODE_APK_REPOSITORY_URL" | sed 's#.*refs/tags/##')
|
||||
|
||||
if [[ -n "${APK_VERSION_CODE:-}" ]]; then
|
||||
version_code="$APK_VERSION_CODE"
|
||||
else
|
||||
version_code=$((highest + 1))
|
||||
fi
|
||||
if ! [[ "$version_code" =~ ^[1-9][0-9]*$ ]] || (( version_code > 2100000000 )); then
|
||||
echo "APK_VERSION_CODE must be between 1 and 2100000000." >&2
|
||||
exit 1
|
||||
fi
|
||||
if (( version_code <= highest )); then
|
||||
echo "Version code $version_code must exceed existing maximum $highest." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tag_name="apk-$version_code"
|
||||
if git ls-remote --exit-code --tags --refs origin "$tag_name" >/dev/null 2>&1; then
|
||||
echo "Remote tag $tag_name already exists." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export T3CODE_APK_RELEASE_TAG="$tag_name"
|
||||
export APP_VARIANT=production
|
||||
export T3CODE_MOBILE_UPDATES_ENABLED=0
|
||||
bash scripts/build-fork-apk.sh
|
||||
|
||||
commit_sha=$(git rev-parse HEAD)
|
||||
node --input-type=module <<'NODE'
|
||||
import * as NodeFS from "node:fs/promises";
|
||||
import { publishForkApk } from "./scripts/publish-fork-apk.ts";
|
||||
const tag = process.env.T3CODE_APK_RELEASE_TAG;
|
||||
const repositoryUrl = process.env.T3CODE_APK_REPOSITORY_URL;
|
||||
const token = process.env.APK_RELEASE_TOKEN;
|
||||
const commit = process.env.APK_RELEASE_COMMIT;
|
||||
if (!tag || !repositoryUrl || !token || !commit) throw new Error("Release environment is incomplete.");
|
||||
await publishForkApk({
|
||||
tag, repositoryUrl, token, commit,
|
||||
apk: new Blob([await NodeFS.readFile(`release/t3code-${tag}.apk`)], { type: "application/vnd.android.package-archive" }),
|
||||
checksum: new Blob([await NodeFS.readFile(`release/t3code-${tag}.apk.sha256`)], { type: "text/plain" }),
|
||||
});
|
||||
NODE
|
||||
|
||||
git tag "$tag_name" "$commit_sha"
|
||||
git push origin "$tag_name"
|
||||
echo "Published $tag_name"
|
||||
Reference in new issue
Block a user