62 lines
3.6 KiB
Bash
Executable File
62 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Builds the launcher APK (MoonBit page + Java shell, android/build.sh) and publishes it as a
|
|
# Gitea release: build-<versionCode>, holding ultra-launcher.apk and version.json, made a
|
|
# draft first and published once both files are up, so the latest release never lacks them.
|
|
# Runs in .gitea/workflows/launcher.yml's "apk" job (node:22-bookworm container, as root,
|
|
# no docker). The installed app updates itself from the latest release (updater/ in MoonBit).
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
# Minutes since the epoch: always above every earlier build's versionCode (the Qt builds used
|
|
# the same scale) and always rising.
|
|
export VERSION_CODE=$(( $(date +%s) / 60 ))
|
|
COMMIT="${GITHUB_SHA:-$(git rev-parse HEAD)}"
|
|
|
|
echo "== tools"
|
|
# In the cluster's android-sdk image the JDK, SDK and common tools are already there; on a bare
|
|
# image (the documented fallback, e.g. node:22-bookworm) they are installed below.
|
|
if ! command -v javac >/dev/null || ! command -v zip >/dev/null || ! command -v curl >/dev/null; then
|
|
apt-get update -qq
|
|
apt-get install -y -qq --no-install-recommends openjdk-17-jdk-headless unzip zip curl ca-certificates git >/dev/null
|
|
fi
|
|
command -v moon >/dev/null || [ -x "$HOME/.moon/bin/moon" ] || curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
|
|
export PATH="$HOME/.moon/bin:$PATH"
|
|
moon update
|
|
|
|
SDK="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-/opt/android-sdk}}"
|
|
if [ -f "$SDK/platforms/android-35/android.jar" ] && ls -d "$SDK"/build-tools/35* >/dev/null 2>&1; then
|
|
echo "== Android SDK from the image ($SDK)"
|
|
else
|
|
echo "== Android SDK fallback (build-tools and the platform jar only)"
|
|
SDK=/opt/android-sdk
|
|
mkdir -p "$SDK/cmdline-tools"
|
|
curl -fsSL -o /tmp/cmdline.zip https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
|
|
unzip -q /tmp/cmdline.zip -d "$SDK/cmdline-tools"
|
|
mv "$SDK/cmdline-tools/cmdline-tools" "$SDK/cmdline-tools/latest"
|
|
yes | "$SDK/cmdline-tools/latest/bin/sdkmanager" --licenses >/dev/null || true
|
|
"$SDK/cmdline-tools/latest/bin/sdkmanager" --install "build-tools;35.0.0" >/dev/null
|
|
# Only android.jar is needed from the platform: unzipping the whole thing (sdkmanager) is slow.
|
|
curl -fsSL -o /tmp/platform.zip https://dl.google.com/android/repository/platform-35_r02.zip
|
|
mkdir -p "$SDK/platforms" && unzip -q /tmp/platform.zip 'android-35/android.jar' -d "$SDK/platforms"
|
|
fi
|
|
export ANDROID_SDK_ROOT="$SDK"
|
|
|
|
echo "== build (versionCode $VERSION_CODE)"
|
|
android/build.sh ultra-launcher.apk
|
|
|
|
echo "== release build-$VERSION_CODE"
|
|
server="${GITHUB_SERVER_URL:-https://git.site.latha.org}"
|
|
repo="${GITHUB_REPOSITORY:-experiments/launcher}"
|
|
api="${server%/}/api/v1/repos/$repo"
|
|
token="${GITEA_TOKEN:-${GITHUB_TOKEN:-}}"
|
|
test -n "$token" || { echo "no GITEA_TOKEN/GITHUB_TOKEN in the environment"; exit 1; }
|
|
auth=(-H "Authorization: token $token")
|
|
tag="build-$VERSION_CODE"
|
|
id=$(curl -fsS "${auth[@]}" -H "Content-Type: application/json" -X POST "$api/releases" \
|
|
-d "{\"tag_name\": \"$tag\", \"name\": \"ultra Home build $VERSION_CODE\", \"target_commitish\": \"$COMMIT\", \"draft\": true, \"body\": \"MoonBit launcher built from $COMMIT.\"}" \
|
|
| python3 -c 'import sys, json; print(json.load(sys.stdin)["id"])')
|
|
curl -fsS "${auth[@]}" -F "attachment=@ultra-launcher.apk" "$api/releases/$id/assets?name=ultra-launcher.apk" >/dev/null
|
|
curl -fsS "${auth[@]}" -F "attachment=@$(dirname ultra-launcher.apk)/version.json" "$api/releases/$id/assets?name=version.json" >/dev/null
|
|
curl -fsS "${auth[@]}" -H "Content-Type: application/json" -X PATCH "$api/releases/$id" -d '{"draft": false}' >/dev/null
|
|
echo "published $tag to $server/$repo"
|