Files
fileworkbench/scripts/test-build-config.py
zemion db873063f8
Verify source and build Android / android (push) Canceled after 0s
initial commit v 0.2.0
2026-09-24 22:49:27 +02:00

46 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""Regression checks for the release-pin guard; no Gradle execution or downloads."""
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
ROOT = Path(__file__).resolve().parent.parent
passed = 0
cases = [
("baseline", None, None, None, True),
("stale Gradle distribution", "gradle/wrapper/gradle-wrapper.properties", "gradle-8.14.5-bin", "gradle-9.7.1-bin", False),
("wrong daemon JVM", "gradle/gradle-daemon-jvm.properties", "toolchainVersion=17", "toolchainVersion=25", False),
("duplicate JVM alias", "build.gradle.kts", "alias(libs.plugins.kotlin.jvm) apply false",
"alias(libs.plugins.kotlin.jvm) apply false\n alias(libs.plugins.kotlin.jvm) apply false", False),
("catalog maps two aliases to JVM", "gradle/libs.versions.toml", 'id = "org.jetbrains.kotlin.android"',
'id = "org.jetbrains.kotlin.jvm"', False),
("extra direct plugin request", "build.gradle.kts", "plugins {",
'plugins {\n id("org.jetbrains.kotlin.jvm") apply false', False),
("stale shell bootstrap", "scripts/bootstrap-wrapper.sh", "v8.14.5/", "v8.13.0/", False),
("stale Windows bootstrap", "scripts/bootstrap-wrapper.ps1", "v8.14.5/", "v8.13.0/", False),
]
for name, relative, old, new, expect_success in cases:
with tempfile.TemporaryDirectory(prefix="fileworkbench-build-config-") as work:
target = Path(work) / "project"
shutil.copytree(ROOT, target, ignore=shutil.ignore_patterns("out", "build", ".gradle", ".git", ".idea", "local.properties", "__pycache__"))
if relative:
file = target / relative
source = file.read_text(encoding="utf-8")
assert old in source, name + ": expected fixture content missing"
file.write_text(source.replace(old, new, 1), encoding="utf-8")
else:
# Local IDE/SDK state is legitimate on the developer's machine.
# The source-package check must not accidentally prohibit ordinary builds.
(target / "local.properties").write_text("sdk.dir=/example/local/sdk\n", encoding="utf-8")
(target / ".idea").mkdir()
result = subprocess.run([sys.executable, str(target / "scripts/check-build-config.py")],
text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if (result.returncode == 0) != expect_success:
print(result.stdout)
raise SystemExit("FAIL " + name)
passed += 1
print("PASS " + name + (" accepted" if expect_success else " rejected"))
print(f"Build-guard regression: {passed}/{len(cases)} cases passed. Not a Gradle build.")