Only the -gplay edition may read a Google library. The google-services plugin's classpath moves from the root plugins block into droid/app/gplay-classpath.gradle and its application into droid/app/gplay.gradle, both applied only in a Gradle run whose tasks name gplay. Such a run refuses release or debug tasks beside it, so the Makefile and the release workflow build the normal and gplay APKs in separate runs, and the normal and F-Droid builds never resolve the plugin. The Moto check builds only the normal APK and no longer writes the Firebase config. CI checks the Gradle files with Kryon's google-free action, the release workflow checks the normal, per-ABI and -fdroid APKs and finds Play Billing in the -gplay APK, and the F-Droid workflow checks F-Droid's own APK.
177 lines
6.9 KiB
YAML
177 lines
6.9 KiB
YAML
name: Android Moto APK
|
|
|
|
"on":
|
|
workflow_dispatch:
|
|
inputs:
|
|
source_commit:
|
|
description: Full commit hash whose Release checks passed
|
|
required: true
|
|
verified_run:
|
|
description: Release run with successful Secret Scan and Test jobs
|
|
required: true
|
|
|
|
permissions:
|
|
contents: read
|
|
actions: read
|
|
|
|
jobs:
|
|
android:
|
|
name: Build signed Moto APK
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 60
|
|
steps:
|
|
- name: Require passing checks for the exact source commit
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
SOURCE_COMMIT: ${{ inputs.source_commit }}
|
|
VERIFIED_RUN: ${{ inputs.verified_run }}
|
|
run: |
|
|
python3 - <<'PY'
|
|
import json
|
|
import os
|
|
import re
|
|
import subprocess
|
|
|
|
commit = os.environ['SOURCE_COMMIT']
|
|
run_id = os.environ['VERIFIED_RUN']
|
|
repository = os.environ['GITHUB_REPOSITORY']
|
|
if not re.fullmatch(r'[0-9a-f]{40}', commit):
|
|
raise SystemExit('A full, immutable source commit is required')
|
|
if not re.fullmatch(r'[0-9]+', run_id):
|
|
raise SystemExit('A numeric Release run ID is required')
|
|
|
|
def api(path):
|
|
return json.loads(subprocess.check_output(['gh', 'api', path], text=True))
|
|
|
|
run = api(f'repos/{repository}/actions/runs/{run_id}')
|
|
if run['head_sha'] != commit or run['path'] != '.github/workflows/release.yml':
|
|
raise SystemExit('The Release checks must belong to the requested source commit')
|
|
jobs = api(f'repos/{repository}/actions/runs/{run_id}/jobs?per_page=100')['jobs']
|
|
for name in ('Secret Scan', 'Test (0/3)', 'Test (1/3)', 'Test (2/3)'):
|
|
checks = [job for job in jobs if job['name'] == name]
|
|
if len(checks) != 1 or checks[0]['conclusion'] != 'success':
|
|
raise SystemExit(f'{name} must have passed before signing')
|
|
print('Verified passing Secret Scan and all three Test shards for ' + commit)
|
|
PY
|
|
|
|
- name: Checkout verified source
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ inputs.source_commit }}
|
|
fetch-depth: 1
|
|
|
|
- name: Fetch Ziran packages
|
|
uses: ./.github/actions/ziran-packages
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
|
|
- name: Set up JDK 21
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
distribution: temurin
|
|
java-version: '21'
|
|
|
|
- name: Setup Gradle
|
|
uses: gradle/actions/setup-gradle@v3
|
|
|
|
- name: Cache Android SDK packages
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
${{ env.ANDROID_HOME }}/platforms/android-36
|
|
${{ env.ANDROID_HOME }}/build-tools/35.0.0
|
|
${{ env.ANDROID_HOME }}/ndk/28.2.13676358
|
|
${{ env.ANDROID_HOME }}/cmake/3.22.1
|
|
key: android-sdk-v2-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/android-sdk-packages.txt') }}
|
|
restore-keys: |
|
|
android-sdk-v2-${{ runner.os }}-${{ runner.arch }}-
|
|
|
|
- name: Verify and install Android SDK components
|
|
timeout-minutes: 20
|
|
run: python3 .github/scripts/install-android-sdk.py
|
|
|
|
- name: Install Android build dependencies
|
|
timeout-minutes: 15
|
|
run: .github/scripts/install-apt-packages.sh .github/apt/android-packages.txt
|
|
|
|
- name: Prepare Android signing key
|
|
env:
|
|
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
|
run: |
|
|
set -euo pipefail
|
|
umask 077
|
|
mkdir -p ~/.android
|
|
printf '%s' "$KEYSTORE_BASE64" | base64 -d > ~/.android/inbe-release.keystore
|
|
|
|
- name: Copy Android assets
|
|
run: ./scripts/copy-android-assets.sh
|
|
|
|
- name: Build signed ARMv7 release APK
|
|
env:
|
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
|
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
|
SOURCE_COMMIT: ${{ inputs.source_commit }}
|
|
run: |
|
|
set -euo pipefail
|
|
python3 - <<'PY'
|
|
import importlib.util
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
spec = importlib.util.spec_from_file_location('phone_check', 'scripts/phone-check.py')
|
|
check = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(check)
|
|
revision = os.environ['SOURCE_COMMIT']
|
|
assert subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip() == revision
|
|
assert check.app_tree(Path.cwd()) == check.app_tree(Path.cwd(), revision), 'App source differs from candidate'
|
|
PY
|
|
./droid/gradlew -p droid assembleRelease \
|
|
-Papp.onlyAbi=armeabi-v7a \
|
|
-Pkeystore.path="$HOME/.android/inbe-release.keystore" \
|
|
-Pkeystore.alias="$KEY_ALIAS" \
|
|
-Pkeystore.password="$KEYSTORE_PASSWORD" \
|
|
--stacktrace
|
|
VERSION=$(python3 scripts/check-version.py --print-version)
|
|
mkdir -p build/release/moto
|
|
cp droid/app/build/outputs/apk/release/app-armeabi-v7a-release.apk "build/release/moto/inbe-$VERSION-moto.apk"
|
|
"$ANDROID_HOME/build-tools/35.0.0/apksigner" verify --print-certs "build/release/moto/inbe-$VERSION-moto.apk"
|
|
printf '%s\n' "$SOURCE_COMMIT" > build/release/moto/source-commit.txt
|
|
(
|
|
cd build/release/moto
|
|
sha256sum "inbe-$VERSION-moto.apk" > "inbe-$VERSION-moto.apk.sha256"
|
|
)
|
|
python3 - <<'PY'
|
|
import hashlib
|
|
import importlib.util
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
spec = importlib.util.spec_from_file_location('phone_check', 'scripts/phone-check.py')
|
|
check = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(check)
|
|
root = Path.cwd()
|
|
revision = os.environ['SOURCE_COMMIT']
|
|
content = check.app_tree(root, revision)
|
|
assert check.app_tree(root) == content, 'App source changed during build'
|
|
apk = next(Path('build/release/moto').glob('inbe-*-moto.apk'))
|
|
receipt = dict(schema=1, status='passed', source_commit=revision, app_tree=content,
|
|
apk=dict(sha256=hashlib.sha256(apk.read_bytes()).hexdigest(), **check.apk_identity(apk)),
|
|
workflow_run=os.environ['GITHUB_SERVER_URL'] + '/' + os.environ['GITHUB_REPOSITORY'] +
|
|
'/actions/runs/' + os.environ['GITHUB_RUN_ID'])
|
|
(apk.parent / 'build-receipt.json').write_text(json.dumps(receipt, indent=2) + '\n')
|
|
PY
|
|
|
|
- name: Remove signing key
|
|
if: always()
|
|
run: rm -f ~/.android/inbe-release.keystore
|
|
|
|
- name: Upload signed Moto APK
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: android-moto
|
|
path: build/release/moto/*
|
|
if-no-files-found: error
|