Recover corrupt Android SDK downloads and start release builds earlier

This commit is contained in:
waozi committed 2026-10-22 22:43:10 -03:00
1 parent 22d642b7b8
commit f83b44fd3e
12 files changed
+424 -94

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
platforms;android-36
build-tools;35.0.0
ndk;28.2.13676358
cmake;3.22.1
+1
View File
@@ -0,0 +1 @@
python3-fonttools
+113
View File
@@ -0,0 +1,113 @@
#!/usr/bin/env python3
"""Install the pinned SDK components, retrying downloads in fresh staging areas."""
from pathlib import Path
import argparse
import os
import re
import shutil
import subprocess
import tempfile
import time
import xml.etree.ElementTree as ET
import zipfile
ROOT = Path(__file__).resolve().parents[2]
def component_path(root, package):
if not re.fullmatch(r"(?:platforms;android-[0-9]+|(?:build-tools|ndk|cmake);[0-9]+\.[0-9]+\.[0-9]+)", package):
raise ValueError("invalid pinned SDK component: " + package)
return root.joinpath(*package.split(";"))
def valid(root, package):
directory = component_path(root, package)
try:
document = ET.parse(directory / "package.xml")
if not any(element.tag.rsplit("}", 1)[-1] == "localPackage" and
element.get("path") == package for element in document.iter()):
return False
kind, version = package.split(";")
if kind == "platforms":
with zipfile.ZipFile(directory / "android.jar") as archive:
return archive.testzip() is None
properties = (directory / "source.properties").read_text()
if not re.search(r"^Pkg\.Revision\s*=\s*" + re.escape(version) + r"\s*$", properties, re.M):
return False
if kind == "cmake":
command = [directory / "bin/cmake", "--version"]
elif kind == "build-tools":
command = [directory / "aapt2", "version"]
else:
command = [next(directory.glob("toolchains/llvm/prebuilt/*/bin/clang")), "--version"]
result = subprocess.run(command, capture_output=True, text=True, timeout=15)
if result.returncode != 0:
return False
if kind == "cmake":
expected = "cmake version " + re.escape(version) + r"(?:-[0-9A-Za-z.]+)?"
return re.fullmatch(expected, result.stdout.splitlines()[0]) is not None
return True
except (OSError, UnicodeError, ET.ParseError, zipfile.BadZipFile, StopIteration, IndexError,
subprocess.TimeoutExpired):
return False
def install(root, packages, manager, sleep=time.sleep):
root = Path(root).resolve()
manager = Path(manager).resolve(strict=True)
root.mkdir(parents=True, exist_ok=True)
for package in packages:
destination = component_path(root, package)
if valid(root, package):
print("Android SDK: verified cached " + package, flush=True)
continue
for attempt in range(1, 4):
print(f"Android SDK: install {package}, attempt {attempt}/3", flush=True)
# sdkmanager keeps partial archives beneath its SDK root. A new
# stage guarantees that a corrupt ZIP cannot survive the retry.
with tempfile.TemporaryDirectory(prefix=".inbe-sdk-", dir=root) as temporary:
stage = Path(temporary)
if (root / "licenses").is_dir():
shutil.copytree(root / "licenses", stage / "licenses")
environment = dict(os.environ, ANDROID_HOME=str(stage), ANDROID_SDK_ROOT=str(stage))
try:
result = subprocess.run([manager, "--sdk_root=" + str(stage), package],
input=b"y\n" * 128, env=environment, timeout=600)
except subprocess.TimeoutExpired:
result = None
if result is not None and result.returncode == 0 and valid(stage, package):
source = component_path(stage, package)
destination.parent.mkdir(parents=True, exist_ok=True)
if destination.exists():
destination.rename(stage / "incomplete-component")
source.rename(destination)
if (stage / "licenses").is_dir():
shutil.copytree(stage / "licenses", root / "licenses", dirs_exist_ok=True)
if not valid(root, package):
raise RuntimeError("SDK component failed validation after installation: " + package)
break
print("Android SDK: rejected incomplete or invalid " + package, flush=True)
if attempt == 3:
raise RuntimeError("Android SDK download failed after three fresh attempts: " + package)
sleep(attempt * 2)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--sdk-root", type=Path,
default=os.environ.get("ANDROID_SDK_ROOT") or os.environ.get("ANDROID_HOME"))
parser.add_argument("--sdkmanager", type=Path)
parser.add_argument("--packages", type=Path, default=ROOT / ".github/android-sdk-packages.txt")
args = parser.parse_args()
if args.sdk_root is None:
parser.error("ANDROID_SDK_ROOT or ANDROID_HOME must name the job's SDK")
manager = args.sdkmanager or args.sdk_root / "cmdline-tools/latest/bin/sdkmanager"
if args.sdkmanager is None and not manager.is_file():
manager = Path(shutil.which("sdkmanager") or manager)
packages = [line.strip() for line in args.packages.read_text().splitlines()
if line.strip() and not line.lstrip().startswith("#")]
install(args.sdk_root, packages, manager)
if __name__ == "__main__":
main()
+9 -12
View File
@@ -47,11 +47,11 @@ jobs:
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)'):
for name in ('Secret Scan', 'Test (0/3)', 'Test (1/3)', 'Test (2/3)', 'Visual Tests'):
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)
print('Verified passing Secret Scan, all three Test shards and Visual Tests for ' + commit)
PY
- name: Checkout verified source
@@ -82,19 +82,16 @@ jobs:
with:
path: |
${{ env.ANDROID_HOME }}/platforms/android-36
${{ env.ANDROID_HOME }}/build-tools/34.0.0
${{ env.ANDROID_HOME }}/build-tools/35.0.0
${{ env.ANDROID_HOME }}/ndk/28.2.13676358
${{ env.ANDROID_HOME }}/cmake/3.22.1
key: android-moto-sdk-${{ runner.os }}-api36-ndk28-cmake322
key: android-sdk-v2-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/android-sdk-packages.txt') }}
restore-keys: |
android-sdk-${{ runner.os }}-${{ runner.arch }}-
android-sdk-v2-${{ runner.os }}-${{ runner.arch }}-
- name: Install Android SDK components
run: |
set -euo pipefail
SDKMANAGER="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
yes | "$SDKMANAGER" --licenses >/dev/null || true
"$SDKMANAGER" "platforms;android-36" "build-tools;34.0.0" "ndk;28.2.13676358" "cmake;3.22.1"
- name: Verify and install Android SDK components
timeout-minutes: 20
run: python3 .github/scripts/install-android-sdk.py
- name: Prepare Android signing key
env:
@@ -129,7 +126,7 @@ jobs:
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/34.0.0/apksigner" verify --print-certs "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
+73 -32
View File
@@ -133,38 +133,6 @@ jobs:
- name: Run Tests
run: sh scripts/test-shard.sh ${{ matrix.shard }} 3
- name: Require Visual Tests
if: matrix.shard == 1
run: make visual-test
- name: Save Visual Test Evidence
if: always() && matrix.shard == 1
uses: actions/upload-artifact@v4
with:
name: native-visual-tests
path: |
build/visual-test/
build/native-visual-test/
build/entity-profile-ui-test/
build/native-zoom-test/*.png
build/native-zoom-test/app.log
build/launcher-ui-test/
build/locale-render-ui-test/
build/native-screenshot-test/
build/native-text-pixels-test/*.png
build/native-text-pixels-test/*.log
build/settings-sidebar-test/
build/startup-quit-test/
build/lumi-ui-test/
build/lumi-history-ui-test/
build/habits-table-ui-test/
build/lists-ui-test/
build/sync-review-ui-test/
build/data-back-ui-test/
build/leaderboard-ui-test/
build/practice-images-ui-test/
retention-days: 7
- name: Read sync test server revision
if: matrix.shard == 0
id: sync-test-server
@@ -194,6 +162,79 @@ jobs:
make -C .test-server build
make sync-server-test DAOCHI_BIN="$GITHUB_WORKSPACE/.test-server/daochi"
visual-test:
name: Visual Tests
runs-on: ubuntu-latest
needs: guard-package-urls
timeout-minutes: 120
env:
APT_CACHE_DIR: /tmp/apt-cache
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 1
lfs: true
- 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 Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- name: Cache Test apt packages
uses: actions/cache@v4
with:
path: ${{ env.APT_CACHE_DIR }}
key: test-apt-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/apt/test-packages.txt') }}
restore-keys: |
test-apt-${{ runner.os }}-${{ runner.arch }}-
- name: Install Test Dependencies
timeout-minutes: 15
run: .github/scripts/install-apt-packages.sh .github/apt/test-packages.txt
- name: Require Visual Tests
run: make visual-test
- name: Save Visual Test Evidence
if: always()
uses: actions/upload-artifact@v4
with:
name: native-visual-tests
path: |
build/visual-test/
build/native-visual-test/
build/entity-profile-ui-test/
build/native-zoom-test/*.png
build/native-zoom-test/app.log
build/launcher-ui-test/
build/locale-render-ui-test/
build/native-screenshot-test/
build/native-text-pixels-test/*.png
build/native-text-pixels-test/*.log
build/settings-sidebar-test/
build/startup-quit-test/
build/lumi-ui-test/
build/lumi-history-ui-test/
build/habits-table-ui-test/
build/lists-ui-test/
build/sync-review-ui-test/
build/data-back-ui-test/
build/leaderboard-ui-test/
build/practice-images-ui-test/
retention-days: 7
browser-addons:
# Builds the web app once, packages it for Chrome and Firefox, and runs
# the smoke test in both browsers. It runs beside the tests; a failure in
+4 -1
View File
@@ -47,7 +47,6 @@ jobs:
apt-get update
apt-get install -y --no-install-recommends build-essential jimsh libssl-dev python3-fonttools openjdk-21-jdk-headless fdroidserver git-lfs
update-alternatives --set java /usr/lib/jvm/java-21-openjdk-amd64/bin/java
sdkmanager 'platforms;android-36' 'build-tools;34.0.0' 'ndk;28.2.13676358' 'cmake;3.22.1'
- name: Checkout candidate
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
@@ -57,6 +56,10 @@ jobs:
lfs: true
persist-credentials: false
- name: Verify and install Android SDK components
timeout-minutes: 20
run: python3 build/xyz.waozi.inbe/.github/scripts/install-android-sdk.py
- name: Build and scan with F-Droid without cached package sources
run: python3 build/xyz.waozi.inbe/scripts/check-fdroid.py
+99 -47
View File
@@ -81,7 +81,7 @@ jobs:
name: Test (${{ matrix.shard }}/3)
runs-on: ubuntu-latest
needs: secret-scan
# Run the complete test, visual and package compatibility suites.
# Run every unit shard and the package compatibility suite.
timeout-minutes: 120
strategy:
fail-fast: false
@@ -128,18 +128,61 @@ jobs:
- name: Run Tests
run: sh scripts/test-shard.sh ${{ matrix.shard }} 3
- name: Require Visual Tests
if: matrix.shard == 1
run: make visual-test
- name: Run Packages Across App Versions
if: matrix.shard == 2
run: make package-compat-test
env:
GITHUB_TOKEN: ${{ github.token }}
visual-test:
name: Visual Tests
runs-on: ubuntu-latest
needs: secret-scan
timeout-minutes: 120
env:
APT_CACHE_DIR: /tmp/apt-cache
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.revision || github.sha }}
fetch-depth: 1
lfs: true
- name: Fetch Ziran packages
uses: ./.github/actions/ziran-packages
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
# Robolectric's Android 16 (SDK 36) sandbox needs Java 21.
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- name: Cache Test apt packages
uses: actions/cache@v4
with:
path: ${{ env.APT_CACHE_DIR }}
key: test-apt-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/apt/test-packages.txt') }}
restore-keys: |
test-apt-${{ runner.os }}-${{ runner.arch }}-
- name: Install Test Dependencies
timeout-minutes: 15
run: .github/scripts/install-apt-packages.sh .github/apt/test-packages.txt
- name: Require Visual Tests
run: make visual-test
- name: Save Visual Test Evidence
if: always() && matrix.shard == 1
if: always()
uses: actions/upload-artifact@v4
with:
name: release-visual-tests
@@ -208,7 +251,7 @@ jobs:
name: Build Web
runs-on: ubuntu-latest
timeout-minutes: 60
needs: test
needs: secret-scan
env:
APT_CACHE_DIR: /tmp/apt-cache
@@ -264,7 +307,7 @@ jobs:
name: Build Chrome Extension
runs-on: ubuntu-latest
timeout-minutes: 60
needs: test
needs: secret-scan
env:
APT_CACHE_DIR: /tmp/apt-cache
@@ -320,7 +363,7 @@ jobs:
name: Build Firefox Add-on
runs-on: ubuntu-latest
timeout-minutes: 60
needs: test
needs: secret-scan
env:
APT_CACHE_DIR: /tmp/apt-cache
@@ -377,7 +420,7 @@ jobs:
name: Build Linux AppImage
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
needs: test
needs: secret-scan
strategy:
fail-fast: false
matrix:
@@ -495,7 +538,7 @@ jobs:
name: Build Linux Deb
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
needs: test
needs: secret-scan
strategy:
fail-fast: false
matrix:
@@ -556,7 +599,7 @@ jobs:
name: Build Linux RPM
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
needs: test
needs: secret-scan
strategy:
fail-fast: false
matrix:
@@ -617,7 +660,7 @@ jobs:
name: Build Linux Snap
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
needs: test
needs: secret-scan
strategy:
fail-fast: false
matrix:
@@ -675,7 +718,7 @@ jobs:
name: Build Linux Flatpak
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
needs: test
needs: secret-scan
strategy:
fail-fast: false
matrix:
@@ -733,7 +776,7 @@ jobs:
name: Build Windows
runs-on: ubuntu-latest
timeout-minutes: 60
needs: test
needs: secret-scan
env:
APT_CACHE_DIR: /tmp/apt-cache
@@ -798,7 +841,9 @@ jobs:
name: Build Android
runs-on: ubuntu-latest
timeout-minutes: 60
needs: test
needs: secret-scan
env:
APT_CACHE_DIR: /tmp/apt-cache
steps:
- name: Checkout Repository
@@ -807,6 +852,40 @@ jobs:
ref: ${{ inputs.revision || github.sha }}
fetch-depth: 1
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- 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: Cache Android apt packages
uses: actions/cache@v4
with:
path: ${{ env.APT_CACHE_DIR }}
key: android-apt-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/apt/android-packages.txt') }}
restore-keys: |
android-apt-${{ runner.os }}-${{ runner.arch }}-
- name: Install translation check dependency
timeout-minutes: 15
run: .github/scripts/install-apt-packages.sh .github/apt/android-packages.txt
- name: Fetch Ziran packages
uses: ./.github/actions/ziran-packages
@@ -815,47 +894,18 @@ jobs:
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: Install translation check dependency
run: sudo apt-get update && sudo apt-get install -y python3-fonttools
- name: Cache Android SDK packages
uses: actions/cache@v4
with:
path: |
${{ env.ANDROID_HOME }}/platforms/android-36
${{ env.ANDROID_HOME }}/build-tools/34.0.0
${{ env.ANDROID_HOME }}/ndk/25.1.8937393
${{ env.ANDROID_HOME }}/ndk/28.2.13676358
${{ env.ANDROID_HOME }}/cmake/3.22.1
key: android-sdk-${{ runner.os }}-${{ runner.arch }}-api36-bt34-ndk25-ndk28-cmake322
restore-keys: |
android-sdk-${{ runner.os }}-${{ runner.arch }}-
- name: Cache Android native build
uses: actions/cache@v4
with:
path: |
droid/app/.cxx
droid/app/build/intermediates/cxx
key: android-native-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'src/**/*.c', 'src/**/*.h', 'ziran.lock') }}
key: android-native-v2-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'droid/build.gradle', 'src/**/*.zi', 'src/**/*.c', 'src/**/*.h', 'ziran.lock') }}
restore-keys: |
android-native-${{ runner.os }}-${{ runner.arch }}-
- name: Install Android SDK Components
run: |
set -euo pipefail
SDKMANAGER="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
yes | "$SDKMANAGER" --licenses >/dev/null || true
"$SDKMANAGER" "platforms;android-36" "build-tools;34.0.0" "ndk;25.1.8937393" "cmake;3.22.1"
android-native-v2-${{ runner.os }}-${{ runner.arch }}-
- name: Prepare Android signing key
env:
@@ -945,6 +995,8 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
needs:
- test
- visual-test
- build-web
- build-chrome-extension
- build-firefox-addons
+1
View File
@@ -21,6 +21,7 @@ android {
useLibrary 'android.test.base', false
namespace 'xyz.waozi.inbe'
compileSdk 36
buildToolsVersion "35.0.0"
ndkVersion "28.2.13676358"
compileOptions {
+4
View File
@@ -1,5 +1,9 @@
# Android tests: Ziran host modules, Gradle tests, smoke and device checks.
.PHONY: android-sdk-install-test
android-sdk-install-test:
python3 tests/android_sdk_install_test.py
.PHONY: android-source-test
android-source-test: $(ZI2ZIR_BIN) | build-laws
ZI_CHECK_DEFINES="ANDROID_BUILD KRYON_ANDROID_HOST __aarch64__" \
+1
View File
@@ -156,6 +156,7 @@ test: practice-downloads-test
test: practice-narration-test
test: practice-narration-keys-test
test: practice-narration-snapshot-test
test: android-sdk-install-test
## Local parity with the ci.yml gate: unit tests plus the web build (emcc).
## Run before pushing to catch web-only breakage -- e.g. code under
+113
View File
@@ -0,0 +1,113 @@
"""SDK cache validation and corrupt-download recovery never skip required tools."""
import importlib.util
import json
import os
import re
from pathlib import Path
import tempfile
import unittest
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location("android_sdk", ROOT / ".github/scripts/install-android-sdk.py")
sdk = importlib.util.module_from_spec(spec)
spec.loader.exec_module(sdk)
PACKAGE = "cmake;3.22.1"
def component(root, version="3.22.1"):
directory = root / "cmake/3.22.1"
(directory / "bin").mkdir(parents=True)
(directory / "source.properties").write_text("Pkg.Revision=" + version + "\n")
(directory / "package.xml").write_text('<repository><localPackage path="' + PACKAGE + '"/></repository>')
binary = directory / "bin/cmake"
binary.write_text("#!/bin/sh\nprintf '%s\\n' 'cmake version " + version + "'\n")
binary.chmod(0o755)
class AndroidSdkInstallTest(unittest.TestCase):
def setUp(self):
temporary = tempfile.TemporaryDirectory(prefix="inbe-sdk-fixture-")
self.addCleanup(temporary.cleanup)
self.root = Path(temporary.name)
self.manager = self.root / "sdkmanager"
self.manager.write_text("#!/usr/bin/env python3\n" + '''
import json, os, pathlib, shutil, sys
root = pathlib.Path(__file__).parent
stage = pathlib.Path(next(x.split('=',1)[1] for x in sys.argv if x.startswith('--sdk_root=')))
state = root / 'attempts.json'
attempts = json.loads(state.read_text()) if state.exists() else []
assert all(not pathlib.Path(old).exists() for old in attempts), 'partial download reused'
attempts.append(str(stage)); state.write_text(json.dumps(attempts))
(stage / '.temp').mkdir(); (stage / '.temp/corrupt.zip').write_bytes(b'not a zip')
if len(attempts) == 1 or os.environ.get('SDK_FIXTURE_ALWAYS_FAIL'):
print('Error on ZipFile unknown archive', file=sys.stderr); sys.exit(1)
shutil.copytree(root / 'download/cmake', stage / 'cmake')
''')
self.manager.chmod(0o755)
component(self.root / "download")
def test_verified_cache_needs_no_network_or_download(self):
component(self.root)
sdk.install(self.root, [PACKAGE], self.manager, sleep=lambda _: None)
self.assertFalse((self.root / "attempts.json").exists())
def test_corrupt_archive_is_retried_in_a_new_stage(self):
(self.root / "cmake/3.22.1").mkdir(parents=True)
(self.root / "cmake/3.22.1/partial.zip").write_bytes(b"broken old cache")
sdk.install(self.root, [PACKAGE], self.manager, sleep=lambda _: None)
self.assertEqual(len(json.loads((self.root / "attempts.json").read_text())), 2)
self.assertTrue(sdk.valid(self.root, PACKAGE))
self.assertFalse((self.root / "cmake/3.22.1/partial.zip").exists())
self.assertFalse(list(self.root.glob(".inbe-sdk-*")))
def test_repeated_failure_stops_and_preserves_unrelated_components(self):
other = self.root / "ndk/keep.txt"
other.parent.mkdir()
other.write_text("untouched")
with mock.patch.dict(os.environ, SDK_FIXTURE_ALWAYS_FAIL="1"):
with self.assertRaisesRegex(RuntimeError, "three fresh attempts"):
sdk.install(self.root, [PACKAGE], self.manager, sleep=lambda _: None)
self.assertEqual(other.read_text(), "untouched")
self.assertEqual(len(json.loads((self.root / "attempts.json").read_text())), 3)
self.assertFalse(list(self.root.glob(".inbe-sdk-*")))
def test_wrong_version_and_unsafe_package_path_are_rejected(self):
component(self.root, "3.21.0")
self.assertFalse(sdk.valid(self.root, PACKAGE))
for package in ("cmake;../outside", "ndk;/", "unknown;3.22.1"):
with self.subTest(package=package), self.assertRaises(ValueError):
sdk.component_path(self.root, package)
def test_official_android_cmake_build_suffix_is_valid(self):
component(self.root)
binary = self.root / "cmake/3.22.1/bin/cmake"
binary.write_text("#!/bin/sh\nprintf '%s\\n' 'cmake version 3.22.1-g37088a8'\n")
self.assertTrue(sdk.valid(self.root, PACKAGE))
def test_pinned_components_match_the_actual_android_build(self):
gradle = (ROOT / "droid/app/build.gradle").read_text()
makefile = (ROOT / "Makefile").read_text()
expected = {"platforms;android-" + re.search(r"compileSdk (\d+)", gradle)[1],
"build-tools;" + re.search(r'buildToolsVersion "([0-9.]+)"', gradle)[1],
"ndk;" + re.search(r'ndkVersion "([0-9.]+)"', gradle)[1],
"cmake;" + re.search(r"ANDROID_CMAKE_DIR \?= .*?/cmake/([0-9.]+)", makefile)[1]}
actual = set((ROOT / ".github/android-sdk-packages.txt").read_text().splitlines())
self.assertEqual(actual, expected)
def test_release_builds_start_early_but_publication_keeps_all_gates(self):
workflow = (ROOT / ".github/workflows/release.yml").read_text()
publication = workflow.split("\n release:\n", 1)[1].split("\n outputs:", 1)[0]
self.assertIn(" - test", publication.splitlines())
self.assertIn(" - verify-fdroid", publication.splitlines())
self.assertIn(" - visual-test", publication.splitlines())
self.assertIn("\n visual-test:\n", workflow)
android = workflow.split("\n build-android:\n", 1)[1].split("\n release:\n", 1)[0]
self.assertIn("needs: secret-scan", android)
self.assertLess(android.index("Verify and install Android SDK components"),
android.index("Fetch Ziran packages"))
self.assertNotIn("ndk/25.1.8937393", android)
if __name__ == "__main__":
unittest.main()
+2 -2
View File
@@ -225,13 +225,13 @@ class MotoWorkflowGateTest(unittest.TestCase):
def passing_jobs(self):
return [{"name": name, "conclusion": "success"} for name in
("Secret Scan", "Test (0/3)", "Test (1/3)", "Test (2/3)")]
("Secret Scan", "Test (0/3)", "Test (1/3)", "Test (2/3)", "Visual Tests")]
def test_all_three_shards_allow_the_exact_release(self):
self.check_run(self.passing_jobs())
def test_missing_failed_cancelled_and_duplicate_checks_are_rejected(self):
for index in range(4):
for index in range(len(self.passing_jobs())):
with self.subTest(index=index, state="missing"), self.assertRaises(SystemExit):
self.check_run(self.passing_jobs()[:index] + self.passing_jobs()[index + 1:])
for state in ("failure", "cancelled", "skipped", None):