summaryrefslogtreecommitdiff
path: root/.github/scripts/tests/test_linux_image_publication_policy.py
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
committerChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
commitffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch)
tree1269efa852935b183daae4bb33a58d1b4d2ffb53 /.github/scripts/tests/test_linux_image_publication_policy.py
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to '.github/scripts/tests/test_linux_image_publication_policy.py')
-rw-r--r--.github/scripts/tests/test_linux_image_publication_policy.py252
1 files changed, 250 insertions, 2 deletions
diff --git a/.github/scripts/tests/test_linux_image_publication_policy.py b/.github/scripts/tests/test_linux_image_publication_policy.py
index cb88ac95..57d0ce1f 100644
--- a/.github/scripts/tests/test_linux_image_publication_policy.py
+++ b/.github/scripts/tests/test_linux_image_publication_policy.py
@@ -1,5 +1,10 @@
+import fnmatch
+import os
import pathlib
import re
+import subprocess
+import tempfile
+import textwrap
import unittest
@@ -10,10 +15,10 @@ WARM = (ROOT / ".github/workflows/warm-dependency-caches.yml").read_text()
CLASSIFIER = (ROOT / ".github/scripts/is-linux-ci-image-input.sh").read_text()
-def job(name: str) -> str:
+def job(name: str, workflow: str = PUBLISH) -> str:
match = re.search(
rf"^ {re.escape(name)}:\n(?P<body>.*?)(?=^ [a-z][a-z0-9-]*:\n|\Z)",
- PUBLISH,
+ workflow,
re.MULTILINE | re.DOTALL,
)
if not match:
@@ -22,6 +27,219 @@ def job(name: str) -> str:
class LinuxImagePublicationPolicyTests(unittest.TestCase):
+ def test_armhf_cross_cache_import_and_export_share_registry_destination(self):
+ metadata = job("metadata")
+ for package_root in ("ghcr.io/wsjtx/wsjtx", "ghcr.io/wsjtx/wsjtx-internal"):
+ self.assertIn(
+ f"armhf_cross_cache_from=type=registry,ref={package_root}/linux-armhf-cross-bookworm:buildcache",
+ metadata,
+ )
+ cross = job("build-armhf-cross")
+ self.assertIn("cache-from: ${{ needs.metadata.outputs.armhf_cross_cache_from }}", cross)
+ self.assertIn(
+ "cache-to: type=registry,ref=${{ needs.metadata.outputs.package_root }}/linux-armhf-cross-bookworm:buildcache,mode=max",
+ cross,
+ )
+
+ def select_warmers(self, event, *, target="", schedule="", paths=()):
+ selector = re.search(
+ r" run: \|\n(?P<body>.*?)(?=^ refresh-linux-images:)",
+ WARM,
+ re.MULTILINE | re.DOTALL,
+ ).group("body")
+ git_stub = """
+git() {
+ case "$1" in
+ cat-file) return 0 ;;
+ diff) printf '%s\\n' "$CHANGED_PATHS" ;;
+ *) return 2 ;;
+ esac
+}
+"""
+ with tempfile.TemporaryDirectory() as directory:
+ output = pathlib.Path(directory) / "output"
+ result = subprocess.run(
+ ["bash", "-c", git_stub + textwrap.dedent(selector)],
+ cwd=ROOT,
+ env={
+ **os.environ,
+ "EVENT_NAME": event,
+ "TARGETS": target,
+ "SCHEDULE": schedule,
+ "BEFORE_SHA": "previous",
+ "CURRENT_SHA": "current",
+ "CHANGED_PATHS": "\n".join(paths),
+ "HAMLIB_BRANCH": "4.7.2",
+ "GITHUB_OUTPUT": str(output),
+ "GITHUB_STEP_SUMMARY": str(pathlib.Path(directory) / "summary"),
+ },
+ capture_output=True,
+ text=True,
+ timeout=10,
+ )
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ return dict(line.split("=", 1) for line in output.read_text().splitlines())
+
+ def test_macos_warmer_selection_routes_both_architectures(self):
+ cases = [
+ ({"event": "workflow_dispatch", "target": "macos-x86_64"}, "false", "true"),
+ ({"event": "workflow_dispatch", "target": "macos-arm64"}, "true", "false"),
+ ({"event": "workflow_dispatch", "target": "macos"}, "true", "true"),
+ ({"event": "workflow_dispatch", "target": "all"}, "true", "true"),
+ ({"event": "workflow_dispatch", "target": "linux"}, "false", "false"),
+ ({"event": "schedule", "schedule": "23 10 * * 1"}, "true", "true"),
+ ]
+ for path in (
+ ".github/workflows/build-macos.yml", ".github/actions/warm-macos-deps/action.yml",
+ ".github/scripts/install-xpack-gfortran-macos.sh", ".github/scripts/build-qt-macos.sh",
+ ".github/scripts/macos-qt-cache-key.sh", ".github/scripts/verify-macos-static-archives.sh",
+ ".github/workflows/ci.yml", ".github/workflows/release.yml",
+ ):
+ cases.append(({"event": "push", "paths": [path]}, "true", "true"))
+ for inputs, arm, intel in cases:
+ with self.subTest(inputs=inputs):
+ outputs = self.select_warmers(**inputs)
+ self.assertEqual(outputs["macos_arm64"], arm)
+ self.assertEqual(outputs["macos_x86_64"], intel)
+
+ def test_asan_warmer_selection(self):
+ cases = [
+ ({"event": "schedule", "schedule": "23 10 * * 1"}, "true", "none"),
+ ({"event": "workflow_dispatch", "target": "linux-asan-ubsan"}, "true", "none"),
+ ({"event": "workflow_dispatch", "target": "all"}, "true", "normal"),
+ ({"event": "workflow_dispatch", "target": "linux-tsan"}, "false", "tsan"),
+ ({"event": "push", "paths": [".github/scripts/build-hamlib-linux.sh"]}, "false", "normal"),
+ ({"event": "push", "paths": [".github/scripts/build-qt-tsan-linux.sh"]}, "false", "tsan"),
+ ({"event": "push", "paths": ["CMakeLists.txt", ".github/scripts/verify-linux-ci-image.sh"]}, "true", "normal-and-tsan"),
+ ({"event": "push", "paths": ["mainwindow.cpp"]}, "false", "none"),
+ ]
+ for arguments, selected, image_set in cases:
+ with self.subTest(arguments=arguments):
+ outputs = self.select_warmers(**arguments)
+ self.assertEqual(outputs["linux_asan_ubsan"], selected)
+ self.assertEqual(outputs["image_set"], image_set)
+
+ def test_armhf_warmer_selection(self):
+ cases = [
+ ({"event": "schedule", "schedule": "23 10 * * 1"}, "true", "none"),
+ ({"event": "workflow_dispatch", "target": "linux-armhf"}, "true", "none"),
+ ({"event": "workflow_dispatch", "target": "all"}, "true", "normal"),
+ ({"event": "workflow_dispatch", "target": "linux-tsan"}, "false", "tsan"),
+ ({"event": "push", "paths": [".github/images/linux-ci/Dockerfile.armhf-cross"]}, "false", "normal"),
+ ({"event": "push", "paths": ["mainwindow.cpp"]}, "false", "none"),
+ ]
+ for arguments, selected, image_set in cases:
+ with self.subTest(arguments=arguments):
+ outputs = self.select_warmers(**arguments)
+ self.assertEqual(outputs["linux_armhf"], selected)
+ self.assertEqual(outputs["image_set"], image_set)
+
+ def test_armhf_build_inputs_select_warming(self):
+ push_filters = re.findall(r'^ - "([^"]+)"$', WARM.split(" schedule:", 1)[0], re.MULTILINE)
+ for path in (
+ ".github/workflows/build-linux.yml",
+ ".github/scripts/build-linux-armhf-cross.sh",
+ ".github/scripts/audit-armhf-cross-build.sh",
+ ".github/cmake/armhf-toolchain.cmake",
+ ".github/scripts/linux-artifact-validation.sh",
+ "CMakeLists.txt", "CMake/Sources.cmake", "tests/unit/CMakeLists.txt",
+ ):
+ with self.subTest(path=path):
+ self.assertTrue(any(fnmatch.fnmatchcase(path, pattern) for pattern in push_filters))
+ outputs = self.select_warmers("push", paths=[path])
+ self.assertEqual(outputs["linux_armhf"], "true")
+ self.assertEqual(outputs["image_set"], "none")
+
+ def test_armhf_warmers_share_configuration_and_serialize(self):
+ standalone = job("warm-linux-armhf-ccache", WARM)
+ published = job("warm-armhf-ccache")
+ for warmer in (standalone, published):
+ for required in (
+ "github.ref == 'refs/heads/develop'",
+ "uses: ./.github/workflows/build-linux.yml", "arch: armhf",
+ "armhf_build_only: true", "allow_stale_image: false",
+ "recache: false", "save_ccache: true",
+ "group: armhf-ccache-develop", "cancel-in-progress: false",
+ "contents: read", "packages: read",
+ ):
+ self.assertIn(required, warmer)
+ self.assertNotIn("packages: write", warmer)
+ for condition in (
+ "needs.detect.outputs.linux_armhf == 'true'",
+ "needs.detect.outputs.image_set != 'normal'",
+ "needs.detect.outputs.image_set != 'normal-and-tsan'",
+ ):
+ self.assertIn(condition, standalone)
+ self.assertIn("- warm-linux-armhf-ccache", job("summary", WARM))
+ for condition in (
+ "needs.promote.result == 'success'", "inputs.publication_target == 'internal'",
+ "inputs.mode == 'refresh'", "inputs.promote", "inputs.include_armhf",
+ "(inputs.image_set == 'normal' || inputs.image_set == 'normal-and-tsan')",
+ "image_tag: ${{ needs.metadata.outputs.build_tag }}",
+ ):
+ self.assertIn(condition, published)
+ self.assertIn("- metadata", published)
+ self.assertIn("- promote", published)
+ self.assertNotIn("warm-armhf-ccache", job("promote"))
+
+ def test_sanitizer_build_inputs_select_warming(self):
+ push_filters = re.findall(
+ r'^ - "([^"]+)"$',
+ WARM.split(" schedule:", 1)[0],
+ re.MULTILINE,
+ )
+ for path in (
+ ".github/workflows/build-linux-sanitizers.yml",
+ ".github/actions/build-linux-sanitizers/action.yml",
+ ".github/scripts/verify-sanitizer-instrumentation.py",
+ "CMakeLists.txt",
+ "CMake/Sources.cmake",
+ "tests/CMakeLists.txt",
+ "tests/unit/CMakeLists.txt",
+ ):
+ with self.subTest(path=path):
+ self.assertTrue(any(fnmatch.fnmatchcase(path, pattern) for pattern in push_filters))
+ outputs = self.select_warmers("push", paths=[path])
+ self.assertEqual(outputs["linux_asan_ubsan"], "true")
+ self.assertEqual(outputs["image_set"], "none")
+
+ def test_asan_warmers_share_configuration_and_serialize(self):
+ standalone = job("warm-linux-asan-ubsan-ccache", WARM)
+ published = job("warm-asan-ubsan-ccache")
+ for warmer in (standalone, published):
+ with self.subTest(warmer=warmer):
+ for required in (
+ "github.ref == 'refs/heads/develop'",
+ "uses: ./.github/workflows/build-linux-sanitizers.yml",
+ "sanitizer: asan-ubsan",
+ "run_tests: false",
+ "recache: false",
+ "save_ccache: true",
+ "allow_stale_image: false",
+ "group: asan-ubsan-ccache-develop",
+ "cancel-in-progress: false",
+ "contents: read",
+ "packages: read",
+ ):
+ self.assertIn(required, warmer)
+ self.assertNotIn("packages: write", warmer)
+ self.assertIn("needs.detect.outputs.linux_asan_ubsan == 'true'", standalone)
+ self.assertIn("needs.detect.outputs.image_set != 'normal'", standalone)
+ self.assertIn("needs.detect.outputs.image_set != 'normal-and-tsan'", standalone)
+ self.assertIn("- warm-linux-asan-ubsan-ccache", job("summary", WARM))
+
+ def test_asan_warming_follows_internal_promotion_without_gating_it(self):
+ warm = job("warm-asan-ubsan-ccache")
+ self.assertIn("metadata", warm)
+ self.assertIn("promote", warm)
+ self.assertIn("needs.promote.result == 'success'", warm)
+ self.assertIn("inputs.publication_target == 'internal'", warm)
+ self.assertIn("inputs.mode == 'refresh'", warm)
+ self.assertIn("inputs.promote", warm)
+ self.assertIn("(inputs.image_set == 'normal' || inputs.image_set == 'normal-and-tsan')", warm)
+ self.assertIn("image_tag: ${{ needs.metadata.outputs.build_tag }}", warm)
+ self.assertNotIn("warm-asan-ubsan-ccache", job("promote"))
+
def test_public_release_publication_is_tag_scoped_and_complete(self):
validate = job("validate-inputs")
self.assertIn('[ "$REQUEST_REPOSITORY" != WSJTX/wsjtx ]', validate)
@@ -177,5 +395,35 @@ class LinuxImagePublicationPolicyTests(unittest.TestCase):
self.assertIn("stable_packages+=(linux-noble)", rollback)
+ def test_release_paths_consume_the_same_committed_selection(self):
+ candidate = (ROOT / ".github/workflows/release.yml").read_text()
+ public = (ROOT / ".github/workflows/public-release.yml").read_text()
+ tagging = (ROOT / ".github/workflows/release-tag-helper.yml").read_text()
+ promotion = (ROOT / ".github/workflows/promote-release.yml").read_text()
+ for workflow in (candidate, public):
+ self.assertIn("release-linux-images.py validate release-linux-images.json", workflow)
+ self.assertIn('--check-remote --github-output "$GITHUB_OUTPUT"', workflow)
+ self.assertEqual(workflow.count("image_source: public-release"), 3)
+ for output in ("x86_64_digest", "aarch64_digest", "armhf_digest", "armhf_cross_digest"):
+ self.assertIn("needs.prepare.outputs." + output, workflow)
+ self.assertNotIn("allow_stale_image: true", workflow)
+ self.assertNotIn("resolve-linux-ci-image-tag.py", workflow)
+ self.assertNotIn("publish-linux-ci-images.yml", public)
+ self.assertNotIn("packages: write", public)
+ self.assertIn(
+ "environment: ${{ needs.prepare.outputs.release_channel == 'BETA' && 'beta-release' || 'public-release' }}",
+ public,
+ )
+ self.assertIn("linux_images: $linux_images", candidate)
+ self.assertIn("release-linux-images.py provenance release-linux-images.json", candidate)
+ self.assertIn("release-linux-images.py verify-provenance", promotion)
+ self.assertLess(tagging.index("release-linux-images.py validate"), tagging.index("- name: Create candidate tag"))
+
+ def test_prepared_image_consumption_keeps_source_and_recipe_guards(self):
+ self.assertIn("WSJTX/wsjtx:refs/tags/v*|WSJTX/wsjtx-internal:refs/heads/release/*", BUILD)
+ self.assertIn('if [ "$ALLOW_STALE_IMAGE" = true ]; then', BUILD)
+ self.assertIn("Prepared public images require strict recipe verification", BUILD)
+
+
if __name__ == "__main__":
unittest.main()