Files
pkgmgr/tests/integration/test_publish_containers_release.py
T
kevinveenbirkenbachandClaude Opus 5.5 c2f0a56699
CI / security-codeql (push) Blocked by required conditions
CI / test-unit (push) Blocked by required conditions
CI / test-integration (push) Blocked by required conditions
CI / test-env-virtual (push) Blocked by required conditions
CI / test-env-nix (push) Blocked by required conditions
CI / test-e2e (push) Blocked by required conditions
CI / test-virgin-user (push) Blocked by required conditions
CI / test-virgin-root (push) Blocked by required conditions
CI / lint-shell (push) Blocked by required conditions
CI / lint-python (push) Blocked by required conditions
CI / lint-docker (push) Blocked by required conditions
CodeQL Advanced / Check security (none, actions) (push) Blocked by required conditions
CodeQL Advanced / Check security (none, python) (push) Blocked by required conditions
Test Units / test-unit (push) Blocked by required conditions
Test Code Integration / test-integration (push) Blocked by required conditions
Test OS Containers / test-env-virtual (arch) (push) Blocked by required conditions
Test OS Containers / test-env-virtual (centos) (push) Blocked by required conditions
Test OS Containers / test-env-virtual (debian) (push) Blocked by required conditions
Test OS Containers / test-env-virtual (fedora) (push) Blocked by required conditions
Test OS Containers / test-env-virtual (ubuntu) (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (arch) (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (centos) (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (debian) (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (fedora) (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (ubuntu) (push) Blocked by required conditions
Test End-To-End / test-e2e (arch) (push) Blocked by required conditions
Test End-To-End / test-e2e (centos) (push) Blocked by required conditions
Test End-To-End / test-e2e (debian) (push) Blocked by required conditions
Test End-To-End / test-e2e (fedora) (push) Blocked by required conditions
Test End-To-End / test-e2e (ubuntu) (push) Blocked by required conditions
Test Virgin User / test-virgin-user (arch) (push) Blocked by required conditions
Test Virgin User / test-virgin-user (centos) (push) Blocked by required conditions
Test Virgin User / test-virgin-user (debian) (push) Blocked by required conditions
Test Virgin User / test-virgin-user (fedora) (push) Blocked by required conditions
Test Virgin User / test-virgin-user (ubuntu) (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (arch) (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (centos) (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (debian) (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (fedora) (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (ubuntu) (push) Blocked by required conditions
ShellCheck / lint-shell (push) Blocked by required conditions
Ruff (Python code sniffer) / lint-python (push) Blocked by required conditions
Docker Linter / Lint Dockerfile (push) Blocked by required conditions
feat(publish): rebuild releases nightly and let stable follow the tested one
Every image build now carries <version> and the immutable
<version>.<unix-ts>; latest goes to the newest release on main, each
prefix (2, 2.3) to the newest release starting with it, and stable to the
release the git tag stable marks, which "Mark stable commit" sets only
after all tests passed.

publish-containers.yml runs daily at 03:00 UTC and on workflow_dispatch.
A rebuild publishes the newest release and, when the git tag stable sits
on an older one, that release too, so both get base-image security
updates. compute-publish-container-info.sh emits the release list with
each release's moving tags; image.sh takes them as --aliases instead of
--stable.

A platform build whose installed package set equals the published
<version> pushes nothing, and a merge whose image index equals the
published one only moves the tags not yet on it, without a new stamp.
Only vX.Y.Z tags count as releases; v2.4.0-rc1 no longer moves 2 or 2.4.

The build scripts come from the release commit: releases tagged before
this change keep the old scripts until a newer release replaces them.

tests/integration: 22 tests for release choice, aliases, the stable
rebuild, the push skip and the triggers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 18:38:42 +01:00

240 lines
7.5 KiB
Python

from __future__ import annotations
import json
import os
import subprocess
import tempfile
import unittest
from pathlib import Path
import yaml
REPO_ROOT = Path(__file__).resolve().parents[2]
RESOLVER = (
REPO_ROOT
/ "scripts"
/ "github"
/ "publish-containers"
/ "compute-publish-container-info.sh"
)
WORKFLOW = REPO_ROOT / ".github" / "workflows" / "publish-containers.yml"
GIT_ENV = {
**os.environ,
"GIT_CONFIG_GLOBAL": os.devnull,
"GIT_CONFIG_NOSYSTEM": "1",
"GIT_AUTHOR_NAME": "test",
"GIT_AUTHOR_EMAIL": "test@example.invalid",
"GIT_COMMITTER_NAME": "test",
"GIT_COMMITTER_EMAIL": "test@example.invalid",
}
class TestComputePublishContainerInfo(unittest.TestCase):
def setUp(self) -> None:
self._tmp = tempfile.TemporaryDirectory()
tmp = Path(self._tmp.name)
self.repo = tmp / "repo"
self.repo.mkdir()
self.output = tmp / "github_output"
self.git("init", "-q", "-b", "main")
def tearDown(self) -> None:
self._tmp.cleanup()
def git(self, *args: str) -> str:
return subprocess.run(
["git", *args],
cwd=self.repo,
env=GIT_ENV,
capture_output=True,
text=True,
check=True,
).stdout.strip()
def commit(self, *tags: str) -> str:
self.git("commit", "-q", "--allow-empty", "-m", " ".join(tags) or "untagged")
for tag in tags:
self.git("tag", tag)
return self.git("rev-parse", "HEAD")
def push_main(self) -> None:
self.git("update-ref", "refs/remotes/origin/main", "HEAD")
def resolve(self, workflow_run_sha: str):
self.output.write_text("")
result = subprocess.run(
["bash", str(RESOLVER)],
cwd=self.repo,
env={
**GIT_ENV,
"GITHUB_OUTPUT": str(self.output),
"WORKFLOW_RUN_SHA": workflow_run_sha,
},
capture_output=True,
text=True,
check=False,
)
outputs = dict(
line.split("=", 1) for line in self.output.read_text().splitlines()
)
return result, outputs
def releases(self, workflow_run_sha: str) -> list[dict[str, str]]:
result, outputs = self.resolve(workflow_run_sha)
self.assertEqual(result.returncode, 0, result.stderr)
return json.loads(outputs["releases"])
def test_a_rebuild_with_stable_on_the_newest_release_publishes_it_once(
self,
) -> None:
self.commit("v2.3.0")
newest = self.commit("v2.4.0", "stable")
self.push_main()
self.assertEqual(
self.releases(""),
[{"sha": newest, "version": "2.4.0", "aliases": "latest 2 2.4 stable"}],
)
def test_a_rebuild_with_stable_behind_publishes_the_newest_and_the_stable_release(
self,
) -> None:
self.commit("v2.2.0")
stable = self.commit("v2.3.0", "stable")
newest = self.commit("v2.4.0")
self.commit("v2.5.0-rc1")
self.push_main()
self.assertEqual(
self.releases(""),
[
{"sha": newest, "version": "2.4.0", "aliases": "latest 2 2.4"},
{"sha": stable, "version": "2.3.0", "aliases": "2.3 stable"},
],
)
def test_the_stable_release_takes_no_prefix_a_newer_release_leads(self) -> None:
stable = self.commit("v2.3.0", "stable")
self.commit("v2.3.1")
newest = self.commit("v2.4.0")
self.push_main()
self.assertEqual(
self.releases(""),
[
{"sha": newest, "version": "2.4.0", "aliases": "latest 2 2.4"},
{"sha": stable, "version": "2.3.0", "aliases": "stable"},
],
)
def test_a_rebuild_publishes_the_newest_release_on_main_not_its_tip(
self,
) -> None:
self.commit("v1.9.0")
newest = self.commit("v1.10.0")
self.commit()
self.push_main()
self.git("checkout", "-q", "-b", "side")
self.commit("v3.0.0")
result, outputs = self.resolve("")
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(
json.loads(outputs["releases"]),
[{"sha": newest, "version": "1.10.0", "aliases": "latest 1 1.10"}],
)
self.assertIn("the stable image stays where it is", result.stdout)
def test_a_workflow_run_publishes_the_commit_it_tagged(self) -> None:
self.commit("v2.3.0")
tagged = self.commit("v2.4.0", "stable")
self.push_main()
self.assertEqual(
self.releases(tagged),
[{"sha": tagged, "version": "2.4.0", "aliases": "latest 2 2.4 stable"}],
)
def test_a_workflow_run_of_a_backport_moves_only_the_prefixes_it_leads(
self,
) -> None:
self.commit("v2.3.0")
self.commit("v2.4.0", "stable")
backport = self.commit("v2.3.1")
self.push_main()
self.assertEqual(
self.releases(backport),
[{"sha": backport, "version": "2.3.1", "aliases": "2.3"}],
)
def test_a_workflow_run_outside_main_publishes_nothing(self) -> None:
self.commit("v2.3.0")
self.push_main()
self.git("checkout", "-q", "-b", "side")
outside = self.commit("v9.0.0")
self.assertEqual(self.releases(outside), [])
def test_a_workflow_run_without_an_x_y_z_tag_publishes_nothing(self) -> None:
self.commit("v2.3.0")
candidate = self.commit("v2.4.0-rc1")
self.push_main()
self.assertEqual(self.releases(candidate), [])
def test_a_rebuild_without_a_release_on_main_fails(self) -> None:
self.commit("v1.0.0-rc1", "stable")
self.push_main()
result, outputs = self.resolve("")
self.assertEqual(result.returncode, 1)
self.assertEqual(outputs, {})
self.assertIn("No vX.Y.Z tag is reachable from origin/main", result.stderr)
class TestPublishContainersWorkflow(unittest.TestCase):
def setUp(self) -> None:
self.workflow = yaml.safe_load(WORKFLOW.read_text())
def test_the_releases_are_rebuilt_daily_at_03_utc_and_on_demand(self) -> None:
triggers = self.workflow[True]
steps = {
step.get("id"): step for step in self.workflow["jobs"]["prepare"]["steps"]
}
self.assertEqual(triggers["schedule"], [{"cron": "0 3 * * *"}])
self.assertIn("workflow_dispatch", triggers)
self.assertEqual(
steps["info"]["run"],
"bash scripts/github/publish-containers/compute-publish-container-info.sh",
)
self.assertEqual(
steps["info"]["env"]["WORKFLOW_RUN_SHA"],
"${{ github.event.workflow_run.head_sha }}",
)
def test_every_resolved_release_is_built_and_merged_with_its_own_tags(
self,
) -> None:
jobs = self.workflow["jobs"]
merge_env = jobs["merge"]["steps"][-1]["env"]
for job in ("build", "merge"):
self.assertEqual(
jobs[job]["strategy"]["matrix"]["release"],
"${{ fromJSON(needs.prepare.outputs.releases) }}",
)
self.assertEqual(
jobs[job]["steps"][0]["with"]["ref"], "${{ matrix.release.sha }}"
)
self.assertEqual(merge_env["VERSION"], "${{ matrix.release.version }}")
self.assertEqual(merge_env["ALIASES"], "${{ matrix.release.aliases }}")
if __name__ == "__main__":
unittest.main()