Rewrite the launcher in MoonBit (old code moves to legacy/) (#1)
Launcher / test (push) Successful in 1m20s
Launcher / apk (push) Successful in 37s

This commit was merged in pull request #1.
This commit is contained in:
nandi committed 2026-11-23 01:57:10 +00:00
1 parent 7d2bf5996f
commit 2fa7bd745b
150 files changed
+8319 -462

No files matched your search

+37 -49
View File
@@ -1,60 +1,48 @@
#!/usr/bin/env bash
# Tests the Qt launcher (qt/), builds its APK 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 (JDK 17 container, as root).
# 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")/.."
QT_VERSION=6.8.3
NDK=26.1.10909125
# Minutes since the epoch: always above the GitHub builds' run numbers and always rising.
VERSION_CODE=$(( $(date +%s) / 60 ))
# 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"
apt-get update -qq
# The host Qt tools (moc, qmlimportscanner, qmlcachegen) need glib, GL and friends;
# g++ builds the desktop test and nodejs runs the layout test.
apt-get install -y -qq --no-install-recommends python3-pip python3-venv ninja-build cmake g++ nodejs unzip curl ca-certificates git \
libglib2.0-0t64 libgl1 libegl1 libopengl0 libgl-dev libglx-dev libopengl-dev libegl-dev libxkbcommon-dev \
libfontconfig1 libfreetype6 libxkbcommon0 libdbus-1-3 >/dev/null
python3 -m venv /opt/aqt && /opt/aqt/bin/pip install -q aqtinstall
# 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
echo "== Qt $QT_VERSION (android arm64 + host)"
/opt/aqt/bin/aqt install-qt linux android "$QT_VERSION" android_arm64_v8a -O /opt/Qt --autodesktop >/dev/null
QT_ROOT=/opt/Qt/$QT_VERSION/android_arm64_v8a
QT_HOST=/opt/Qt/$QT_VERSION/gcc_64
echo "== tests (desktop Qt)"
node qt/tests/layout.test.mjs
cmake -S qt -B build-desktop -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$QT_HOST"
cmake --build build-desktop
QT_QPA_PLATFORM=offscreen build-desktop/ultrahome_e2e
echo "== Android SDK + NDK $NDK"
export ANDROID_SDK_ROOT=/opt/android-sdk
mkdir -p "$ANDROID_SDK_ROOT/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 "$ANDROID_SDK_ROOT/cmdline-tools" && mv "$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools" "$ANDROID_SDK_ROOT/cmdline-tools/latest"
yes | "$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" --licenses >/dev/null || true
"$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" --install "platform-tools" "ndk;$NDK" "platforms;android-35" "build-tools;35.0.0" >/dev/null
export ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/$NDK
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)"
# Signed with the committed key, like every earlier build, so it installs over them.
export QT_ANDROID_KEYSTORE_PATH="$PWD/android/app/debug.keystore"
export QT_ANDROID_KEYSTORE_ALIAS=androiddebugkey
export QT_ANDROID_KEYSTORE_STORE_PASS=android
export QT_ANDROID_KEYSTORE_KEY_PASS=android
"$QT_ROOT/bin/qt-cmake" -S qt -B build-android -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DANDROID_SDK_ROOT="$ANDROID_SDK_ROOT" -DANDROID_NDK_ROOT="$ANDROID_NDK_ROOT" \
-DQT_HOST_PATH="$QT_HOST" -DQT_ANDROID_SIGN_APK=ON -DVERSION_CODE="$VERSION_CODE"
cmake --build build-android --target apk
apk=$(find build-android -name "*-signed.apk" | head -1)
test -n "$apk" || { find build-android -name "*.apk"; exit 1; }
cp "$apk" ultra-launcher.apk
printf '{"versionCode": %s, "commit": "%s"}\n' "$VERSION_CODE" "$COMMIT" > version.json
android/build.sh ultra-launcher.apk
echo "== release build-$VERSION_CODE"
server="${GITHUB_SERVER_URL:-https://git.site.latha.org}"
@@ -65,9 +53,9 @@ test -n "$token" || { echo "no GITEA_TOKEN/GITHUB_TOKEN in the environment"; exi
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\": \"Qt launcher built from $COMMIT.\"}" \
-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=@version.json" "$api/releases/$id/assets?name=version.json" >/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"