From cf0e1c95448b46ba01ac2ebec1c8f85d91273d1b Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:33:46 +0100 Subject: [PATCH 01/13] Added cfengine dev release command skeleton A new command to release the packages built by build-in-container. For now it only parses its options and prints a summary. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/dev.py | 9 ++++++ src/cfengine_cli/main.py | 7 +++++ src/cfengine_cli/release/__init__.py | 0 src/cfengine_cli/release/args.py | 39 ++++++++++++++++++++++++ src/cfengine_cli/release/metadata.py | 19 ++++++++++++ src/cfengine_cli/release/release.py | 45 ++++++++++++++++++++++++++++ tests/unit/test_release_args.py | 16 ++++++++++ tests/unit/test_release_metadata.py | 19 ++++++++++++ 8 files changed, 154 insertions(+) create mode 100644 src/cfengine_cli/release/__init__.py create mode 100644 src/cfengine_cli/release/args.py create mode 100644 src/cfengine_cli/release/metadata.py create mode 100644 src/cfengine_cli/release/release.py create mode 100644 tests/unit/test_release_args.py create mode 100644 tests/unit/test_release_metadata.py diff --git a/src/cfengine_cli/dev.py b/src/cfengine_cli/dev.py index edb8b9d4..5100937e 100644 --- a/src/cfengine_cli/dev.py +++ b/src/cfengine_cli/dev.py @@ -10,6 +10,7 @@ ) from cfengine_cli import docs from cfengine_cli.syntax_tree import syntax_tree +from cfengine_cli.release.release import release def generate_release_information_command( @@ -84,5 +85,13 @@ def dispatch_dev_subcommand(subcommand, args) -> int: ) if subcommand == "generate-changelog": return generate_changelog_impl(args) + if subcommand == "release": + return release( + project=args.project, + version=args.version, + build_dir=args.build, + output_dir=args.output, + dry_run=args.dry_run, + ) raise UserError("Invalid cfengine dev subcommand - " + subcommand) diff --git a/src/cfengine_cli/main.py b/src/cfengine_cli/main.py index d9b39c9b..69b23d9f 100644 --- a/src/cfengine_cli/main.py +++ b/src/cfengine_cli/main.py @@ -10,6 +10,7 @@ from cf_remote.utils import strip_user, CFRExitError from cfengine_cli.cfengine_wrapper import cfengine_commands from cfengine_cli.cfengine_wrapper.arg_parse import parse_wrapper_args +from cfengine_cli.release.args import add_release_args from cfengine_cli.version import cfengine_cli_version_string from cfengine_cli import commands from cfengine_cli.utils import UserError @@ -211,6 +212,12 @@ def _get_arg_parser(): help="Commit range [other optional args], e.g. 3.27.0..origin/3.27.x", ) + parser = dev_subparsers.add_parser( + "release", + help="Release packages built by build-in-container", + ) + add_release_args(parser) + inip = subp.add_parser( "init", help="Initialize a [policy-set, policy-module, promise-type] example." ) diff --git a/src/cfengine_cli/release/__init__.py b/src/cfengine_cli/release/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/cfengine_cli/release/args.py b/src/cfengine_cli/release/args.py new file mode 100644 index 00000000..0d0dd2c2 --- /dev/null +++ b/src/cfengine_cli/release/args.py @@ -0,0 +1,39 @@ +import argparse +import re + + +def release_version(value: str) -> str: + """argparse type for a release or nightly version.""" + if not re.fullmatch(r"\d+\.\d+\.(\d+|x)|master", value): + raise argparse.ArgumentTypeError( + f"'{value}' is not X.Y.Z, or X.Y.x or master for nightlies" + ) + return value + + +def add_release_args(sp: argparse.ArgumentParser) -> None: + _ = sp.add_argument( + "--project", + required=True, + choices=["enterprise", "community"], + help="Which edition to release", + ) + _ = sp.add_argument( + "--version", + required=True, + type=release_version, + help="Version to release, e.g. 3.30.0. Or 3.30.x / master for nightlies", + ) + _ = sp.add_argument( + "--build", + required=True, + help="Directory with the build", + ) + _ = sp.add_argument( + "--output", + required=True, + help="Root directory to write release/ and release-data/ to", + ) + _ = sp.add_argument( + "--dry-run", action="store_true", help="Only print what would be done" + ) diff --git a/src/cfengine_cli/release/metadata.py b/src/cfengine_cli/release/metadata.py new file mode 100644 index 00000000..0103ad5b --- /dev/null +++ b/src/cfengine_cli/release/metadata.py @@ -0,0 +1,19 @@ +import re + + +def is_nightly(version: str) -> bool: + """Return True for master and LTS branches like 3.30.x.""" + return version == "master" or version.endswith(".x") + + +def release_branch(project: str, version: str) -> str: + """Return the branch of a version in releases.json. + + A version number like 3.30.0 becomes 3.30.x. + Community master becomes nightly-master. + """ + if not is_nightly(version): + return re.sub(r"\.\d+$", ".x", version) + if project == "community": + return f"nightly-{version}" + return version diff --git a/src/cfengine_cli/release/release.py b/src/cfengine_cli/release/release.py new file mode 100644 index 00000000..e757067c --- /dev/null +++ b/src/cfengine_cli/release/release.py @@ -0,0 +1,45 @@ +import os + +from cfengine_cli.release.metadata import is_nightly, release_branch +from cfengine_cli.utils import UserError + + +def release( + project: str, + version: str, + build_dir: str, + output_dir: str, + dry_run: bool, +) -> int: + branch = release_branch(project, version) + # Nightlies are debug releases causing them to be hidden from the downloads page + debug = is_nightly(version) + if not os.path.isdir(build_dir): + raise UserError(f"Build directory '{build_dir}' does not exist") + + _print_summary( + project, + version, + branch, + build_dir, + output_dir, + debug, + dry_run, + ) + return 0 + + +def _print_summary( + project: str, + version: str, + branch: str, + build_dir: str, + output_dir: str, + debug: bool, + dry_run: bool, +) -> None: + print(f"Releasing {project} {version} (branch {branch})") + print(f" build: {build_dir}") + print(f" output: {output_dir}") + print(f" debug: {debug}") + print(f" dry run: {dry_run}") diff --git a/tests/unit/test_release_args.py b/tests/unit/test_release_args.py new file mode 100644 index 00000000..9aa0d2f3 --- /dev/null +++ b/tests/unit/test_release_args.py @@ -0,0 +1,16 @@ +import argparse + +import pytest + +from cfengine_cli.release.args import release_version + + +@pytest.mark.parametrize("version", ["3.30.0", "3.27.x", "master"]) +def test_release_version(version: str) -> None: + assert release_version(version) == version + + +@pytest.mark.parametrize("version", ["3.30", "3.15.0b1", "ENT-1234", "3.27.x.1"]) +def test_release_version_invalid(version: str) -> None: + with pytest.raises(argparse.ArgumentTypeError): + _ = release_version(version) diff --git a/tests/unit/test_release_metadata.py b/tests/unit/test_release_metadata.py new file mode 100644 index 00000000..fc1dc79f --- /dev/null +++ b/tests/unit/test_release_metadata.py @@ -0,0 +1,19 @@ +import pytest + +from cfengine_cli.release.metadata import release_branch + + +@pytest.mark.parametrize( + "project, version, branch", + [ + ("community", "3.30.0", "3.30.x"), + ("enterprise", "3.30.0", "3.30.x"), + # Nightlies, as in the published releases.json + ("community", "3.27.x", "nightly-3.27.x"), + ("enterprise", "3.27.x", "3.27.x"), + ("community", "master", "nightly-master"), + ("enterprise", "master", "master"), + ], +) +def test_release_branch(project: str, version: str, branch: str) -> None: + assert release_branch(project, version) == branch From d9939e19bd0cd9ddacf9d8f1a1e5f932c2ecaa61 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:35:59 +0100 Subject: [PATCH 02/13] Added reading of build-in-container output to cfengine dev release Reads the build output directory, with one directory per platform label, and verifies it against its sha256sums.txt files. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/release/build.py | 71 ++++++++++++++++++++ src/cfengine_cli/release/checksums.py | 65 +++++++++++++++++++ src/cfengine_cli/release/release.py | 5 ++ tests/unit/test_release_build.py | 93 +++++++++++++++++++++++++++ tests/unit/test_release_checksums.py | 71 ++++++++++++++++++++ 5 files changed, 305 insertions(+) create mode 100644 src/cfengine_cli/release/build.py create mode 100644 src/cfengine_cli/release/checksums.py create mode 100644 tests/unit/test_release_build.py create mode 100644 tests/unit/test_release_checksums.py diff --git a/src/cfengine_cli/release/build.py b/src/cfengine_cli/release/build.py new file mode 100644 index 00000000..3cdc0400 --- /dev/null +++ b/src/cfengine_cli/release/build.py @@ -0,0 +1,71 @@ +from dataclasses import dataclass +from pathlib import Path + +from cfengine_cli.utils import UserError + +LABEL_PREFIX = "PACKAGES_" +TARBALLS_DIR = "tarballs" +VAGRANT_DIR = "vagrant" +SHA256SUMS = "sha256sums.txt" +# .tar.gz also covers .pkg.tar.gz +PACKAGE_SUFFIXES = (".deb", ".rpm", ".msi", ".tar.gz") + + +@dataclass +class PackageDir: + packages: list[Path] + sha256sums: Path + + +@dataclass +class Build: + labels: dict[str, PackageDir] + tarballs: PackageDir + # The Vagrant quickstart. Only enterprise builds have it. + vagrant: PackageDir | None + # Name of the build dir, e.g. jenkins-master-nightly-pipeline-123. + # Nightlies link to the packages under it on buildcache. + name: str + + +def _read_package_dir(directory: Path) -> PackageDir: + packages = sorted( + path + for path in directory.iterdir() + if path.is_file() and path.name.endswith(PACKAGE_SUFFIXES) + ) + if not packages: + raise UserError(f"No packages in '{directory}'") + + sha256sums = directory / SHA256SUMS + if not sha256sums.is_file(): + raise UserError(f"No {SHA256SUMS} in '{directory}'") + + return PackageDir(packages, sha256sums) + + +def read_build(build_dir: str) -> Build: + """Read a build-in-container output directory. + + It has one subdirectory per label, e.g. PACKAGES_x86_64_linux_debian_12, + a tarballs subdirectory, and optionally a vagrant subdirectory. + """ + labels: dict[str, PackageDir] = {} + tarballs: PackageDir | None = None + vagrant: PackageDir | None = None + + for entry in sorted(Path(build_dir).iterdir()): + if entry.is_dir() and entry.name.startswith(LABEL_PREFIX): + labels[entry.name] = _read_package_dir(entry) + elif entry.is_dir() and entry.name == TARBALLS_DIR: + tarballs = _read_package_dir(entry) + elif entry.is_dir() and entry.name == VAGRANT_DIR: + vagrant = _read_package_dir(entry) + else: + raise UserError(f"Unexpected '{entry}' in build") + + if not labels: + raise UserError(f"No {LABEL_PREFIX}* directories in '{build_dir}'") + if tarballs is None: + raise UserError(f"No {TARBALLS_DIR} directory in '{build_dir}'") + return Build(labels, tarballs, vagrant, Path(build_dir).resolve().name) diff --git a/src/cfengine_cli/release/checksums.py b/src/cfengine_cli/release/checksums.py new file mode 100644 index 00000000..68e6fc10 --- /dev/null +++ b/src/cfengine_cli/release/checksums.py @@ -0,0 +1,65 @@ +import hashlib +import re +from pathlib import Path + +from cfengine_cli.release.build import Build +from cfengine_cli.utils import UserError + +# sha256sum output: hash, two spaces, file name +_LINE_RE = re.compile(r"([0-9a-f]{64}) (.+)") + + +def parse_checksums(manifest: Path) -> dict[str, str]: + """Return a dict mapping each file name to its expected hash.""" + expected: dict[str, str] = {} + # Count from 1, so error messages match the line numbers in an editor + for number, line in enumerate(manifest.read_text().splitlines(), start=1): + match = _LINE_RE.fullmatch(line) + if not match: + raise UserError(f"Invalid line {number} in '{manifest}'") + digest, name = match.groups() + if name in expected: + raise UserError(f"'{name}' is listed twice in '{manifest}'") + expected[name] = digest + return expected + + +def verify_checksums(manifest: Path) -> None: + """Check that the files next to sha256sums.txt are exactly the ones it lists. + + Fails if a listed file is missing, a file is not listed, or a hash differs. + """ + directory = manifest.parent + expected = parse_checksums(manifest) + + # Every file in the directory, except the checksum file itself + actual: set[str] = set() + for path in directory.iterdir(): + if path.is_file() and path != manifest: + actual.add(path.name) + + missing = sorted(expected.keys() - actual) + if missing: + raise UserError(f"Missing in '{directory}': {', '.join(missing)}") + unlisted = sorted(actual - expected.keys()) + if unlisted: + raise UserError(f"Not listed in '{manifest}': {', '.join(unlisted)}") + + for name in sorted(expected): + if file_sha256(directory / name) != expected[name]: + raise UserError(f"Checksum mismatch for '{directory / name}'") + + +def verify_build(build: Build) -> None: + """Verify the checksums of every directory in the build.""" + package_dirs = [*build.labels.values(), build.tarballs] + if build.vagrant is not None: + package_dirs.append(build.vagrant) + for package_dir in package_dirs: + verify_checksums(package_dir.sha256sums) + print("Checksums OK") + + +def file_sha256(path: Path) -> str: + with open(path, "rb") as f: + return hashlib.file_digest(f, "sha256").hexdigest() diff --git a/src/cfengine_cli/release/release.py b/src/cfengine_cli/release/release.py index e757067c..87ec9901 100644 --- a/src/cfengine_cli/release/release.py +++ b/src/cfengine_cli/release/release.py @@ -1,5 +1,7 @@ import os +from cfengine_cli.release.build import read_build +from cfengine_cli.release.checksums import verify_build from cfengine_cli.release.metadata import is_nightly, release_branch from cfengine_cli.utils import UserError @@ -26,6 +28,9 @@ def release( debug, dry_run, ) + + build = read_build(build_dir) + verify_build(build) return 0 diff --git a/tests/unit/test_release_build.py b/tests/unit/test_release_build.py new file mode 100644 index 00000000..b551e046 --- /dev/null +++ b/tests/unit/test_release_build.py @@ -0,0 +1,93 @@ +import shutil +from pathlib import Path + +import pytest + +from cfengine_cli.release.build import read_build +from cfengine_cli.utils import UserError + +HUB = "PACKAGES_HUB_x86_64_linux_debian_12" +AGENT = "PACKAGES_x86_64_linux_redhat_9" + + +def _touch(path: Path) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + path.touch() + + +@pytest.fixture +def build_dir(tmp_path: Path) -> Path: + _touch(tmp_path / HUB / "cfengine-nova-hub_3.30.0-1_amd64.deb") + _touch(tmp_path / HUB / "cfengine-nova-hub-3.30.0-1.x86_64.pkg.tar.gz") + _touch(tmp_path / HUB / "sha256sums.txt") + _touch(tmp_path / AGENT / "cfengine-nova-3.30.0-1.el9.x86_64.rpm") + _touch(tmp_path / AGENT / "sha256sums.txt") + _touch(tmp_path / "tarballs" / "cfengine-masterfiles-3.30.0.tar.gz") + _touch(tmp_path / "tarballs" / "cfengine-3.30.0.tar.gz") + _touch(tmp_path / "tarballs" / "sha256sums.txt") + return tmp_path + + +def test_read_build(build_dir: Path) -> None: + build = read_build(str(build_dir)) + assert {k: [p.name for p in v.packages] for k, v in build.labels.items()} == { + HUB: [ + "cfengine-nova-hub-3.30.0-1.x86_64.pkg.tar.gz", + "cfengine-nova-hub_3.30.0-1_amd64.deb", + ], + AGENT: ["cfengine-nova-3.30.0-1.el9.x86_64.rpm"], + } + assert build.labels[HUB].sha256sums == build_dir / HUB / "sha256sums.txt" + + assert [p.name for p in build.tarballs.packages] == [ + "cfengine-3.30.0.tar.gz", + "cfengine-masterfiles-3.30.0.tar.gz", + ] + assert build.tarballs.sha256sums == build_dir / "tarballs" / "sha256sums.txt" + assert build.vagrant is None + + +def test_read_build_with_vagrant(build_dir: Path) -> None: + tarball = "CFEngine_Enterprise_vagrant_quickstart-3.30.0-1.tar.gz" + _touch(build_dir / "vagrant" / tarball) + _touch(build_dir / "vagrant" / "sha256sums.txt") + build = read_build(str(build_dir)) + assert build.vagrant is not None + assert [p.name for p in build.vagrant.packages] == [tarball] + + +def test_read_build_vagrant_without_sha256sums(build_dir: Path) -> None: + _touch( + build_dir / "vagrant" / "CFEngine_Enterprise_vagrant_quickstart-3.30.0-1.tar.gz" + ) + with pytest.raises(UserError, match="No sha256sums.txt"): + _ = read_build(str(build_dir)) + + +def test_read_build_without_tarballs(build_dir: Path) -> None: + shutil.rmtree(build_dir / "tarballs") + with pytest.raises(UserError, match="No tarballs directory"): + _ = read_build(str(build_dir)) + + +def test_read_build_label_without_packages(build_dir: Path) -> None: + _touch(build_dir / "PACKAGES_x86_64_linux_ubuntu_24" / "sha256sums.txt") + with pytest.raises(UserError, match="No packages"): + _ = read_build(str(build_dir)) + + +def test_read_build_label_without_sha256sums(build_dir: Path) -> None: + (build_dir / HUB / "sha256sums.txt").unlink() + with pytest.raises(UserError, match="No sha256sums.txt"): + _ = read_build(str(build_dir)) + + +def test_read_build_unexpected_entry(build_dir: Path) -> None: + _touch(build_dir / "stray.txt") + with pytest.raises(UserError, match="Unexpected"): + _ = read_build(str(build_dir)) + + +def test_read_build_no_labels(tmp_path: Path) -> None: + with pytest.raises(UserError, match="No PACKAGES_"): + _ = read_build(str(tmp_path)) diff --git a/tests/unit/test_release_checksums.py b/tests/unit/test_release_checksums.py new file mode 100644 index 00000000..22c74359 --- /dev/null +++ b/tests/unit/test_release_checksums.py @@ -0,0 +1,71 @@ +import hashlib +from pathlib import Path + +import pytest + +from cfengine_cli.release.checksums import parse_checksums, verify_checksums +from cfengine_cli.utils import UserError + +FILES = { + "cfengine-nova-3.30.0-1.el9.x86_64.rpm": b"rpm", + "cfengine-nova_3.30.0-1_amd64.deb": b"deb", +} + + +def _sha256(data: bytes) -> str: + return hashlib.sha256(data).hexdigest() + + +@pytest.fixture +def manifest(tmp_path: Path) -> Path: + """A directory with FILES and a manifest listing them, as sha256sum writes it.""" + lines: list[str] = [] + for name, data in sorted(FILES.items()): + _ = (tmp_path / name).write_bytes(data) + lines.append(f"{_sha256(data)} {name}\n") + path = tmp_path / "sha256sums.txt" + _ = path.write_text("".join(lines)) + return path + + +def test_parse_checksums(manifest: Path) -> None: + assert parse_checksums(manifest) == { + name: _sha256(data) for name, data in FILES.items() + } + + +def test_verify_checksums(manifest: Path) -> None: + verify_checksums(manifest) + + +def test_verify_checksums_mismatch(manifest: Path) -> None: + _ = (manifest.parent / "cfengine-nova_3.30.0-1_amd64.deb").write_bytes(b"x") + with pytest.raises(UserError, match="Checksum mismatch"): + verify_checksums(manifest) + + +def test_verify_checksums_missing_file(manifest: Path) -> None: + (manifest.parent / "cfengine-nova_3.30.0-1_amd64.deb").unlink() + with pytest.raises(UserError, match="Missing"): + verify_checksums(manifest) + + +def test_verify_checksums_unlisted_file(manifest: Path) -> None: + _ = (manifest.parent / "stray.txt").write_bytes(b"stray") + with pytest.raises(UserError, match="Not listed"): + verify_checksums(manifest) + + +def test_parse_checksums_invalid_line(manifest: Path) -> None: + with manifest.open("a") as f: + _ = f.write("not a checksum line\n") + with pytest.raises(UserError, match="Invalid line 3"): + _ = parse_checksums(manifest) + + +def test_parse_checksums_listed_twice(manifest: Path) -> None: + first_line = manifest.read_text().splitlines(keepends=True)[0] + with manifest.open("a") as f: + _ = f.write(first_line) + with pytest.raises(UserError, match="listed twice"): + _ = parse_checksums(manifest) From 34c5bc6ab667a4bbd31fb683cff99cdd7f483471 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:38:47 +0100 Subject: [PATCH 03/13] Added platform info for build labels Maps a build label like PACKAGES_x86_64_linux_debian_12 to how its packages appear in a release: title, arch, classexpr and release directory, as in the releases made by the legacy release.py. It also defines the order in which the packages are listed on the downloads page. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/release/platforms.py | 120 ++++++++++++++++++++++++ tests/unit/test_release_platforms.py | 126 ++++++++++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 src/cfengine_cli/release/platforms.py create mode 100644 tests/unit/test_release_platforms.py diff --git a/src/cfengine_cli/release/platforms.py b/src/cfengine_cli/release/platforms.py new file mode 100644 index 00000000..2254bac0 --- /dev/null +++ b/src/cfengine_cli/release/platforms.py @@ -0,0 +1,120 @@ +import re +from dataclasses import dataclass + +from cfengine_cli.utils import UserError + +_ARCHES = {"x86_64": "x86_64", "arm_64": "aarch64"} +_OS_TITLES = {"debian": "Debian", "ubuntu": "Ubuntu", "redhat": "Red Hat / CentOS"} +_OS_ORDER = ("debian", "ubuntu", "redhat", "windows") + +# e.g. PACKAGES_HUB_x86_64_linux_debian_12 or PACKAGES_arm_64_linux_redhat_9, +# with a known arch and OS +_LABEL_RE = re.compile( + rf"PACKAGES_(HUB_)?({'|'.join(_ARCHES)})_linux_({'|'.join(_OS_TITLES)})_(\d+)" +) +_WINDOWS_LABEL = "PACKAGES_x86_64_mingw" + + +@dataclass(frozen=True) +class Platform: + """How a build label's packages appear in a release. + + The values match the 3.29.0 release made by the legacy release.py in the + infra repo, except the Ubuntu agent titles, which had .04. Self-upgrade + policy uses classexpr to pick packages, so changing it changes which hosts + get which package. + """ + + hub: bool + title: str # e.g. Debian 12 + arch: str # x86_64 or aarch64 + classexpr: str # e.g. !am_policy_hub.debian_12.x86_64 + release_dir: str # Subdirectory in the published release, e.g. agent_rhel8_x86_64 + os: str # debian, ubuntu, redhat or windows + version: int # e.g. 12, or 2012 for Windows Server 2012 + + def sort_key(self) -> tuple[bool, int, int, bool]: + """Order on the downloads page. + + Hubs, then agents. Then by OS and version, with x86_64 before + aarch64. The legacy release.py in infra uses the same order. + """ + return ( + not self.hub, + _OS_ORDER.index(self.os), + self.version, + self.arch != "x86_64", + ) + + +def _limit_to_role(project: str, hub: bool, classexpr: str) -> str: + """Limit a classexpr to hubs or to non-hubs, where needed.""" + if project == "community": + # Community has one package for both hubs and agents + if hub: + raise UserError("Community releases have no hub packages") + return classexpr + + # Enterprise has separate hub and agent packages + return f"am_policy_hub.{classexpr}" if hub else f"!am_policy_hub.{classexpr}" + + +def _includes_centos(os: str, version: int, hub: bool) -> bool: + # Exception: RHEL hubs from 9 on are for Red Hat only + # TODO: Figure out if this is necessary + return os == "redhat" and not (hub and version >= 9) + + +def _title(project: str, os: str, version: int, hub: bool) -> str: + if (os == "redhat") and (not _includes_centos(os, version, hub)): + return f"Red Hat {version}" + title = f"{_OS_TITLES[os]} {version}" + # Exception: enterprise says 8.1 for RHEL 8 agents + if (os == "redhat") and (version == 8) and (not hub) and (project == "enterprise"): + title += ".1" + return title + + +def get_platform(label: str, project: str) -> Platform: + """Return how a build label's packages appear in a project's release.""" + if label == _WINDOWS_LABEL: + # Windows packages are enterprise only, and there are no Windows hubs + if project == "community": + raise UserError("Community releases have no Windows packages") + return Platform( + False, + "Windows Server 2012", + "x86_64", + "!am_policy_hub.windows.x86_64", + "windows_x86_64", + "windows", + 2012, + ) + + match = _LABEL_RE.fullmatch(label) + if not match: + raise UserError(f"Unknown build label '{label}'") + hub = match.group(1) is not None + label_arch, os, version = match.group(2), match.group(3), int(match.group(4)) + arch = _ARCHES[label_arch] + + if _includes_centos(os, version, hub): + classexpr = f"(redhat_{version}|centos_{version}).{arch}" + else: + classexpr = f"{os}_{version}.{arch}" + + if hub: + release_dir = f"{os}_{version}_{label_arch}" + else: + short = "rhel" if os == "redhat" else os + release_dir = f"agent_{short}{version}_{label_arch}" + + return Platform( + hub, + _title(project, os, version, hub), + arch, + _limit_to_role(project, hub, classexpr), + release_dir, + os, + version, + ) diff --git a/tests/unit/test_release_platforms.py b/tests/unit/test_release_platforms.py new file mode 100644 index 00000000..ba980c9a --- /dev/null +++ b/tests/unit/test_release_platforms.py @@ -0,0 +1,126 @@ +import pytest + +from cfengine_cli.release.platforms import get_platform +from cfengine_cli.utils import UserError + +# Every package in the published release-data//3.29.0.json, made by +# the legacy release.py: label, title, arch, classexpr, release_dir. Except the +# Ubuntu agent titles, which had .04. +ENTERPRISE = [ + ("PACKAGES_HUB_x86_64_linux_debian_12", "Debian 12", "x86_64", "am_policy_hub.debian_12.x86_64", "debian_12_x86_64"), + ("PACKAGES_HUB_arm_64_linux_debian_12", "Debian 12", "aarch64", "am_policy_hub.debian_12.aarch64", "debian_12_arm_64"), + ("PACKAGES_HUB_x86_64_linux_debian_13", "Debian 13", "x86_64", "am_policy_hub.debian_13.x86_64", "debian_13_x86_64"), + ("PACKAGES_HUB_arm_64_linux_debian_13", "Debian 13", "aarch64", "am_policy_hub.debian_13.aarch64", "debian_13_arm_64"), + ("PACKAGES_HUB_x86_64_linux_redhat_8", "Red Hat / CentOS 8", "x86_64", "am_policy_hub.(redhat_8|centos_8).x86_64", "redhat_8_x86_64"), + ("PACKAGES_HUB_x86_64_linux_redhat_9", "Red Hat 9", "x86_64", "am_policy_hub.redhat_9.x86_64", "redhat_9_x86_64"), + ("PACKAGES_HUB_x86_64_linux_redhat_10", "Red Hat 10", "x86_64", "am_policy_hub.redhat_10.x86_64", "redhat_10_x86_64"), + ("PACKAGES_HUB_arm_64_linux_redhat_10", "Red Hat 10", "aarch64", "am_policy_hub.redhat_10.aarch64", "redhat_10_arm_64"), + ("PACKAGES_HUB_x86_64_linux_ubuntu_22", "Ubuntu 22", "x86_64", "am_policy_hub.ubuntu_22.x86_64", "ubuntu_22_x86_64"), + ("PACKAGES_HUB_arm_64_linux_ubuntu_22", "Ubuntu 22", "aarch64", "am_policy_hub.ubuntu_22.aarch64", "ubuntu_22_arm_64"), + ("PACKAGES_HUB_x86_64_linux_ubuntu_24", "Ubuntu 24", "x86_64", "am_policy_hub.ubuntu_24.x86_64", "ubuntu_24_x86_64"), + ("PACKAGES_HUB_arm_64_linux_ubuntu_24", "Ubuntu 24", "aarch64", "am_policy_hub.ubuntu_24.aarch64", "ubuntu_24_arm_64"), + ("PACKAGES_HUB_x86_64_linux_ubuntu_26", "Ubuntu 26", "x86_64", "am_policy_hub.ubuntu_26.x86_64", "ubuntu_26_x86_64"), + ("PACKAGES_HUB_arm_64_linux_ubuntu_26", "Ubuntu 26", "aarch64", "am_policy_hub.ubuntu_26.aarch64", "ubuntu_26_arm_64"), + ("PACKAGES_x86_64_linux_debian_12", "Debian 12", "x86_64", "!am_policy_hub.debian_12.x86_64", "agent_debian12_x86_64"), + ("PACKAGES_arm_64_linux_debian_12", "Debian 12", "aarch64", "!am_policy_hub.debian_12.aarch64", "agent_debian12_arm_64"), + ("PACKAGES_x86_64_linux_debian_13", "Debian 13", "x86_64", "!am_policy_hub.debian_13.x86_64", "agent_debian13_x86_64"), + ("PACKAGES_arm_64_linux_debian_13", "Debian 13", "aarch64", "!am_policy_hub.debian_13.aarch64", "agent_debian13_arm_64"), + ("PACKAGES_x86_64_linux_ubuntu_20", "Ubuntu 20", "x86_64", "!am_policy_hub.ubuntu_20.x86_64", "agent_ubuntu20_x86_64"), + ("PACKAGES_x86_64_linux_ubuntu_22", "Ubuntu 22", "x86_64", "!am_policy_hub.ubuntu_22.x86_64", "agent_ubuntu22_x86_64"), + ("PACKAGES_arm_64_linux_ubuntu_22", "Ubuntu 22", "aarch64", "!am_policy_hub.ubuntu_22.aarch64", "agent_ubuntu22_arm_64"), + ("PACKAGES_arm_64_linux_ubuntu_24", "Ubuntu 24", "aarch64", "!am_policy_hub.ubuntu_24.aarch64", "agent_ubuntu24_arm_64"), + ("PACKAGES_x86_64_linux_ubuntu_24", "Ubuntu 24", "x86_64", "!am_policy_hub.ubuntu_24.x86_64", "agent_ubuntu24_x86_64"), + ("PACKAGES_arm_64_linux_ubuntu_26", "Ubuntu 26", "aarch64", "!am_policy_hub.ubuntu_26.aarch64", "agent_ubuntu26_arm_64"), + ("PACKAGES_x86_64_linux_ubuntu_26", "Ubuntu 26", "x86_64", "!am_policy_hub.ubuntu_26.x86_64", "agent_ubuntu26_x86_64"), + ("PACKAGES_x86_64_linux_redhat_7", "Red Hat / CentOS 7", "x86_64", "!am_policy_hub.(redhat_7|centos_7).x86_64", "agent_rhel7_x86_64"), + ("PACKAGES_x86_64_linux_redhat_8", "Red Hat / CentOS 8.1", "x86_64", "!am_policy_hub.(redhat_8|centos_8).x86_64", "agent_rhel8_x86_64"), + ("PACKAGES_arm_64_linux_redhat_8", "Red Hat / CentOS 8.1", "aarch64", "!am_policy_hub.(redhat_8|centos_8).aarch64", "agent_rhel8_arm_64"), + ("PACKAGES_x86_64_linux_redhat_9", "Red Hat / CentOS 9", "x86_64", "!am_policy_hub.(redhat_9|centos_9).x86_64", "agent_rhel9_x86_64"), + ("PACKAGES_arm_64_linux_redhat_9", "Red Hat / CentOS 9", "aarch64", "!am_policy_hub.(redhat_9|centos_9).aarch64", "agent_rhel9_arm_64"), + ("PACKAGES_x86_64_linux_redhat_10", "Red Hat / CentOS 10", "x86_64", "!am_policy_hub.(redhat_10|centos_10).x86_64", "agent_rhel10_x86_64"), + ("PACKAGES_arm_64_linux_redhat_10", "Red Hat / CentOS 10", "aarch64", "!am_policy_hub.(redhat_10|centos_10).aarch64", "agent_rhel10_arm_64"), + ("PACKAGES_x86_64_mingw", "Windows Server 2012", "x86_64", "!am_policy_hub.windows.x86_64", "windows_x86_64"), +] # fmt: skip + +COMMUNITY = [ + ("PACKAGES_x86_64_linux_debian_12", "Debian 12", "x86_64", "debian_12.x86_64", "agent_debian12_x86_64"), + ("PACKAGES_arm_64_linux_debian_12", "Debian 12", "aarch64", "debian_12.aarch64", "agent_debian12_arm_64"), + ("PACKAGES_x86_64_linux_debian_13", "Debian 13", "x86_64", "debian_13.x86_64", "agent_debian13_x86_64"), + ("PACKAGES_arm_64_linux_debian_13", "Debian 13", "aarch64", "debian_13.aarch64", "agent_debian13_arm_64"), + ("PACKAGES_x86_64_linux_ubuntu_20", "Ubuntu 20", "x86_64", "ubuntu_20.x86_64", "agent_ubuntu20_x86_64"), + ("PACKAGES_x86_64_linux_ubuntu_22", "Ubuntu 22", "x86_64", "ubuntu_22.x86_64", "agent_ubuntu22_x86_64"), + ("PACKAGES_arm_64_linux_ubuntu_22", "Ubuntu 22", "aarch64", "ubuntu_22.aarch64", "agent_ubuntu22_arm_64"), + ("PACKAGES_arm_64_linux_ubuntu_24", "Ubuntu 24", "aarch64", "ubuntu_24.aarch64", "agent_ubuntu24_arm_64"), + ("PACKAGES_x86_64_linux_ubuntu_24", "Ubuntu 24", "x86_64", "ubuntu_24.x86_64", "agent_ubuntu24_x86_64"), + ("PACKAGES_arm_64_linux_ubuntu_26", "Ubuntu 26", "aarch64", "ubuntu_26.aarch64", "agent_ubuntu26_arm_64"), + ("PACKAGES_x86_64_linux_ubuntu_26", "Ubuntu 26", "x86_64", "ubuntu_26.x86_64", "agent_ubuntu26_x86_64"), + ("PACKAGES_x86_64_linux_redhat_7", "Red Hat / CentOS 7", "x86_64", "(redhat_7|centos_7).x86_64", "agent_rhel7_x86_64"), + ("PACKAGES_x86_64_linux_redhat_8", "Red Hat / CentOS 8", "x86_64", "(redhat_8|centos_8).x86_64", "agent_rhel8_x86_64"), + ("PACKAGES_arm_64_linux_redhat_8", "Red Hat / CentOS 8", "aarch64", "(redhat_8|centos_8).aarch64", "agent_rhel8_arm_64"), + ("PACKAGES_x86_64_linux_redhat_9", "Red Hat / CentOS 9", "x86_64", "(redhat_9|centos_9).x86_64", "agent_rhel9_x86_64"), + ("PACKAGES_arm_64_linux_redhat_9", "Red Hat / CentOS 9", "aarch64", "(redhat_9|centos_9).aarch64", "agent_rhel9_arm_64"), + ("PACKAGES_x86_64_linux_redhat_10", "Red Hat / CentOS 10", "x86_64", "(redhat_10|centos_10).x86_64", "agent_rhel10_x86_64"), + ("PACKAGES_arm_64_linux_redhat_10", "Red Hat / CentOS 10", "aarch64", "(redhat_10|centos_10).aarch64", "agent_rhel10_arm_64"), +] # fmt: skip + + +@pytest.mark.parametrize( + "project, label, title, arch, classexpr, release_dir", + [("enterprise", *row) for row in ENTERPRISE] + + [("community", *row) for row in COMMUNITY], +) +def test_get_platform_matches_published( + project: str, label: str, title: str, arch: str, classexpr: str, release_dir: str +) -> None: + hub = label.startswith("PACKAGES_HUB_") + platform = get_platform(label, project) + published = (hub, title, arch, classexpr, release_dir) + assert ( + platform.hub, + platform.title, + platform.arch, + platform.classexpr, + platform.release_dir, + ) == published + + +def test_platform_sort_key() -> None: + expected = [ + "PACKAGES_HUB_x86_64_linux_debian_12", + "PACKAGES_HUB_x86_64_linux_ubuntu_22", + "PACKAGES_HUB_x86_64_linux_redhat_9", + "PACKAGES_x86_64_linux_debian_12", + "PACKAGES_arm_64_linux_debian_12", + "PACKAGES_x86_64_linux_ubuntu_24", + "PACKAGES_arm_64_linux_ubuntu_24", + "PACKAGES_x86_64_linux_redhat_8", + "PACKAGES_x86_64_linux_redhat_10", + "PACKAGES_arm_64_linux_redhat_10", + "PACKAGES_x86_64_mingw", + ] + labels = sorted(expected, reverse=True) + labels.sort(key=lambda label: get_platform(label, "enterprise").sort_key()) + assert labels == expected + + +@pytest.mark.parametrize( + "label", + [ + "PACKAGES_x86_64_freebsd_14", + "PACKAGES_x86_64_linux_suse_15", + "PACKAGES_i386_linux_debian_12", + ], +) +def test_get_platform_unknown_label(label: str) -> None: + with pytest.raises(UserError, match=f"Unknown build label '{label}'"): + _ = get_platform(label, "enterprise") + + +def test_get_platform_community_hub() -> None: + with pytest.raises(UserError, match="no hub packages"): + _ = get_platform("PACKAGES_HUB_x86_64_linux_debian_12", "community") + + +def test_get_platform_community_windows() -> None: + with pytest.raises(UserError, match="no Windows packages"): + _ = get_platform("PACKAGES_x86_64_mingw", "community") From 7fa843228b38bf0d9af0e8c26d5e0a0bae886d5e Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:41:38 +0100 Subject: [PATCH 04/13] Added planning of platform packages to cfengine dev release Plans where each .deb, .rpm and .msi of the build is published, its download URL, and how it is shown in the release data, and prints the plan. Nightlies copy nothing, and link to the build on buildcache. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/release/plan.py | 117 ++++++++++++++++++++++++++++ src/cfengine_cli/release/release.py | 17 ++++ tests/unit/test_release_plan.py | 111 ++++++++++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 src/cfengine_cli/release/plan.py create mode 100644 tests/unit/test_release_plan.py diff --git a/src/cfengine_cli/release/plan.py b/src/cfengine_cli/release/plan.py new file mode 100644 index 00000000..6f28b95b --- /dev/null +++ b/src/cfengine_cli/release/plan.py @@ -0,0 +1,117 @@ +from dataclasses import dataclass +from pathlib import Path + +from cfengine_cli.release.build import Build +from cfengine_cli.release.platforms import get_platform + +S3_URL = "https://cfengine-package-repos.s3.amazonaws.com" +BUILDCACHE_URL = "http://buildcache.cfengine.com/packages/build-in-container" +PLATFORM_PACKAGE_SUFFIXES = (".deb", ".rpm", ".msi") + + +# Arguments must be passed with keywords +@dataclass(frozen=True, kw_only=True) +class PlannedFile: + """A file to publish, and how it appears in the release metadata.""" + + # The file to release, as built. In the build directory, never modified. + source: Path + # The published copy of source in the release dir. .rpm and .deb copies are + # signed. + # None for debug releases (nightlies): nothing is copied, and the metadata + # links to the source on buildcache. + destination: Path | None + # Download URL in the metadata. For releases, the URL of destination on S3, + # once uploaded. For debug releases (nightlies), the URL of source on + # buildcache. + url: str + # Artifact section. "Policy Server" and "Hosts (Clients)" for enterprise + # packages, and "Binary packages" for community packages. + section: str + # Shown on the downloads page, e.g. "Debian 12" + title: str + # e.g. "x86_64" or "aarch64" + arch: str + # Selects the package in self-upgrade policy, e.g. + # "!am_policy_hub.debian_12.x86_64" + classexpr: str + # Build label the file came from, e.g. "PACKAGES_x86_64_linux_debian_12" + package: str + + +def _section(project: str, hub: bool) -> str: + if project == "community": + return "Binary packages" + return "Policy Server" if hub else "Hosts (Clients)" + + +def _edition_root(project: str, version: str) -> str: + """Return the edition's directory in the release, relative to its root.""" + if project == "community": + return f"community_binaries/Community-{version}" + return f"enterprise/Enterprise-{version}" + + +def _release_path(project: str, version: str, hub: bool, release_dir: str) -> str: + """Return a platform's directory in the release, relative to its root.""" + if project == "community": + return f"{_edition_root(project, version)}/{release_dir}" + role = "hub" if hub else "agent" + return f"{_edition_root(project, version)}/{role}/{release_dir}" + + +def _place( + source: Path, + release_path: str, + name: str, + build_name: str, + output_dir: str, + debug: bool, +) -> tuple[Path | None, str]: + """Return the destination and URL of a file published as name. + + Debug releases (nightlies) link to the source on buildcache, under its own + name. + """ + if debug: + return None, f"{BUILDCACHE_URL}/{build_name}/{source.parent.name}/{source.name}" + destination = Path(output_dir) / "release" / release_path / name + return destination, f"{S3_URL}/{release_path}/{name}" + + +def plan_packages( + project: str, + version: str, + build: Build, + output_dir: str, + debug: bool, +) -> list[PlannedFile]: + """Plan the platform packages, i.e. .deb, .rpm and .msi, of every label.""" + build_name = build.name + planned: list[PlannedFile] = [] + platforms = {label: get_platform(label, project) for label in build.labels} + for label in sorted(platforms, key=lambda label: platforms[label].sort_key()): + platform = platforms[label] + label_dir = build.labels[label] + release_path = _release_path( + project, version, platform.hub, platform.release_dir + ) + for source in label_dir.packages: + if not source.name.endswith(PLATFORM_PACKAGE_SUFFIXES): + continue + destination, url = _place( + source, release_path, source.name, build_name, output_dir, debug + ) + planned.append( + PlannedFile( + source=source, + destination=destination, + url=url, + section=_section(project, platform.hub), + title=platform.title, + arch=platform.arch, + classexpr=platform.classexpr, + package=label, + ) + ) + return planned diff --git a/src/cfengine_cli/release/release.py b/src/cfengine_cli/release/release.py index 87ec9901..0d49afc4 100644 --- a/src/cfengine_cli/release/release.py +++ b/src/cfengine_cli/release/release.py @@ -3,6 +3,7 @@ from cfengine_cli.release.build import read_build from cfengine_cli.release.checksums import verify_build from cfengine_cli.release.metadata import is_nightly, release_branch +from cfengine_cli.release.plan import PlannedFile, plan_packages from cfengine_cli.utils import UserError @@ -31,9 +32,25 @@ def release( build = read_build(build_dir) verify_build(build) + + planned = plan_packages(project, version, build, output_dir, debug) + _print_plan(planned) return 0 +def _print_plan(planned: list[PlannedFile]) -> None: + print(f"Planned {len(planned)} files:") + section = None + for file in planned: + if file.section != section: + section = file.section + print(f" {section}") + print(f" {file.source.name}") + print(f" from: {file.source}") + print(f" to: {file.destination or 'not copied'}") + print(f" url: {file.url}") + + def _print_summary( project: str, version: str, diff --git a/tests/unit/test_release_plan.py b/tests/unit/test_release_plan.py new file mode 100644 index 00000000..b1d0878d --- /dev/null +++ b/tests/unit/test_release_plan.py @@ -0,0 +1,111 @@ +from pathlib import Path + +from cfengine_cli.release.build import Build, PackageDir +from cfengine_cli.release.plan import PlannedFile, plan_packages + +BUILD = Path("/builds/jenkins-master-nightly-pipeline-123") +OUTPUT = "/var/www/buildcache" +HUB = "PACKAGES_HUB_x86_64_linux_debian_12" +AGENT = "PACKAGES_x86_64_linux_redhat_9" +RHEL7 = "PACKAGES_x86_64_linux_redhat_7" +WINDOWS = "PACKAGES_x86_64_mingw" +S3 = "https://cfengine-package-repos.s3.amazonaws.com" + +# Files in each label dir. Only .deb, .rpm and .msi are platform packages. +FILES = { + HUB: [ + "cfengine-nova-hub-3.30.0-1.x86_64.pkg.tar.gz", + "cfengine-nova-hub_3.30.0-1_amd64.deb", + ], + AGENT: ["cfengine-nova-3.30.0-1.el9.x86_64.rpm"], + # The binary tarball is only published from this label + RHEL7: [ + "cfengine-nova-3.30.0-1.el7.x86_64.rpm", + "cfengine-nova-3.30.0-1.x86_64.pkg.tar.gz", + ], + WINDOWS: ["cfengine-nova-3.30.0-1-x86_64.msi"], +} +TARBALLS = [ + "cfengine-3.30.0.tar.gz", + "cfengine-masterfiles-3.30.0-1.pkg.tar.gz", + "cfengine-masterfiles-3.30.0.tar.gz", +] +VAGRANT = "CFEngine_Enterprise_vagrant_quickstart-3.30.0-1.tar.gz" + + +def _package_dir(label: str, names: list[str]) -> PackageDir: + return PackageDir( + [BUILD / label / name for name in names], BUILD / label / "sha256sums.txt" + ) + + +def _build( + *labels: str, tarballs: list[str] = TARBALLS, vagrant: bool = False +) -> Build: + """A build with the given labels. No files need to exist.""" + return Build( + {label: _package_dir(label, FILES[label]) for label in labels}, + _package_dir("tarballs", tarballs), + _package_dir("vagrant", [VAGRANT]) if vagrant else None, + BUILD.name, + ) + + +def test_plan_packages_enterprise() -> None: + planned = plan_packages("enterprise", "3.30.0", _build(HUB, AGENT), OUTPUT, False) + hub_deb = "cfengine-nova-hub_3.30.0-1_amd64.deb" + hub_path = "enterprise/Enterprise-3.30.0/hub/debian_12_x86_64" + agent_rpm = "cfengine-nova-3.30.0-1.el9.x86_64.rpm" + agent_path = "enterprise/Enterprise-3.30.0/agent/agent_rhel9_x86_64" + # The hub's .pkg.tar.gz is not a platform package, so it is skipped + assert planned == [ + PlannedFile( + source=BUILD / HUB / hub_deb, + destination=Path(OUTPUT) / "release" / hub_path / hub_deb, + url=f"{S3}/{hub_path}/{hub_deb}", + section="Policy Server", + title="Debian 12", + arch="x86_64", + classexpr="am_policy_hub.debian_12.x86_64", + package=HUB, + ), + PlannedFile( + source=BUILD / AGENT / agent_rpm, + destination=Path(OUTPUT) / "release" / agent_path / agent_rpm, + url=f"{S3}/{agent_path}/{agent_rpm}", + section="Hosts (Clients)", + title="Red Hat / CentOS 9", + arch="x86_64", + classexpr="!am_policy_hub.(redhat_9|centos_9).x86_64", + package=AGENT, + ), + ] + + +def test_plan_packages_community() -> None: + [planned] = plan_packages("community", "3.30.0", _build(AGENT), OUTPUT, False) + rpm = "cfengine-nova-3.30.0-1.el9.x86_64.rpm" + path = "community_binaries/Community-3.30.0/agent_rhel9_x86_64" + assert planned.destination == Path(OUTPUT) / "release" / path / rpm + assert planned.url == f"{S3}/{path}/{rpm}" + assert planned.section == "Binary packages" + assert planned.classexpr == "(redhat_9|centos_9).x86_64" + + +def test_plan_packages_debug() -> None: + [planned] = plan_packages("enterprise", "master", _build(AGENT), OUTPUT, True) + assert planned.destination is None + assert planned.url == ( + "http://buildcache.cfengine.com/packages/build-in-container/" + f"jenkins-master-nightly-pipeline-123/{AGENT}/" + "cfengine-nova-3.30.0-1.el9.x86_64.rpm" + ) + + +def test_plan_packages_windows() -> None: + [planned] = plan_packages("enterprise", "3.30.0", _build(WINDOWS), OUTPUT, False) + assert planned.source.name == "cfengine-nova-3.30.0-1-x86_64.msi" + assert planned.url == ( + f"{S3}/enterprise/Enterprise-3.30.0/agent/windows_x86_64/" + "cfengine-nova-3.30.0-1-x86_64.msi" + ) From b5e30a1f2a34a0f5e9391169e3e95fda1a9c93c5 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:42:57 +0100 Subject: [PATCH 05/13] Added planning of additional assets to cfengine dev release Plans the masterfiles tarballs, the binary tarball and the Vagrant quickstart, and for community the source tarballs, in the same order as the legacy release.py lists them. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/release/plan.py | 181 +++++++++++++++++++++++++++- src/cfengine_cli/release/release.py | 6 +- tests/unit/test_release_plan.py | 113 ++++++++++++++++- 3 files changed, 292 insertions(+), 8 deletions(-) diff --git a/src/cfengine_cli/release/plan.py b/src/cfengine_cli/release/plan.py index 6f28b95b..b8e7ad00 100644 --- a/src/cfengine_cli/release/plan.py +++ b/src/cfengine_cli/release/plan.py @@ -1,13 +1,31 @@ +import re from dataclasses import dataclass from pathlib import Path from cfengine_cli.release.build import Build from cfengine_cli.release.platforms import get_platform +from cfengine_cli.utils import UserError S3_URL = "https://cfengine-package-repos.s3.amazonaws.com" BUILDCACHE_URL = "http://buildcache.cfengine.com/packages/build-in-container" +DOCS_URL = "https://docs.cfengine.com/docs" PLATFORM_PACKAGE_SUFFIXES = (".deb", ".rpm", ".msi") +ADDITIONAL_ASSETS = "Additional Assets" +# Matches no host, so self-upgrade policy never picks these files +NO_CLASSEXPR = "!any" +NO_ARCH = "no arch" +# The label whose binary tarball is published, as in the legacy release.py +BINARY_TARBALL_LABEL = "PACKAGES_x86_64_linux_redhat_7" +BINARY_TARBALL_FOOTNOTE = ( + "Tarball containing compiled CFEngine host (client) binaries that runs on " + "most Linux systems but are not optimized for specific library or platform " + "features. Appropriate for testing purposes. Not supported under the " + "CFEngine support contract." +) +BINARY_TARBALL_DOCS = "getting-started-installation-general-installation-installation-enterprise-generic-tarball.html" +VAGRANT_DOCS = "getting-started-installation-general-installation-installation-enterprise-vagrant.html" + # Arguments must be passed with keywords @dataclass(frozen=True, kw_only=True) @@ -26,17 +44,24 @@ class PlannedFile: # buildcache. url: str # Artifact section. "Policy Server" and "Hosts (Clients)" for enterprise - # packages, and "Binary packages" for community packages. + # packages, "Binary packages" for community packages, and "Additional + # Assets" for tarballs and the Vagrant quickstart. section: str - # Shown on the downloads page, e.g. "Debian 12" + # Shown on the downloads page, e.g. "Debian 12" or "Masterfiles source + # tarball" title: str - # e.g. "x86_64" or "aarch64" + # e.g. "x86_64", "aarch64", or "no arch" for tarballs arch: str # Selects the package in self-upgrade policy, e.g. # "!am_policy_hub.debian_12.x86_64" classexpr: str - # Build label the file came from, e.g. "PACKAGES_x86_64_linux_debian_12" - package: str + # Build label the file came from, e.g. "PACKAGES_x86_64_linux_debian_12". + # None for most additional assets. + package: str | None + # Link to installation docs, if any + instructions: str | None = None + # Footnote text, if any + footnote: str | None = None def _section(project: str, hub: bool) -> str: @@ -79,6 +104,12 @@ def _place( return destination, f"{S3_URL}/{release_path}/{name}" +def _docs_url(version: str, page: str) -> str: + """Return a docs link, e.g. for 3.30.0 under docs/3.30/, for master under docs/master/.""" + docs_version = re.sub(r"(\d+\.\d+).*", r"\1", version) + return f"{DOCS_URL}/{docs_version}/{page}" + + def plan_packages( project: str, version: str, @@ -115,3 +146,143 @@ def plan_packages( ) ) return planned + + +def _asset( + source: Path, + release_path: str, + title: str, + build_name: str, + output_dir: str, + debug: bool, + *, + name: str | None = None, + arch: str = NO_ARCH, + package: str | None = None, + instructions: str | None = None, + footnote: str | None = None, +) -> PlannedFile: + """Plan an additional asset. name is the published file name, if not the source's.""" + destination, url = _place( + source, release_path, name or source.name, build_name, output_dir, debug + ) + return PlannedFile( + source=source, + destination=destination, + url=url, + section=ADDITIONAL_ASSETS, + title=title, + arch=arch, + classexpr=NO_CLASSEXPR, + package=package, + instructions=instructions, + footnote=footnote, + ) + + +def plan_assets( + project: str, + version: str, + build: Build, + output_dir: str, + debug: bool, +) -> list[PlannedFile]: + """Plan the additional assets: tarballs and the Vagrant quickstart. + + In the same order as the legacy release.py lists them. + """ + build_name = build.name + misc = f"{_edition_root(project, version)}/misc" + + # Sort tarballs/ by kind + masterfiles_packages: list[Path] = [] + masterfiles_sources: list[Path] = [] + sources: list[Path] = [] + for source in build.tarballs.packages: + if source.name.startswith("cfengine-masterfiles-"): + if source.name.endswith(".pkg.tar.gz"): + masterfiles_packages.append(source) + else: + masterfiles_sources.append(source) + elif source.name.startswith("cfengine-3."): + sources.append(source) + else: + raise UserError(f"Unexpected tarball '{source}'") + + planned: list[PlannedFile] = [] + for source in masterfiles_packages: + planned.append( + _asset( + source, + misc, + "Masterfiles ready-to-install tarball", + build_name, + output_dir, + debug, + package="PACKAGES_VIRTUAL_PACKAGES_masterfiles", + ) + ) + + binary_label = build.labels.get(BINARY_TARBALL_LABEL) + if binary_label is not None: + for source in binary_label.packages: + if source.name.endswith(".pkg.tar.gz"): + planned.append( + _asset( + source, + misc, + "Linux binary tarball (unsupported)", + build_name, + output_dir, + debug, + arch="x86_64", + instructions=_docs_url(version, BINARY_TARBALL_DOCS), + footnote=BINARY_TARBALL_FOOTNOTE, + ) + ) + + if build.vagrant is not None: + if project == "community": + raise UserError("Community releases have no Vagrant quickstart") + for source in build.vagrant.packages: + planned.append( + _asset( + source, + misc, + "Vagrant Environment", + build_name, + output_dir, + debug, + arch="Linux/Mac/Windows (Virtualbox)", + instructions=_docs_url(version, VAGRANT_DOCS), + ) + ) + + # Source tarballs are only published with community releases + if project == "community": + for source in sources: + # cfengine-3.30.0.tar.gz is published as cfengine-community-3.30.0.tar.gz + planned.append( + _asset( + source, + "tarballs", + "Source code tarball", + build_name, + output_dir, + debug, + name=source.name.replace("cfengine-", "cfengine-community-", 1), + ) + ) + for source in masterfiles_sources: + planned.append( + _asset( + source, + "tarballs", + "Masterfiles source tarball", + build_name, + output_dir, + debug, + ) + ) + + return planned diff --git a/src/cfengine_cli/release/release.py b/src/cfengine_cli/release/release.py index 0d49afc4..931aa899 100644 --- a/src/cfengine_cli/release/release.py +++ b/src/cfengine_cli/release/release.py @@ -3,7 +3,7 @@ from cfengine_cli.release.build import read_build from cfengine_cli.release.checksums import verify_build from cfengine_cli.release.metadata import is_nightly, release_branch -from cfengine_cli.release.plan import PlannedFile, plan_packages +from cfengine_cli.release.plan import PlannedFile, plan_assets, plan_packages from cfengine_cli.utils import UserError @@ -33,7 +33,9 @@ def release( build = read_build(build_dir) verify_build(build) - planned = plan_packages(project, version, build, output_dir, debug) + planned = plan_packages(project, version, build, output_dir, debug) + plan_assets( + project, version, build, output_dir, debug + ) _print_plan(planned) return 0 diff --git a/tests/unit/test_release_plan.py b/tests/unit/test_release_plan.py index b1d0878d..55992b9b 100644 --- a/tests/unit/test_release_plan.py +++ b/tests/unit/test_release_plan.py @@ -1,7 +1,15 @@ from pathlib import Path +import pytest + from cfengine_cli.release.build import Build, PackageDir -from cfengine_cli.release.plan import PlannedFile, plan_packages +from cfengine_cli.release.plan import ( + BINARY_TARBALL_FOOTNOTE, + PlannedFile, + plan_assets, + plan_packages, +) +from cfengine_cli.utils import UserError BUILD = Path("/builds/jenkins-master-nightly-pipeline-123") OUTPUT = "/var/www/buildcache" @@ -10,6 +18,7 @@ RHEL7 = "PACKAGES_x86_64_linux_redhat_7" WINDOWS = "PACKAGES_x86_64_mingw" S3 = "https://cfengine-package-repos.s3.amazonaws.com" +DOCS = "https://docs.cfengine.com/docs" # Files in each label dir. Only .deb, .rpm and .msi are platform packages. FILES = { @@ -109,3 +118,105 @@ def test_plan_packages_windows() -> None: f"{S3}/enterprise/Enterprise-3.30.0/agent/windows_x86_64/" "cfengine-nova-3.30.0-1-x86_64.msi" ) + + +def test_plan_assets_enterprise() -> None: + planned = plan_assets( + "enterprise", + "3.30.0", + _build(RHEL7, vagrant=True), + OUTPUT, + False, + ) + # Checks which assets are planned, and that they are in the same order as + # the legacy release.py lists them. No source tarballs, they are only + # published with community releases. + assert [p.title for p in planned] == [ + "Masterfiles ready-to-install tarball", + "Linux binary tarball (unsupported)", + "Vagrant Environment", + ] + assert all(p.section == "Additional Assets" for p in planned) + assert all(p.classexpr == "!any" for p in planned) + assert planned[0].package == "PACKAGES_VIRTUAL_PACKAGES_masterfiles" + + misc = "enterprise/Enterprise-3.30.0/misc" + tarball = "cfengine-nova-3.30.0-1.x86_64.pkg.tar.gz" + assert planned[1] == PlannedFile( + source=BUILD / RHEL7 / tarball, + destination=Path(OUTPUT) / "release" / misc / tarball, + url=f"{S3}/{misc}/{tarball}", + section="Additional Assets", + title="Linux binary tarball (unsupported)", + arch="x86_64", + classexpr="!any", + package=None, + instructions=( + f"{DOCS}/3.30/getting-started-installation-general-installation-" + "installation-enterprise-generic-tarball.html" + ), + footnote=BINARY_TARBALL_FOOTNOTE, + ) + assert planned[2].url == f"{S3}/{misc}/{VAGRANT}" + + +def test_plan_assets_community() -> None: + planned = plan_assets("community", "3.30.0", _build(RHEL7), OUTPUT, False) + # Checks which assets are planned, and that they are in the same order as + # the legacy release.py lists them + assert [p.title for p in planned] == [ + "Masterfiles ready-to-install tarball", + "Linux binary tarball (unsupported)", + "Source code tarball", + "Masterfiles source tarball", + ] + assert planned[0].destination == ( + Path(OUTPUT) + / "release/community_binaries/Community-3.30.0/misc" + / "cfengine-masterfiles-3.30.0-1.pkg.tar.gz" + ) + # The source tarball is published under a community name + source = planned[2] + assert source.source == BUILD / "tarballs" / "cfengine-3.30.0.tar.gz" + assert source.destination == ( + Path(OUTPUT) / "release/tarballs/cfengine-community-3.30.0.tar.gz" + ) + assert source.url == f"{S3}/tarballs/cfengine-community-3.30.0.tar.gz" + assert planned[3].url == f"{S3}/tarballs/cfengine-masterfiles-3.30.0.tar.gz" + + +def test_plan_assets_debug() -> None: + planned = plan_assets("community", "master", _build(RHEL7), OUTPUT, True) + assert all(p.destination is None for p in planned) + buildcache = ( + "http://buildcache.cfengine.com/packages/build-in-container/" + "jenkins-master-nightly-pipeline-123" + ) + assert planned[1].url == ( + f"{buildcache}/{RHEL7}/cfengine-nova-3.30.0-1.x86_64.pkg.tar.gz" + ) + # Debug releases link to the source, so the source tarball keeps its name + assert planned[2].url == f"{buildcache}/tarballs/cfengine-3.30.0.tar.gz" + + +def test_plan_assets_master_docs() -> None: + planned = plan_assets("enterprise", "master", _build(RHEL7), OUTPUT, True) + assert planned[1].instructions is not None + assert planned[1].instructions.startswith(f"{DOCS}/master/") + + +def test_plan_assets_without_binary_tarball_label() -> None: + planned = plan_assets("enterprise", "3.30.0", _build(AGENT), OUTPUT, False) + assert [p.title for p in planned] == ["Masterfiles ready-to-install tarball"] + + +def test_plan_assets_unexpected_tarball() -> None: + build = _build(RHEL7, tarballs=["something-else.tar.gz"]) + with pytest.raises(UserError, match="Unexpected tarball"): + _ = plan_assets("enterprise", "3.30.0", build, OUTPUT, False) + + +def test_plan_assets_community_vagrant() -> None: + build = _build(RHEL7, vagrant=True) + with pytest.raises(UserError, match="no Vagrant quickstart"): + _ = plan_assets("community", "3.30.0", build, OUTPUT, False) From fc635a7f87f4b55d97d66ced1dfb51c9b5b99681 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:45:15 +0100 Subject: [PATCH 06/13] Added copying of release files to cfengine dev release Copies the planned files to the release dir. Each file is written in a temporary directory in the output dir and then renamed, so a published file is always complete. Existing files are skipped, so a failed run can be run again. The output dir is locked while writing, and the disk space is checked first. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/release/copy_files.py | 14 +++ src/cfengine_cli/release/release.py | 12 +++ src/cfengine_cli/release/utils.py | 125 +++++++++++++++++++++++++ tests/unit/test_release_copy_files.py | 68 ++++++++++++++ tests/unit/test_release_utils.py | 39 ++++++++ 5 files changed, 258 insertions(+) create mode 100644 src/cfengine_cli/release/copy_files.py create mode 100644 src/cfengine_cli/release/utils.py create mode 100644 tests/unit/test_release_copy_files.py create mode 100644 tests/unit/test_release_utils.py diff --git a/src/cfengine_cli/release/copy_files.py b/src/cfengine_cli/release/copy_files.py new file mode 100644 index 00000000..62176929 --- /dev/null +++ b/src/cfengine_cli/release/copy_files.py @@ -0,0 +1,14 @@ +from cfengine_cli.release.plan import PlannedFile +from cfengine_cli.release.utils import copy_or_skip + + +def copy_files(planned: list[PlannedFile], output_dir: str, *, dry_run: bool) -> None: + """Copy the planned files to their destinations. + + Existing destinations are skipped, so a failed run can be resumed. Files + without a destination (debug releases) are not copied. + """ + for file in planned: + if file.destination is None: + continue + copy_or_skip(file.source, file.destination, output_dir, dry_run=dry_run) diff --git a/src/cfengine_cli/release/release.py b/src/cfengine_cli/release/release.py index 931aa899..225d98b5 100644 --- a/src/cfengine_cli/release/release.py +++ b/src/cfengine_cli/release/release.py @@ -4,6 +4,12 @@ from cfengine_cli.release.checksums import verify_build from cfengine_cli.release.metadata import is_nightly, release_branch from cfengine_cli.release.plan import PlannedFile, plan_assets, plan_packages +from cfengine_cli.release.copy_files import copy_files +from cfengine_cli.release.utils import ( + check_disk_space, + exit_on_sigterm, + output_lock, +) from cfengine_cli.utils import UserError @@ -20,6 +26,8 @@ def release( if not os.path.isdir(build_dir): raise UserError(f"Build directory '{build_dir}' does not exist") + exit_on_sigterm() + _print_summary( project, version, @@ -37,6 +45,10 @@ def release( project, version, build, output_dir, debug ) _print_plan(planned) + + with output_lock(output_dir, dry_run=dry_run): + check_disk_space([(f.source, f.destination) for f in planned], output_dir) + copy_files(planned, output_dir, dry_run=dry_run) return 0 diff --git a/src/cfengine_cli/release/utils.py b/src/cfengine_cli/release/utils.py new file mode 100644 index 00000000..ae46c362 --- /dev/null +++ b/src/cfengine_cli/release/utils.py @@ -0,0 +1,125 @@ +import fcntl +import shutil +import signal +import sys +import tempfile +from collections.abc import Generator +from contextlib import contextmanager +from pathlib import Path +from types import FrameType +from typing import NoReturn + +from cfengine_cli.utils import UserError + +# In the output dir. Also taken by the legacy release.py in infra. +LOCK_FILE = ".lock" +# Free space to keep on top of the files to copy, as in the legacy release.py. +DISK_SPACE_MARGIN = 1024**3 + + +def exit_on_sigterm() -> None: + """Exit cleanly on SIGTERM, e.g. from an aborted Jenkins job. + + Python's default is to die at once, which leaves temporary files behind. + sys.exit() raises SystemExit, so they are removed on the way out. + """ + + def handler(_signum: int, _frame: FrameType | None) -> NoReturn: + sys.exit(1) + + _ = signal.signal(signal.SIGTERM, handler) + + +@contextmanager +def atomic_write(destination: Path, output_dir: str) -> Generator[Path, None, None]: + """Yield a temporary file to write, then rename it to destination. + + So a file at the destination is always complete. The temporary file is in + a unique directory in the output dir, outside release/, repo/ and + release-data/. So no repo tool or upload picks it up, also not those of + the legacy release.py, and parallel runs never write the same file. It is + on the same filesystem, so the rename is atomic. + """ + Path(output_dir).mkdir(parents=True, exist_ok=True) + destination.parent.mkdir(parents=True, exist_ok=True) + # Removed with its contents on errors, also on Ctrl-C. Only SIGKILL or a + # crash leaves it behind. + with tempfile.TemporaryDirectory(dir=output_dir, prefix=".tmp-") as directory: + temporary = Path(directory) / destination.name + yield temporary + _ = temporary.rename(destination) + + +@contextmanager +def output_lock(output_dir: str, *, dry_run: bool) -> Generator[None, None, None]: + """Hold an exclusive lock on the output dir while writing to it. + + Runs write the same releases.json and repos, so they must not overlap. + The legacy release.py takes the same lock. The kernel releases it when + the process ends, also on SIGKILL. A dry run only reads, so takes none. + """ + if dry_run: + yield + return + Path(output_dir).mkdir(parents=True, exist_ok=True) + with open(Path(output_dir) / LOCK_FILE, "w") as f: + try: + fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB) + except BlockingIOError: + print("Waiting for another release to finish ...", flush=True) + fcntl.flock(f, fcntl.LOCK_EX) + yield + + +def _existing_parent(path: Path) -> Path: + while not path.exists(): + path = path.parent + return path + + +def check_disk_space(copies: list[tuple[Path, Path | None]], output_dir: str) -> None: + """Fail unless output_dir fits the copies, plus a margin. + + copies are (source, destination) pairs. Destinations that are None or + exist already are not copied, so they are not counted. + """ + sizes = [ + source.stat().st_size + for source, destination in copies + if destination is not None and not destination.exists() + ] + if not sizes: + return + needed = sum(sizes) + DISK_SPACE_MARGIN + # The output dir may not exist yet, e.g. locally + free = shutil.disk_usage(_existing_parent(Path(output_dir))).free + if free < needed: + raise UserError( + f"Not enough disk space in '{output_dir}': " + + f"need ~{needed // 1024**2} MiB, only {free // 1024**2} MiB free" + ) + + +def copy_or_skip( + source: Path, destination: Path, output_dir: str, *, dry_run: bool +) -> None: + """Copy source to destination unless it exists, and print what is done.""" + if destination.exists(): + # Already there, e.g. from an earlier run that failed later on + print(f"Warning: Skipped existing '{destination}'") + return + if dry_run: + print(f"Would have copied '{source}' to '{destination}'") + return + copy_file(source, destination, output_dir) + print(f"Copied '{source}' to '{destination}'") + + +def copy_file(source: Path, destination: Path, output_dir: str) -> None: + """Copy source to destination. + + The copy is written in a temporary directory in output_dir, see + atomic_write(). + """ + with atomic_write(destination, output_dir) as temporary: + _ = shutil.copyfile(source, temporary) diff --git a/tests/unit/test_release_copy_files.py b/tests/unit/test_release_copy_files.py new file mode 100644 index 00000000..9f3ddd3e --- /dev/null +++ b/tests/unit/test_release_copy_files.py @@ -0,0 +1,68 @@ +from pathlib import Path + +import pytest + +from cfengine_cli.release.plan import PlannedFile +from cfengine_cli.release.copy_files import copy_files + + +def _planned(source: Path, destination: Path | None) -> PlannedFile: + return PlannedFile( + source=source, + destination=destination, + url="url", + section="Section", + title="Title", + arch="x86_64", + classexpr="any", + package=None, + ) + + +def _built(tmp_path: Path, name: str) -> Path: + source = tmp_path / "build" / name + source.parent.mkdir(exist_ok=True) + _ = source.write_text("built") + return source + + +@pytest.fixture +def tarball(tmp_path: Path) -> Path: + return _built(tmp_path, "cfengine-masterfiles-3.30.0-1.pkg.tar.gz") + + +def test_copy_files(tmp_path: Path, tarball: Path) -> None: + destination = tmp_path / "release" / tarball.name + copy_files([_planned(tarball, destination)], str(tmp_path), dry_run=False) + assert destination.read_text() == "built" + # No temporary dir left + assert list(tmp_path.glob(".tmp-*")) == [] + + +def test_copy_files_skips_existing( + tmp_path: Path, tarball: Path, capsys: pytest.CaptureFixture[str] +) -> None: + destination = tmp_path / "release" / tarball.name + destination.parent.mkdir() + _ = destination.write_text("published") + copy_files([_planned(tarball, destination)], str(tmp_path), dry_run=False) + assert destination.read_text() == "published" + assert f"Warning: Skipped existing '{destination}'" in capsys.readouterr().out + + +def test_copy_files_skips_debug( + tmp_path: Path, tarball: Path, capsys: pytest.CaptureFixture[str] +) -> None: + copy_files([_planned(tarball, None)], str(tmp_path), dry_run=False) + assert capsys.readouterr().out == "" + + +def test_copy_files_dry_run( + tmp_path: Path, tarball: Path, capsys: pytest.CaptureFixture[str] +) -> None: + destination = tmp_path / "release" / tarball.name + copy_files([_planned(tarball, destination)], str(tmp_path), dry_run=True) + assert not destination.parent.exists() + assert capsys.readouterr().out == ( + f"Would have copied '{tarball}' to '{destination}'\n" + ) diff --git a/tests/unit/test_release_utils.py b/tests/unit/test_release_utils.py new file mode 100644 index 00000000..d93a0efa --- /dev/null +++ b/tests/unit/test_release_utils.py @@ -0,0 +1,39 @@ +import fcntl +from pathlib import Path + +import pytest + +from cfengine_cli.release.utils import atomic_write, output_lock + + +def test_atomic_write_error(tmp_path: Path) -> None: + destination = tmp_path / "release" / "cfengine-nova_3.30.0-1_amd64.deb" + with pytest.raises(RuntimeError): + with atomic_write(destination, str(tmp_path)) as temporary: + _ = temporary.write_text("half written") + raise RuntimeError + assert not destination.exists() + assert list(tmp_path.glob(".tmp-*")) == [] + + +def _try_lock(path: Path) -> bool: + """Return True if the lock is free, as another release would see it.""" + with open(path, "w") as f: + try: + fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB) + return True + except BlockingIOError: + return False + + +def test_output_lock(tmp_path: Path) -> None: + with output_lock(str(tmp_path), dry_run=False): + assert not _try_lock(tmp_path / ".lock") + assert _try_lock(tmp_path / ".lock") + + +def test_output_lock_dry_run(tmp_path: Path) -> None: + output = tmp_path / "output" + with output_lock(str(output), dry_run=True): + pass + assert not output.exists() From 77803ae3ae5342bd8bcef4677a4ce9be959b791d Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:46:06 +0100 Subject: [PATCH 07/13] Added signing of packages to cfengine dev release Signs the .rpm and .deb copies with the release key. Signing is reproducible: the signature time is the build time of the package, set from SOURCE_DATE_EPOCH by build-in-container, so signing the same build with the same key gives identical files. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/release/copy_files.py | 26 ++++++- src/cfengine_cli/release/utils.py | 95 ++++++++++++++++++++++++-- tests/unit/test_release_copy_files.py | 21 +++++- tests/unit/test_release_utils.py | 19 +++++- 4 files changed, 150 insertions(+), 11 deletions(-) diff --git a/src/cfengine_cli/release/copy_files.py b/src/cfengine_cli/release/copy_files.py index 62176929..5d11c7eb 100644 --- a/src/cfengine_cli/release/copy_files.py +++ b/src/cfengine_cli/release/copy_files.py @@ -1,14 +1,34 @@ from cfengine_cli.release.plan import PlannedFile -from cfengine_cli.release.utils import copy_or_skip +from cfengine_cli.release.utils import SIGNED_SUFFIXES, check_tools, copy_or_skip + +SIGNING_TOOLS = ("rpm", "rpmsign", "debsigs") + + +def _to_copy(planned: list[PlannedFile]) -> list[PlannedFile]: + """Return the files with a destination that does not exist yet.""" + return [ + file + for file in planned + if file.destination is not None and not file.destination.exists() + ] def copy_files(planned: list[PlannedFile], output_dir: str, *, dry_run: bool) -> None: - """Copy the planned files to their destinations. + """Copy the planned files to their destinations, signing .rpm and .deb. Existing destinations are skipped, so a failed run can be resumed. Files without a destination (debug releases) are not copied. """ + to_sign = [ + file for file in _to_copy(planned) if file.source.name.endswith(SIGNED_SUFFIXES) + ] + if to_sign: + check_tools("Signing", SIGNING_TOOLS) + for file in planned: if file.destination is None: continue - copy_or_skip(file.source, file.destination, output_dir, dry_run=dry_run) + signed = file.source.name.endswith(SIGNED_SUFFIXES) + copy_or_skip( + file.source, file.destination, output_dir, signed=signed, dry_run=dry_run + ) diff --git a/src/cfengine_cli/release/utils.py b/src/cfengine_cli/release/utils.py index ae46c362..7d3c73df 100644 --- a/src/cfengine_cli/release/utils.py +++ b/src/cfengine_cli/release/utils.py @@ -1,6 +1,7 @@ import fcntl import shutil import signal +import subprocess import sys import tempfile from collections.abc import Generator @@ -11,10 +12,15 @@ from cfengine_cli.utils import UserError +SIGNED_SUFFIXES = (".rpm", ".deb") +# Signs the packages and the repo metadata. Always named, as gpg silently +# falls back to the default key for --default-key or no key. +SIGNING_KEY = "contact@northern.tech" # In the output dir. Also taken by the legacy release.py in infra. LOCK_FILE = ".lock" # Free space to keep on top of the files to copy, as in the legacy release.py. DISK_SPACE_MARGIN = 1024**3 +AR_MAGIC = b"!\n" def exit_on_sigterm() -> None: @@ -30,6 +36,78 @@ def handler(_signum: int, _frame: FrameType | None) -> NoReturn: _ = signal.signal(signal.SIGTERM, handler) +def run(command: list[str]) -> str: + """Run a command and return its stdout. stderr goes to the terminal.""" + try: + return subprocess.run( + command, check=True, stdout=subprocess.PIPE, text=True + ).stdout + except subprocess.CalledProcessError as e: + # A UserError, as a failed command is not a bug in cfengine-cli + raise UserError(f"Command failed: {' '.join(command)}") from e + + +def _deb_build_time(path: Path) -> int: + """Return the mtime of the first ar member, set from SOURCE_DATE_EPOCH.""" + with open(path, "rb") as f: + header = f.read(len(AR_MAGIC) + 60) + if not header.startswith(AR_MAGIC) or len(header) < len(AR_MAGIC) + 60: + raise UserError(f"Not a .deb: '{path}'") + # An ar member header starts with a 16 byte name, then a 12 byte mtime + mtime = header[len(AR_MAGIC) + 16 : len(AR_MAGIC) + 28] + return int(mtime.decode("ascii")) + + +def _rpm_build_time(path: Path) -> int: + """Return BUILDTIME, set from SOURCE_DATE_EPOCH by build-in-container.""" + # Skip signature checking. The package is not signed yet, and checking + # needs the rpm database, which Debian hosts lack. + return int(run(["rpm", "-qp", "--nosignature", "--qf", "%{BUILDTIME}", str(path)])) + + +def build_time(path: Path) -> int: + """Return the package's SOURCE_DATE_EPOCH.""" + if path.name.endswith(".rpm"): + return _rpm_build_time(path) + return _deb_build_time(path) + + +def sign(path: Path, time: int) -> None: + """Sign a .rpm or .deb with the given signature creation time. + + A fixed time makes the signed package reproducible with the same key. + """ + # The "!" stops the faked clock, so the time does not tick during signing + faked_time = f"--faked-system-time {time}!" + if path.name.endswith(".rpm"): + _ = run( + [ + "rpmsign", + "--resign", + "--digest-algo=sha256", + "--define", + f"_gpg_name {SIGNING_KEY}", + "--define", + f"_gpg_sign_cmd_extra_args {faked_time}", + str(path), + ] + ) + else: + # debsigs has no strict key option, its -k is --default-key + gpgopts = f"{faked_time} --local-user {SIGNING_KEY}" + _ = run(["debsigs", "--sign=origin", f"--gpgopts={gpgopts}", str(path)]) + # debsigs can print an error, yet exit 0 with an unsigned package. + # So check that the signature is there and good. + _ = run(["debsigs", "--verify", str(path)]) + + +def check_tools(kind: str, tools: tuple[str, ...]) -> None: + """Fail before any work if a tool is missing, e.g. kind "Signing".""" + missing = [tool for tool in tools if shutil.which(tool) is None] + if missing: + raise UserError(f"{kind} tools not found: {', '.join(missing)}") + + @contextmanager def atomic_write(destination: Path, output_dir: str) -> Generator[Path, None, None]: """Yield a temporary file to write, then rename it to destination. @@ -45,6 +123,7 @@ def atomic_write(destination: Path, output_dir: str) -> Generator[Path, None, No # Removed with its contents on errors, also on Ctrl-C. Only SIGKILL or a # crash leaves it behind. with tempfile.TemporaryDirectory(dir=output_dir, prefix=".tmp-") as directory: + # The destination name, as sign() needs the .rpm or .deb suffix temporary = Path(directory) / destination.name yield temporary _ = temporary.rename(destination) @@ -101,7 +180,7 @@ def check_disk_space(copies: list[tuple[Path, Path | None]], output_dir: str) -> def copy_or_skip( - source: Path, destination: Path, output_dir: str, *, dry_run: bool + source: Path, destination: Path, output_dir: str, *, signed: bool, dry_run: bool ) -> None: """Copy source to destination unless it exists, and print what is done.""" if destination.exists(): @@ -110,16 +189,22 @@ def copy_or_skip( return if dry_run: print(f"Would have copied '{source}' to '{destination}'") + if signed: + print(f"Would have signed '{destination}'") return - copy_file(source, destination, output_dir) - print(f"Copied '{source}' to '{destination}'") + copy_file(source, destination, output_dir, signed=signed) + print(f"Copied '{source}' to '{destination}'{' and signed' if signed else ''}") -def copy_file(source: Path, destination: Path, output_dir: str) -> None: - """Copy source to destination. +def copy_file( + source: Path, destination: Path, output_dir: str, *, signed: bool +) -> None: + """Copy source to destination, and sign the copy if signed. The copy is written in a temporary directory in output_dir, see atomic_write(). """ with atomic_write(destination, output_dir) as temporary: _ = shutil.copyfile(source, temporary) + if signed: + sign(temporary, build_time(source)) diff --git a/tests/unit/test_release_copy_files.py b/tests/unit/test_release_copy_files.py index 9f3ddd3e..7a53539c 100644 --- a/tests/unit/test_release_copy_files.py +++ b/tests/unit/test_release_copy_files.py @@ -4,6 +4,7 @@ from cfengine_cli.release.plan import PlannedFile from cfengine_cli.release.copy_files import copy_files +from cfengine_cli.utils import UserError def _planned(source: Path, destination: Path | None) -> PlannedFile: @@ -28,9 +29,16 @@ def _built(tmp_path: Path, name: str) -> Path: @pytest.fixture def tarball(tmp_path: Path) -> Path: + """Copied, but not signed.""" return _built(tmp_path, "cfengine-masterfiles-3.30.0-1.pkg.tar.gz") +@pytest.fixture +def rpm(tmp_path: Path) -> Path: + """Signed when copied, so these tests never copy it.""" + return _built(tmp_path, "cfengine-nova-3.30.0-1.el9.x86_64.rpm") + + def test_copy_files(tmp_path: Path, tarball: Path) -> None: destination = tmp_path / "release" / tarball.name copy_files([_planned(tarball, destination)], str(tmp_path), dry_run=False) @@ -51,9 +59,9 @@ def test_copy_files_skips_existing( def test_copy_files_skips_debug( - tmp_path: Path, tarball: Path, capsys: pytest.CaptureFixture[str] + tmp_path: Path, rpm: Path, capsys: pytest.CaptureFixture[str] ) -> None: - copy_files([_planned(tarball, None)], str(tmp_path), dry_run=False) + copy_files([_planned(rpm, None)], str(tmp_path), dry_run=False) assert capsys.readouterr().out == "" @@ -66,3 +74,12 @@ def test_copy_files_dry_run( assert capsys.readouterr().out == ( f"Would have copied '{tarball}' to '{destination}'\n" ) + + +def test_copy_files_missing_signing_tools( + tmp_path: Path, rpm: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setenv("PATH", str(tmp_path)) + destination = tmp_path / "release" / rpm.name + with pytest.raises(UserError, match="Signing tools not found"): + copy_files([_planned(rpm, destination)], str(tmp_path), dry_run=True) diff --git a/tests/unit/test_release_utils.py b/tests/unit/test_release_utils.py index d93a0efa..eb78675d 100644 --- a/tests/unit/test_release_utils.py +++ b/tests/unit/test_release_utils.py @@ -3,7 +3,24 @@ import pytest -from cfengine_cli.release.utils import atomic_write, output_lock +from cfengine_cli.release.utils import atomic_write, build_time, output_lock, run +from cfengine_cli.utils import UserError + + +def test_build_time_not_a_deb(tmp_path: Path) -> None: + deb = tmp_path / "cfengine-nova_3.30.0-1_amd64.deb" + _ = deb.write_text("not an ar archive") + with pytest.raises(UserError, match="Not a .deb"): + _ = build_time(deb) + + +def test_run() -> None: + assert run(["sh", "-c", "echo out; echo warning >&2"]) == "out\n" + + +def test_run_fails_on_exit_status() -> None: + with pytest.raises(UserError, match="Command failed: sh -c exit 1"): + _ = run(["sh", "-c", "exit 1"]) def test_atomic_write_error(tmp_path: Path) -> None: From f4878bd5442164c1e84f27f9eaabaea8dc8d1d2f Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:46:41 +0100 Subject: [PATCH 08/13] Added release data formats and version logic The formats of releases.json and the per-version documents, and the version rules behind them: sorting, LTS branches, support dates, titles and the latest flags. They give the same results as the legacy release.py. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/release/metadata.py | 292 ++++++++++++++++++++++++++ tests/unit/test_release_metadata.py | 295 ++++++++++++++++++++++++++- 2 files changed, 586 insertions(+), 1 deletion(-) diff --git a/src/cfengine_cli/release/metadata.py b/src/cfengine_cli/release/metadata.py index 0103ad5b..122b9a74 100644 --- a/src/cfengine_cli/release/metadata.py +++ b/src/cfengine_cli/release/metadata.py @@ -1,4 +1,74 @@ +import copy +import datetime import re +from typing import Required, TypedDict + +RELEASE_DATA_URL = "https://cfengine-package-repos.s3.amazonaws.com/release-data" + + +class LtsBranch(TypedDict): + """An entry in lts_branches in releases.json.""" + + branch_name: str # e.g. 3.27.x, or nightly-3.27.x for community nightlies + supported_until: str # YYYY-MM + + +class Release(TypedDict, total=False): + """An entry in releases in releases.json. Old entries lack some keys.""" + + version: Required[str] # e.g. 3.27.0, or 3.27.x / master for nightlies + URL: str # Of release-data//.json. + debug: bool # Nightly, hidden from downloads and from the latest flags + release_date: str # YYYY-MM-DD, or "nightly" + lts_branch: str # branch_name of the LTS branch it belongs to + alpha: bool # Legacy, only on old entries + beta: bool # Legacy, only on old entries like 3.15.0b1 + latest: bool # Newest non-debug release + latest_stable: bool # Newest non-debug release that is not a beta + latest_on_branch: bool # Newest stable release on its LTS branch + latestLTS: bool # latest_on_branch of the newest LTS branch + + +class ReleasesData(TypedDict): + """The contents of releases.json.""" + + lts_branches: list[LtsBranch] + releases: list[Release] + + +class Artifact(TypedDict, total=False): + """A downloadable file in release-data//.json.""" + + Title: Required[str] # e.g. Debian 12 + Arch: Required[str] # e.g. x86_64, or "no arch" + classexpr: Required[str] # Selects the package in self-upgrade policy + Published: Required[bool] # False hides it from the downloads page + URL: Required[str] # cf-remote reads "URL" + SHA256: Required[str] + package: str # Build label, e.g. PACKAGES_x86_64_linux_debian_12 + Footnote: int # 1-based index into footnotes + Instructions: str # Link to installation docs + + +class VersionDocument(TypedDict, total=False): + """The contents of release-data//.json.""" + + project: Required[str] + version: Required[str] # The title, from version_title() + nightly_release_date: str # Only for nightlies + note: str # Only for non-LTS versions + # Always set, but not Required, so version_document() can add them after + # the optional keys. The key order matters, see version_document(). + # Section title, e.g. "Policy Server", mapped to its artifacts + artifacts: dict[str, list[Artifact]] + footnotes: list[str] + + +NON_LTS_NOTE = ( + 'Please note that non-LTS releases are ' + "unsupported, i.e. excluded from CFEngine Enterprise support " + "contract, and we do not recommend installing them in production." +) def is_nightly(version: str) -> bool: @@ -17,3 +87,225 @@ def release_branch(project: str, version: str) -> str: if project == "community": return f"nightly-{version}" return version + + +def release_data_url(project: str, version: str) -> str: + """Return the URL of release-data//.json.""" + return f"{RELEASE_DATA_URL}/{project}/{version}.json" + + +def version_key(version: str) -> tuple[int, ...]: + """Sort key for versions in releases.json. + + master > 3.30.x > 3.30.0 > 3.27.0 > 3.15.0 > 3.15.0b1. We no longer + release betas, but releases.json still has old ones like 3.15.0b1. + """ + if version == "master": + return (999,) + match = re.fullmatch(r"(\d+(?:\.\d+)*)(.*)", version) + if not match: + return (0,) + parts = [int(x) for x in match.group(1).split(".")] + remainder = match.group(2) + if remainder == ".x": + # A branch nightly sorts above every release on its branch + parts.append(999) + suffix = (2, 0) + elif remainder == "": + suffix = (2, 0) + elif remainder.startswith("b"): + suffix = (1, int(remainder[1:])) + elif remainder.startswith("a"): + suffix = (0, int(remainder[1:])) + else: + suffix = (0, 0) + return tuple(parts) + suffix + + +def _minor(version: str) -> int: + """Return the minor version, e.g. 30 for 3.30.0, or 0 for master.""" + match = re.match(r"\d+\.(\d+)", version) + return int(match.group(1)) if match else 0 + + +def is_lts(version: str) -> bool: + """Return True if the version is on an LTS branch, e.g. 3.27.x or 3.30.x.""" + minor = _minor(version) + if minor < 11: + return minor % 3 == 1 # 3.7, 3.10 + return minor % 3 == 0 # 3.12, 3.15, ... + + +def support_end(version: str) -> tuple[str, str]: + """Return when the version's branch goes out of support. + + E.g. ("2028-12", "December 2028") for 3.27.x. + """ + # Same formula as the legacy release.py in the infra repo. LTS branches + # come 1.5 years apart, so their support ends alternate between December + # of one year and August of the next. The value below is a year as a + # decimal number. (minor + 1) / 2 is a whole number or ends in .5, so + # adding 2014.4 makes it end in .4 or .9. Rounding then gives the year: + # .4 rounds down and means December, .9 rounds up and means August. + # E.g. 3.27: 2028.4 -> December 2028, 3.30: 2029.9 -> August 2030. + minor = _minor(version) + if minor < 11: + value = minor / 2 + 2014.4 + else: + value = (minor + 1) / 2 + 2014.4 + year = round(value) + if value - year > 0.2: + return f"{year}-12", f"December {year}" + return f"{year}-08", f"August {year}" + + +def version_title(project: str, version: str) -> str: + """Return the title shown for a version. + + E.g. "3.27.0 LTS (supported until December 2028)" for enterprise. + """ + enterprise = project == "enterprise" + if is_lts(version): + title = f"{version} LTS" + if enterprise: + _, until = support_end(version) + title += f" (supported until {until})" + return title + title = f"{version} non-LTS" + if enterprise: + title += " (unsupported)" + return title + + +def update_releases( + releases_data: ReleasesData, + project: str, + version: str, + branch: str, + debug: bool, + today: datetime.date, +) -> ReleasesData: + """Returns a copy of releases.json with the version added and the latest flags redone.""" + data = copy.deepcopy(releases_data) + branches = data["lts_branches"] + + releases = _without_version(data["releases"], version) + release = _new_release(project, version, debug, today) + releases.append(release) + + if _in_lts_branches(version, branch): + _attach_to_branch(release, branches, branch) + + releases.sort(key=lambda r: version_key(r["version"]), reverse=True) + _clear_latest_flags(releases) + _set_latest_flags(releases, branches) + + return {"lts_branches": branches, "releases": releases} + + +def _in_lts_branches(version: str, branch: str) -> bool: + """Return True if the release is listed under a branch in lts_branches. + + That is LTS versions, and community master nightlies. master is not LTS, + but the legacy release.py has always listed it under the nightly-master + branch, which makes "cf-remote install --version nightly-master" work. + """ + return is_lts(version) or branch == "nightly-master" + + +def _without_version(releases: list[Release], version: str) -> list[Release]: + """Drop any existing entry for the version, so re-releasing does not become a duplicate entry.""" + return [r for r in releases if r["version"] != version] + + +def _new_release( + project: str, version: str, debug: bool, today: datetime.date +) -> Release: + return { + "version": version, + "URL": release_data_url(project, version), + "debug": debug, + "release_date": "nightly" if is_nightly(version) else str(today), + } + + +def _attach_to_branch(release: Release, branches: list[LtsBranch], branch: str) -> None: + """Attach the release to its branch. + + So cf-remote can expire it, and the per-branch flags can find it. + """ + release["lts_branch"] = branch + # Add the branch the first time a release is made on it. Newest first, + # as _set_branch_flags expects. + if not any(b["branch_name"] == branch for b in branches): + date, _ = support_end(release["version"]) + branches.insert(0, {"branch_name": branch, "supported_until": date}) + + +def _clear_latest_flags(releases: list[Release]) -> None: + """Drop existing latest flags so they can be recomputed.""" + for release in releases: + _ = release.pop("latest", None) + _ = release.pop("latest_stable", None) + _ = release.pop("latest_on_branch", None) + _ = release.pop("latestLTS", None) + + +def _set_latest_flags(releases: list[Release], branches: list[LtsBranch]) -> None: + """Set the latest flags. releases must be sorted newest first.""" + # Nightlies are debug releases and never get the latest flags. Only the + # first, i.e. newest, entry gets the flag. + published = [r for r in releases if not r.get("debug")] + if published: + published[0]["latest"] = True + + # Skip old betas like 3.15.0b1 + stable = [r for r in published if "b" not in r["version"]] + if stable: + stable[0]["latest_stable"] = True + + _set_branch_flags(stable, branches) + + +def _set_branch_flags(stable: list[Release], branches: list[LtsBranch]) -> None: + """Mark the newest stable release on each branch. + + lts_branches is newest first, so the first branch with a stable release + also holds the latest LTS release. cf-remote uses latestLTS as its + default version. + """ + found_latest_lts = False + for b in branches: + on_branch = [r for r in stable if r.get("lts_branch") == b["branch_name"]] + if not on_branch: + continue + on_branch[0]["latest_on_branch"] = True + if not found_latest_lts: + on_branch[0]["latestLTS"] = True + found_latest_lts = True + + +def version_document( + project: str, + version: str, + branch: str, + artifacts: dict[str, list[Artifact]], + footnotes: list[str], + today: datetime.date, +) -> VersionDocument: + """Return the contents of release-data//.json.""" + # Built in the key order of the legacy release.py, with the optional keys + # before the artifacts + doc: VersionDocument = { + "project": project, + "version": version_title(project, version), + } + if is_nightly(version): + doc["nightly_release_date"] = str(today) + # Same as the legacy release.py: no note for releases in lts_branches. So + # community master nightlies have no note, while enterprise ones do. + if not _in_lts_branches(version, branch): + doc["note"] = NON_LTS_NOTE + doc["artifacts"] = artifacts + doc["footnotes"] = footnotes + return doc diff --git a/tests/unit/test_release_metadata.py b/tests/unit/test_release_metadata.py index fc1dc79f..f34188b8 100644 --- a/tests/unit/test_release_metadata.py +++ b/tests/unit/test_release_metadata.py @@ -1,6 +1,299 @@ +import copy +import datetime + import pytest -from cfengine_cli.release.metadata import release_branch +from cfengine_cli.release.metadata import ( + NON_LTS_NOTE, + Release, + ReleasesData, + is_lts, + release_branch, + support_end, + update_releases, + version_document, + version_key, + version_title, +) + +# Every version in the published enterprise releases.json, highest first +EXPECTED = [ + "master", "3.27.x", "3.27.0", "3.26.0", "3.25.0", "3.24.x", + "3.24.3", "3.24.2", "3.24.1", "3.24.0", "3.23.0", "3.22.0", + "3.21.x", "3.21.8", "3.21.7", "3.21.6", "3.21.5", "3.21.4", + "3.21.3", "3.21.2", "3.21.1", "3.21.0", "3.20.0", "3.19.0", + "3.18.x", "3.18.8", "3.18.7", "3.18.6", "3.18.5", "3.18.4", + "3.18.3", "3.18.2", "3.18.1", "3.18.0", "3.17.0", "3.16.0", + "3.15.x", "3.15.7", "3.15.6", "3.15.5", "3.15.4", "3.15.3", + "3.15.2", "3.15.1", "3.15.0", "3.15.0b1", "3.14.0", "3.13.0", + "3.12.x", "3.12.7", "3.12.6", "3.12.5", "3.12.4", "3.12.3", + "3.12.2", "3.12.1", "3.12.0", "3.11.0", "3.11.0b1", "3.10.x", + "3.10.7", "3.10.6", "3.10.5", "3.10.4", "3.10.3", "3.10.2", + "3.10.1", "3.10.0", "3.9.2", "3.9.0", "3.9.0b1", "3.8.2", + "3.8.1", "3.8.0", "3.8.0b1", "3.7.8", "3.7.7", "3.7.6", + "3.7.5", "3.7.4", "3.7.3", "3.7.2", "3.7.1", "3.7.0", + "3.6.7", "3.6.6", "3.6.5", "3.6.4", "3.6.3", "3.6.2", + "3.6.1", "3.6.0", +] # fmt: skip + + +def test_version_key_stable_releases() -> None: + assert version_key("3.24.0") > version_key("3.9.2") + assert version_key("3.10.0") > version_key("3.9.2") + assert version_key("3.27.0") > version_key("3.24.3") + + +def test_version_key_pre_releases() -> None: + assert version_key("3.15.0") > version_key("3.15.0b1") + assert version_key("3.15.0b1") > version_key("3.15.0a1") + assert version_key("3.15.0b1") > version_key("3.15.0a2") + assert version_key("3.15.0b2") > version_key("3.15.0b1") + + +def test_version_key_branch_nightlies() -> None: + assert version_key("3.27.x") > version_key("3.27.0") + assert version_key("3.27.x") > version_key("3.24.x") + assert version_key("3.30.0") > version_key("3.27.x") + + +def test_version_key_master() -> None: + assert version_key("master") > version_key("3.30.x") + + +def test_version_key_unknown() -> None: + assert version_key("unknown") < version_key("3.6.0") + + +def test_version_key_sort_order() -> None: + # Sorting as strings scrambles the order, e.g. 3.10.0 before 3.9.2 + assert sorted(sorted(EXPECTED), key=version_key, reverse=True) == EXPECTED + + +@pytest.mark.parametrize( + "version", ["3.7.0", "3.10.0", "3.12.0", "3.24.3", "3.27.0", "3.30.0", "3.30.x"] +) +def test_is_lts(version: str) -> None: + assert is_lts(version) + + +@pytest.mark.parametrize( + "version", ["3.8.0", "3.11.0", "3.26.0", "3.28.0", "3.29.0", "3.31.0", "master"] +) +def test_is_not_lts(version: str) -> None: + assert not is_lts(version) + + +# supported_until of each LTS branch in the published enterprise releases.json, +# plus 3.30.x +@pytest.mark.parametrize( + "version, date", + [ + ("3.7.x", "2018-08"), + ("3.10.x", "2019-12"), + ("3.12.x", "2021-08"), + ("3.15.x", "2022-12"), + ("3.18.x", "2024-08"), + ("3.21.x", "2025-12"), + ("3.24.x", "2027-08"), + ("3.27.x", "2028-12"), + ("3.30.x", "2030-08"), + ], +) +def test_support_end_date(version: str, date: str) -> None: + assert support_end(version)[0] == date + + +def test_support_end_text() -> None: + assert support_end("3.27.0") == ("2028-12", "December 2028") + assert support_end("3.30.0") == ("2030-08", "August 2030") + + +# The first 8 are from the published release-data//.json +@pytest.mark.parametrize( + "project, version, title", + [ + ("enterprise", "master", "master non-LTS (unsupported)"), + ("enterprise", "3.27.x", "3.27.x LTS (supported until December 2028)"), + ("enterprise", "3.27.0", "3.27.0 LTS (supported until December 2028)"), + ("enterprise", "3.26.0", "3.26.0 non-LTS (unsupported)"), + ("community", "master", "master non-LTS"), + ("community", "3.27.x", "3.27.x LTS"), + ("community", "3.27.0", "3.27.0 LTS"), + ("community", "3.26.0", "3.26.0 non-LTS"), + ("enterprise", "3.30.0", "3.30.0 LTS (supported until August 2030)"), + ("enterprise", "3.31.0", "3.31.0 non-LTS (unsupported)"), + ], +) +def test_version_title(project: str, version: str, title: str) -> None: + assert version_title(project, version) == title + + +TODAY = datetime.date(2027, 6, 1) + + +@pytest.fixture +def releases_data() -> ReleasesData: + """A small releases.json, shaped like the published enterprise one.""" + return { + "lts_branches": [ + {"branch_name": "3.27.x", "supported_until": "2028-12"}, + {"branch_name": "3.24.x", "supported_until": "2027-08"}, + ], + "releases": [ + Release(version="master", debug=True, release_date="nightly", alpha=True), + Release(version="3.29.0", debug=False, latest=True, latest_stable=True), + Release( + version="3.27.x", + debug=True, + release_date="nightly", + lts_branch="3.27.x", + ), + Release( + version="3.27.3", + debug=False, + lts_branch="3.27.x", + latest_on_branch=True, + latestLTS=True, + ), + Release( + version="3.24.6", + debug=False, + lts_branch="3.24.x", + latest_on_branch=True, + ), + Release(version="3.15.0b1", debug=False, beta=True), + ], + } + + +def _flags(data: ReleasesData) -> dict[str, list[str]]: + """Return which versions have which latest flags.""" + flags = ("latest", "latest_stable", "latest_on_branch", "latestLTS") + return { + f: [r["version"] for r in data["releases"] if dict(r).get(f)] for f in flags + } + + +def _entry(data: ReleasesData, version: str) -> Release: + return next(r for r in data["releases"] if r["version"] == version) + + +def test_update_releases_lts(releases_data: ReleasesData) -> None: + data = update_releases( + releases_data, "enterprise", "3.30.0", "3.30.x", False, TODAY + ) + assert _entry(data, "3.30.0") == { + "version": "3.30.0", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.30.0.json", + "debug": False, + "release_date": "2027-06-01", + "lts_branch": "3.30.x", + "latest": True, + "latest_stable": True, + "latest_on_branch": True, + "latestLTS": True, + } + assert data["lts_branches"][0] == { + "branch_name": "3.30.x", + "supported_until": "2030-08", + } + assert _flags(data) == { + "latest": ["3.30.0"], + "latest_stable": ["3.30.0"], + "latest_on_branch": ["3.30.0", "3.27.3", "3.24.6"], + "latestLTS": ["3.30.0"], + } + + +def test_update_releases_non_lts(releases_data: ReleasesData) -> None: + data = update_releases( + releases_data, "enterprise", "3.31.0", "3.31.x", False, TODAY + ) + assert "lts_branch" not in _entry(data, "3.31.0") + assert len(data["lts_branches"]) == 2 + assert _flags(data) == { + "latest": ["3.31.0"], + "latest_stable": ["3.31.0"], + "latest_on_branch": ["3.27.3", "3.24.6"], + "latestLTS": ["3.27.3"], + } + + +def test_update_releases_enterprise_master(releases_data: ReleasesData) -> None: + data = update_releases(releases_data, "enterprise", "master", "master", True, TODAY) + # No "alpha": the legacy release.py set it only because "master" contains + # an "a" + assert _entry(data, "master") == { + "version": "master", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/master.json", + "debug": True, + "release_date": "nightly", + } + assert data["releases"][0]["version"] == "master" + assert _flags(data) == _flags(releases_data) + + +def test_update_releases_community_master(releases_data: ReleasesData) -> None: + data = update_releases( + releases_data, "community", "master", "nightly-master", True, TODAY + ) + assert _entry(data, "master").get("lts_branch") == "nightly-master" + assert data["lts_branches"][0]["branch_name"] == "nightly-master" + + +def test_update_releases_replaces_existing(releases_data: ReleasesData) -> None: + data = update_releases( + releases_data, "enterprise", "3.27.3", "3.27.x", False, TODAY + ) + assert [r["version"] for r in data["releases"]].count("3.27.3") == 1 + assert _entry(data, "3.27.3").get("release_date") == "2027-06-01" + + +def test_update_releases_skips_old_beta(releases_data: ReleasesData) -> None: + for release in releases_data["releases"]: + if release["version"] != "3.15.0b1": + release["debug"] = True + data = update_releases(releases_data, "enterprise", "master", "master", True, TODAY) + assert _flags(data)["latest"] == ["3.15.0b1"] + assert _flags(data)["latest_stable"] == [] + + +def test_update_releases_does_not_modify_input(releases_data: ReleasesData) -> None: + original = copy.deepcopy(releases_data) + _ = update_releases(releases_data, "enterprise", "3.30.0", "3.30.x", False, TODAY) + assert releases_data == original + + +def test_version_document() -> None: + doc = version_document("enterprise", "3.30.0", "3.30.x", {}, ["A footnote"], TODAY) + assert doc == { + "project": "enterprise", + "version": "3.30.0 LTS (supported until August 2030)", + "artifacts": {}, + "footnotes": ["A footnote"], + } + + +@pytest.mark.parametrize( + "project, version, branch, keys", + [ + ("enterprise", "3.30.0", "3.30.x", []), + ("enterprise", "3.31.0", "3.31.x", ["note"]), + ("enterprise", "master", "master", ["nightly_release_date", "note"]), + ("community", "master", "nightly-master", ["nightly_release_date"]), + ("community", "3.30.x", "nightly-3.30.x", ["nightly_release_date"]), + ], +) +def test_version_document_keys( + project: str, version: str, branch: str, keys: list[str] +) -> None: + doc = version_document(project, version, branch, {}, [], TODAY) + # In the key order of the legacy release.py + assert list(doc) == ["project", "version", *keys, "artifacts", "footnotes"] + if "nightly_release_date" in keys: + assert doc.get("nightly_release_date") == "2027-06-01" + if "note" in keys: + assert doc.get("note") == NON_LTS_NOTE @pytest.mark.parametrize( From 8e9c476a8f9af5391d2372d30295472a1ff871bd Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:47:08 +0100 Subject: [PATCH 09/13] Added writing of release data to cfengine dev release Writes release-data//.json with the checksums of the published files, and adds the version to releases.json. If there is no local releases.json yet, the published one is fetched. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/release/release.py | 12 ++ src/cfengine_cli/release/release_data.py | 128 +++++++++++++++++ tests/unit/test_release_release_data.py | 176 +++++++++++++++++++++++ 3 files changed, 316 insertions(+) create mode 100644 src/cfengine_cli/release/release_data.py create mode 100644 tests/unit/test_release_release_data.py diff --git a/src/cfengine_cli/release/release.py b/src/cfengine_cli/release/release.py index 225d98b5..ffacd3c9 100644 --- a/src/cfengine_cli/release/release.py +++ b/src/cfengine_cli/release/release.py @@ -1,3 +1,4 @@ +import datetime import os from cfengine_cli.release.build import read_build @@ -5,6 +6,7 @@ from cfengine_cli.release.metadata import is_nightly, release_branch from cfengine_cli.release.plan import PlannedFile, plan_assets, plan_packages from cfengine_cli.release.copy_files import copy_files +from cfengine_cli.release.release_data import write_release_data from cfengine_cli.release.utils import ( check_disk_space, exit_on_sigterm, @@ -49,6 +51,16 @@ def release( with output_lock(output_dir, dry_run=dry_run): check_disk_space([(f.source, f.destination) for f in planned], output_dir) copy_files(planned, output_dir, dry_run=dry_run) + write_release_data( + project, + version, + branch, + debug, + planned, + output_dir, + dry_run=dry_run, + today=datetime.date.today(), + ) return 0 diff --git a/src/cfengine_cli/release/release_data.py b/src/cfengine_cli/release/release_data.py new file mode 100644 index 00000000..95f3e309 --- /dev/null +++ b/src/cfengine_cli/release/release_data.py @@ -0,0 +1,128 @@ +import datetime +import json +import urllib.request +from http.client import HTTPResponse +from pathlib import Path +from typing import cast + +from cfengine_cli.release.checksums import file_sha256 +from cfengine_cli.release.metadata import ( + Artifact, + ReleasesData, + VersionDocument, + release_data_url, + update_releases, + version_document, +) +from cfengine_cli.release.plan import PlannedFile +from cfengine_cli.release.utils import atomic_write +from cfengine_cli.utils import UserError + +# Uploaded to release-data on S3 by cfengine dev publish +RELEASE_DATA_DIR = "release-data" + + +def build_artifacts( + planned: list[PlannedFile], dry_run: bool +) -> tuple[dict[str, list[Artifact]], list[str]]: + """Return the artifacts and footnotes of release-data//.json. + + Artifacts are grouped by section, in the order of the plan. + """ + artifacts: dict[str, list[Artifact]] = {} + footnotes: list[str] = [] + for file in planned: + artifact: Artifact = { + "Title": file.title, + "Arch": file.arch, + "classexpr": file.classexpr, + "Published": True, + "URL": file.url, + "SHA256": file_sha256(_downloaded_file(file, dry_run)), + } + if file.footnote is not None: + # Numbered from 1, in order of first use + if file.footnote not in footnotes: + footnotes.append(file.footnote) + artifact["Footnote"] = footnotes.index(file.footnote) + 1 + if file.instructions is not None: + artifact["Instructions"] = file.instructions + if file.package is not None: + artifact["package"] = file.package + artifacts.setdefault(file.section, []).append(artifact) + return artifacts, footnotes + + +def _downloaded_file(file: PlannedFile, dry_run: bool) -> Path: + """Return the file users download, i.e. the signed copy if any. + + A dry run copies nothing, so it falls back to the source, as the legacy + release.py does. Debug releases link to the source. + """ + if dry_run or file.destination is None: + return file.source + return file.destination + + +def _read_releases(path: Path, project: str) -> ReleasesData: + """Read releases.json, or fetch the published one if there is none yet.""" + if path.exists(): + try: + return cast(ReleasesData, json.loads(path.read_text())) + except json.JSONDecodeError as e: + raise UserError(f"Invalid JSON in '{path}': {e}") from e + url = release_data_url(project, "releases") + print(f"No '{path}', fetching '{url}'") + try: + # urlopen() is typed Any, but returns this for http(s) URLs + response = cast(HTTPResponse, urllib.request.urlopen(url, timeout=60)) + with response: + return cast(ReleasesData, json.load(response)) + except OSError as e: + # Unlike the legacy release.py, do not start from an empty list. It + # would replace the published releases.json once uploaded. + raise UserError(f"Could not fetch '{url}': {e}") from e + except json.JSONDecodeError as e: + raise UserError(f"Invalid JSON from '{url}': {e}") from e + + +def _write_json( + path: Path, + data: ReleasesData | VersionDocument, + output_dir: str, + *, + dry_run: bool, +) -> None: + if dry_run: + print(f"Would have written '{path}'") + return + with atomic_write(path, output_dir) as temporary: + # Same format as the legacy release.py + _ = temporary.write_text(json.dumps(data, indent=4)) + print(f"Wrote '{path}'") + + +def write_release_data( + project: str, + version: str, + branch: str, + debug: bool, + planned: list[PlannedFile], + output_dir: str, + *, + dry_run: bool, + today: datetime.date, +) -> None: + """Write release-data//.json and update releases.json.""" + directory = Path(output_dir) / RELEASE_DATA_DIR / project + releases_path = directory / "releases.json" + + artifacts, footnotes = build_artifacts(planned, dry_run) + document = version_document(project, version, branch, artifacts, footnotes, today) + releases = update_releases( + _read_releases(releases_path, project), project, version, branch, debug, today + ) + + # The document first, so releases.json never links to a missing one + _write_json(directory / f"{version}.json", document, output_dir, dry_run=dry_run) + _write_json(releases_path, releases, output_dir, dry_run=dry_run) diff --git a/tests/unit/test_release_release_data.py b/tests/unit/test_release_release_data.py new file mode 100644 index 00000000..1c57b8ca --- /dev/null +++ b/tests/unit/test_release_release_data.py @@ -0,0 +1,176 @@ +import datetime +import hashlib +import json +from pathlib import Path +from typing import cast + +import pytest + +from cfengine_cli.release.metadata import ReleasesData, VersionDocument +from cfengine_cli.release.plan import PlannedFile +from cfengine_cli.release.release_data import build_artifacts, write_release_data +from cfengine_cli.utils import UserError + +TODAY = datetime.date(2027, 6, 1) + + +def _setup(tmp_path: Path) -> tuple[list[PlannedFile], Path]: + source = tmp_path / "cfengine-masterfiles-3.30.0-1.pkg.tar.gz" + _ = source.write_bytes(b"tarball") + planned = [ + PlannedFile( + source=source, + destination=source, + url="url", + section="Additional Assets", + title="Masterfiles ready-to-install tarball", + arch="no arch", + classexpr="!any", + package=None, + ) + ] + directory = tmp_path / "out" / "release-data" / "community" + directory.mkdir(parents=True) + _ = (directory / "releases.json").write_text('{"lts_branches": [], "releases": []}') + return planned, directory + + +def test_write_release_data(tmp_path: Path) -> None: + planned, directory = _setup(tmp_path) + write_release_data( + "community", + "3.30.0", + "3.30.x", + False, + planned, + str(tmp_path / "out"), + dry_run=False, + today=TODAY, + ) + text = (directory / "3.30.0.json").read_text() + document = cast(VersionDocument, json.loads(text)) + assert document["version"] == "3.30.0 LTS" + assert list(document.get("artifacts", {})) == ["Additional Assets"] + text = (directory / "releases.json").read_text() + releases = cast(ReleasesData, json.loads(text)) + assert [r["version"] for r in releases["releases"]] == ["3.30.0"] + + +def test_write_release_data_dry_run(tmp_path: Path) -> None: + planned, directory = _setup(tmp_path) + write_release_data( + "community", + "3.30.0", + "3.30.x", + False, + planned, + str(tmp_path / "out"), + dry_run=True, + today=TODAY, + ) + assert not (directory / "3.30.0.json").exists() + assert (directory / "releases.json").read_text() == ( + '{"lts_branches": [], "releases": []}' + ) + + +def test_write_release_data_invalid_releases(tmp_path: Path) -> None: + planned, directory = _setup(tmp_path) + _ = (directory / "releases.json").write_text('{"releases": [') + with pytest.raises(UserError, match="Invalid JSON in"): + write_release_data( + "community", + "3.30.0", + "3.30.x", + False, + planned, + str(tmp_path / "out"), + dry_run=True, + today=TODAY, + ) + + +def _write(path: Path, content: bytes) -> Path: + _ = path.write_bytes(content) + return path + + +def test_build_artifacts(tmp_path: Path) -> None: + deb = PlannedFile( + source=_write(tmp_path / "unsigned.deb", b"unsigned"), + destination=_write(tmp_path / "signed.deb", b"signed"), + url="https://example.com/signed.deb", + section="Binary packages", + title="Debian 12", + arch="x86_64", + classexpr="debian_12.x86_64", + package="PACKAGES_x86_64_linux_debian_12", + ) + tarball = PlannedFile( + source=_write(tmp_path / "source.tar.gz", b"tarball"), + destination=_write(tmp_path / "copy.tar.gz", b"tarball"), + url="https://example.com/copy.tar.gz", + section="Additional Assets", + title="Linux binary tarball (unsupported)", + arch="x86_64", + classexpr="!any", + package=None, + instructions="https://docs.example.com", + footnote="Not supported", + ) + artifacts, footnotes = build_artifacts([deb, tarball], dry_run=False) + assert artifacts == { + "Binary packages": [ + { + "Title": "Debian 12", + "Arch": "x86_64", + "classexpr": "debian_12.x86_64", + "Published": True, + "URL": "https://example.com/signed.deb", + # Of the signed copy + "SHA256": hashlib.sha256(b"signed").hexdigest(), + "package": "PACKAGES_x86_64_linux_debian_12", + } + ], + "Additional Assets": [ + { + "Title": "Linux binary tarball (unsupported)", + "Arch": "x86_64", + "classexpr": "!any", + "Published": True, + "URL": "https://example.com/copy.tar.gz", + "SHA256": hashlib.sha256(b"tarball").hexdigest(), + "Footnote": 1, + "Instructions": "https://docs.example.com", + } + ], + } + assert footnotes == ["Not supported"] + # Key order as in the legacy release.py + assert list(artifacts["Additional Assets"][0]) == [ + "Title", + "Arch", + "classexpr", + "Published", + "URL", + "SHA256", + "Footnote", + "Instructions", + ] + + +def test_build_artifacts_dry_run(tmp_path: Path) -> None: + # Nothing is copied in a dry run, so the source is checksummed + deb = PlannedFile( + source=_write(tmp_path / "unsigned.deb", b"unsigned"), + destination=tmp_path / "not-copied.deb", + url="url", + section="Binary packages", + title="Debian 12", + arch="x86_64", + classexpr="debian_12.x86_64", + package="PACKAGES_x86_64_linux_debian_12", + ) + artifacts, _ = build_artifacts([deb], dry_run=True) + sha256 = artifacts["Binary packages"][0]["SHA256"] + assert sha256 == hashlib.sha256(b"unsigned").hexdigest() From 61527a171bae7139a11782b9f4cada48eb467ba1 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:48:48 +0100 Subject: [PATCH 10/13] Added cfengine dev update-repo command Adds a community release to the APT and YUM repositories, and regenerates and signs their metadata, with the same settings as the legacy release.py, as both write to the same repositories. It adds the signed copies from the release dir, and refuses unsigned packages. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/dev.py | 8 + src/cfengine_cli/main.py | 8 +- src/cfengine_cli/release/args.py | 29 +++ src/cfengine_cli/release/update_repo.py | 237 ++++++++++++++++++++++++ src/cfengine_cli/release/utils.py | 38 ++++ tests/unit/test_release_args.py | 12 +- tests/unit/test_release_update_repo.py | 63 +++++++ 7 files changed, 393 insertions(+), 2 deletions(-) create mode 100644 src/cfengine_cli/release/update_repo.py create mode 100644 tests/unit/test_release_update_repo.py diff --git a/src/cfengine_cli/dev.py b/src/cfengine_cli/dev.py index 5100937e..fe1aebe8 100644 --- a/src/cfengine_cli/dev.py +++ b/src/cfengine_cli/dev.py @@ -11,6 +11,7 @@ from cfengine_cli import docs from cfengine_cli.syntax_tree import syntax_tree from cfengine_cli.release.release import release +from cfengine_cli.release.update_repo import update_repo def generate_release_information_command( @@ -93,5 +94,12 @@ def dispatch_dev_subcommand(subcommand, args) -> int: output_dir=args.output, dry_run=args.dry_run, ) + if subcommand == "update-repo": + return update_repo( + version=args.version, + build_dir=args.build, + output_dir=args.output, + dry_run=args.dry_run, + ) raise UserError("Invalid cfengine dev subcommand - " + subcommand) diff --git a/src/cfengine_cli/main.py b/src/cfengine_cli/main.py index 69b23d9f..7b041d05 100644 --- a/src/cfengine_cli/main.py +++ b/src/cfengine_cli/main.py @@ -10,7 +10,7 @@ from cf_remote.utils import strip_user, CFRExitError from cfengine_cli.cfengine_wrapper import cfengine_commands from cfengine_cli.cfengine_wrapper.arg_parse import parse_wrapper_args -from cfengine_cli.release.args import add_release_args +from cfengine_cli.release.args import add_release_args, add_update_repo_args from cfengine_cli.version import cfengine_cli_version_string from cfengine_cli import commands from cfengine_cli.utils import UserError @@ -218,6 +218,12 @@ def _get_arg_parser(): ) add_release_args(parser) + parser = dev_subparsers.add_parser( + "update-repo", + help="Add a community release to the APT and YUM repositories", + ) + add_update_repo_args(parser) + inip = subp.add_parser( "init", help="Initialize a [policy-set, policy-module, promise-type] example." ) diff --git a/src/cfengine_cli/release/args.py b/src/cfengine_cli/release/args.py index 0d0dd2c2..c236dbf5 100644 --- a/src/cfengine_cli/release/args.py +++ b/src/cfengine_cli/release/args.py @@ -11,6 +11,13 @@ def release_version(value: str) -> str: return value +def stable_version(value: str) -> str: + """argparse type for a release version, not a nightly.""" + if not re.fullmatch(r"\d+\.\d+\.\d+", value): + raise argparse.ArgumentTypeError(f"'{value}' is not X.Y.Z") + return value + + def add_release_args(sp: argparse.ArgumentParser) -> None: _ = sp.add_argument( "--project", @@ -37,3 +44,25 @@ def add_release_args(sp: argparse.ArgumentParser) -> None: _ = sp.add_argument( "--dry-run", action="store_true", help="Only print what would be done" ) + + +def add_update_repo_args(sp: argparse.ArgumentParser) -> None: + _ = sp.add_argument( + "--version", + required=True, + type=stable_version, + help="Community version to add, e.g. 3.30.0", + ) + _ = sp.add_argument( + "--build", + required=True, + help="Directory with the build, as given to cfengine dev release", + ) + _ = sp.add_argument( + "--output", + required=True, + help="Root directory with release/ and repo/, as given to cfengine dev release", + ) + _ = sp.add_argument( + "--dry-run", action="store_true", help="Only print what would be done" + ) diff --git a/src/cfengine_cli/release/update_repo.py b/src/cfengine_cli/release/update_repo.py new file mode 100644 index 00000000..242e6c83 --- /dev/null +++ b/src/cfengine_cli/release/update_repo.py @@ -0,0 +1,237 @@ +import os +import tempfile +from dataclasses import dataclass +from pathlib import Path + +from cfengine_cli.release.build import read_build +from cfengine_cli.release.checksums import verify_build +from cfengine_cli.release.plan import PlannedFile, plan_packages +from cfengine_cli.release.utils import ( + SIGNING_KEY, + check_disk_space, + check_tools, + copy_or_skip, + exit_on_sigterm, + is_signed, + output_lock, + run, +) +from cfengine_cli.utils import UserError + +# The community repos, shared by all branches. The legacy release.py, still +# used for LTS releases, writes to the same repos with the same settings. +REPO_DIR = "repo" +APT_POOL = "apt/packages/pool/main/C" +# Labels whose packages go into the repos, as in the legacy release.py +APT_LABELS = ("PACKAGES_x86_64_linux_debian_12", "PACKAGES_arm_64_linux_debian_12") +YUM_LABELS = { + "PACKAGES_x86_64_linux_redhat_7": "x86_64", + "PACKAGES_x86_64_linux_redhat_8": "x86_64", + "PACKAGES_arm_64_linux_redhat_8": "aarch64", + "PACKAGES_x86_64_linux_redhat_9": "x86_64", + "PACKAGES_arm_64_linux_redhat_9": "aarch64", + "PACKAGES_x86_64_linux_redhat_10": "x86_64", + "PACKAGES_arm_64_linux_redhat_10": "aarch64", +} +REPO_TOOLS = ("apt-ftparchive", "createrepo_c", "gpg", "rpm") + +# The settings of apt-ftparchive.conf in infra, with paths from the repo dir. +# i386 is kept, as the pool still has old i386 packages. +APT_FTPARCHIVE_CONF = """\ +Dir {{ + ArchiveDir "{apt}/packages"; + CacheDir "{apt}/cache/"; +}}; + + +Default {{ + Packages::Compress ". gzip bzip2"; + Sources::Compress ". gzip bzip2"; + Contents::Compress ". gzip bzip2"; +}}; + + +TreeDefault {{ + BinCacheDB "packages-$(SECTION)-$(ARCH).db"; + Directory "pool/$(SECTION)"; + SrcDirectory "pool/$(SECTION)"; + Packages "$(DIST)/$(SECTION)/binary-$(ARCH)/Packages"; + Sources "$(DIST)/$(SECTION)/source/Sources"; + Contents "$(DIST)/Contents-$(ARCH)"; +}}; + + +Tree "dists/stable" {{ + Sections "main"; + Architectures "i386 amd64 arm64"; +}} +""" + +# The settings of apt-ftparchiveRelease.conf in infra +APT_FTPARCHIVE_RELEASE_CONF = """\ +APT::FTPArchive::Release::Codename "community"; +APT::FTPArchive::Release::Origin "CFEngine"; +APT::FTPArchive::Release::Components "main"; +APT::FTPArchive::Release::Label "Official packages"; +APT::FTPArchive::Release::Architectures "i386 amd64 arm64"; +APT::FTPArchive::Release::Suite "stable"; +""" + + +@dataclass(frozen=True) +class RepoFile: + """A package to add to a repo.""" + + source: Path + destination: Path + + +def plan_repo(planned: list[PlannedFile], output_dir: str) -> list[RepoFile]: + """Plan the packages to add to the community repos.""" + repo = Path(output_dir) / REPO_DIR + files: list[RepoFile] = [] + for file in planned: + # Debug releases publish nothing + if file.destination is None or file.package is None: + continue + # The signed copies in the release dir, so a package has the same + # checksum on the downloads page and in the repos. The legacy + # release.py adds the unsigned debs instead, which apt accepts too. + name = file.destination.name + if file.package in APT_LABELS and name.endswith(".deb"): + files.append(RepoFile(file.destination, repo / APT_POOL / name)) + elif file.package in YUM_LABELS and name.endswith(".rpm"): + yum_dir = repo / "yum" / YUM_LABELS[file.package] + files.append(RepoFile(file.destination, yum_dir / name)) + return files + + +def _update_apt(apt: Path, output_dir: str) -> None: + """Regenerate and sign the APT metadata, as update-apt-repo.sh in infra.""" + stable = apt / "packages/dists/stable" + for directory in ( + apt / "cache", + apt / "packages/pool/main", + stable / "main/binary-amd64", + stable / "main/binary-i386", + stable / "main/binary-arm64", + stable / "main/source", + ): + directory.mkdir(parents=True, exist_ok=True) + + # In the output dir, so the renames below are atomic + with tempfile.TemporaryDirectory(dir=output_dir, prefix=".tmp-") as tmp: + temporary = Path(tmp) + conf = temporary / "apt-ftparchive.conf" + _ = conf.write_text(APT_FTPARCHIVE_CONF.format(apt=apt)) + release_conf = temporary / "apt-ftparchiveRelease.conf" + _ = release_conf.write_text(APT_FTPARCHIVE_RELEASE_CONF) + _ = run(["apt-ftparchive", "generate", str(conf)]) + release = run( + ["apt-ftparchive", "-c", str(release_conf), "release", str(stable)] + ) + release_file = temporary / "Release" + _ = release_file.write_text(release) + + gpg = ["gpg", "--yes", "--armor", "--digest-algo=SHA256"] + gpg += ["--local-user", SIGNING_KEY] + signature = str(temporary / "Release.gpg") + _ = run([*gpg, "--detach-sign", "--output", signature, str(release_file)]) + # The same signature embedded, the modern way + in_release = str(temporary / "InRelease") + _ = run([*gpg, "--clearsign", "--output", in_release, str(release_file)]) + + # Signed first, then all moved in at once, so Release never disagrees + # with its signatures while gpg runs + for name in ("Release", "Release.gpg", "InRelease"): + _ = (temporary / name).rename(stable / name) + + +def _update_yum(directory: Path) -> None: + """Regenerate and sign the YUM metadata of one arch.""" + _ = run(["createrepo_c", "--simple-md-filenames", str(directory)]) + _ = run( + [ + "gpg", + "--yes", + "--armor", + "--local-user", + SIGNING_KEY, + "--detach-sign", + str(directory / "repodata/repomd.xml"), + ] + ) + + +def update_repo(version: str, build_dir: str, output_dir: str, *, dry_run: bool) -> int: + """Add a community release to the repos, after cfengine dev release.""" + if not os.path.isdir(build_dir): + raise UserError(f"Build directory '{build_dir}' does not exist") + exit_on_sigterm() + + print(f"Updating the community repositories with {version}") + print(f" build: {build_dir}") + print(f" output: {output_dir}") + print(f" dry run: {dry_run}") + + build = read_build(build_dir) + verify_build(build) + planned = plan_packages("community", version, build, output_dir, False) + files = plan_repo(planned, output_dir) + _print_repo_plan(files) + with output_lock(output_dir, dry_run=dry_run): + update_repos(files, output_dir, dry_run=dry_run) + return 0 + + +def _print_repo_plan(files: list[RepoFile]) -> None: + print(f"Planned {len(files)} repository files:") + for file in files: + print(f" {file.destination.name}") + print(f" from: {file.source}") + print(f" to: {file.destination}") + + +def update_repos(files: list[RepoFile], output_dir: str, *, dry_run: bool) -> None: + """Add the planned packages to the repos, and regenerate their metadata. + + The metadata is regenerated from all packages in the repo, so a failed + run is repaired by running again. + """ + if not files: + return + missing = [str(file.source) for file in files if not file.source.exists()] + if missing: + raise UserError( + f"Not found, run cfengine dev release first: {', '.join(missing)}" + ) + check_tools("Repository", REPO_TOOLS) + # cfengine dev release always signs, so this only fails if the release + # dir was changed by hand. yum clients with gpgcheck would fail. + unsigned = [str(file.source) for file in files if not is_signed(file.source)] + if unsigned: + raise UserError(f"Not signed, cannot add to the repo: {', '.join(unsigned)}") + check_disk_space([(f.source, f.destination) for f in files], output_dir) + + for file in files: + copy_or_skip( + file.source, file.destination, output_dir, signed=False, dry_run=dry_run + ) + + repo = Path(output_dir) / REPO_DIR + apt = any(file.destination.name.endswith(".deb") for file in files) + yum_dirs = sorted( + {file.destination.parent for file in files if file.destination.suffix == ".rpm"} + ) + if apt: + if dry_run: + print(f"Would have updated the APT repo in '{repo / 'apt'}'") + else: + _update_apt(repo / "apt", output_dir) + print(f"Updated the APT repo in '{repo / 'apt'}'") + for yum_dir in yum_dirs: + if dry_run: + print(f"Would have updated the YUM repo in '{yum_dir}'") + else: + _update_yum(yum_dir) + print(f"Updated the YUM repo in '{yum_dir}'") diff --git a/src/cfengine_cli/release/utils.py b/src/cfengine_cli/release/utils.py index 7d3c73df..afccf2fa 100644 --- a/src/cfengine_cli/release/utils.py +++ b/src/cfengine_cli/release/utils.py @@ -1,4 +1,5 @@ import fcntl +import os import shutil import signal import subprocess @@ -19,6 +20,7 @@ # In the output dir. Also taken by the legacy release.py in infra. LOCK_FILE = ".lock" # Free space to keep on top of the files to copy, as in the legacy release.py. +# Also covers the repo metadata that update-repo regenerates. DISK_SPACE_MARGIN = 1024**3 AR_MAGIC = b"!\n" @@ -65,6 +67,42 @@ def _rpm_build_time(path: Path) -> int: return int(run(["rpm", "-qp", "--nosignature", "--qf", "%{BUILDTIME}", str(path)])) +def is_signed_deb(path: Path) -> bool: + """Return True if the deb has an origin signature, as debsigs adds.""" + with open(path, "rb") as f: + if f.read(len(AR_MAGIC)) != AR_MAGIC: + raise UserError(f"Not a .deb: '{path}'") + # Each ar member has a 60 byte header: a 16 byte name, and the size + # at bytes 48 to 58. Members start at even offsets. + while len(header := f.read(60)) == 60: + name = header[:16].rstrip(b" ").rstrip(b"/") + if name == b"_gpgorigin": + return True + size = int(header[48:58].decode("ascii")) + _ = f.seek(size + size % 2, os.SEEK_CUR) + return False + + +def is_signed(path: Path) -> bool: + """Return True if the .rpm or .deb has a signature.""" + if path.name.endswith(".rpm"): + return is_signed_rpm(path) + return is_signed_deb(path) + + +def is_signed_rpm(path: Path) -> bool: + """Return True if the rpm has a signature, as rpmsign adds.""" + # rpmsign of rpm 4 signs into RSAHEADER, of rpm 6 into OPENPGP. rpm 4 does + # not know OPENPGP, and prints nothing for it. --nosignature as in + # _rpm_build_time(). Only checks that a signature is there, verifying it + # would need the key in an rpm database. + for tag in ("RSAHEADER", "OPENPGP"): + query = ["rpm", "-qp", "--nosignature", "--qf", f"%{{{tag}:pgpsig}}"] + if run([*query, str(path)]).strip() not in ("", "(none)"): + return True + return False + + def build_time(path: Path) -> int: """Return the package's SOURCE_DATE_EPOCH.""" if path.name.endswith(".rpm"): diff --git a/tests/unit/test_release_args.py b/tests/unit/test_release_args.py index 9aa0d2f3..5bff60b3 100644 --- a/tests/unit/test_release_args.py +++ b/tests/unit/test_release_args.py @@ -2,7 +2,7 @@ import pytest -from cfengine_cli.release.args import release_version +from cfengine_cli.release.args import release_version, stable_version @pytest.mark.parametrize("version", ["3.30.0", "3.27.x", "master"]) @@ -14,3 +14,13 @@ def test_release_version(version: str) -> None: def test_release_version_invalid(version: str) -> None: with pytest.raises(argparse.ArgumentTypeError): _ = release_version(version) + + +def test_stable_version() -> None: + assert stable_version("3.30.0") == "3.30.0" + + +@pytest.mark.parametrize("version", ["3.27.x", "master"]) +def test_stable_version_invalid(version: str) -> None: + with pytest.raises(argparse.ArgumentTypeError): + _ = stable_version(version) diff --git a/tests/unit/test_release_update_repo.py b/tests/unit/test_release_update_repo.py new file mode 100644 index 00000000..c9f36e28 --- /dev/null +++ b/tests/unit/test_release_update_repo.py @@ -0,0 +1,63 @@ +from pathlib import Path + +import pytest + +from cfengine_cli.release.plan import PlannedFile +from cfengine_cli.release.update_repo import RepoFile, plan_repo, update_repos +from cfengine_cli.utils import UserError + +BUILD = Path("/build") +RELEASE = Path("/output/release") +REPO = Path("/output/repo") + + +def _planned(label: str | None, name: str, debug: bool = False) -> PlannedFile: + return PlannedFile( + source=BUILD / str(label) / name, + destination=None if debug else RELEASE / name, + url="url", + section="Section", + title="Title", + arch="x86_64", + classexpr="any", + package=label, + ) + + +def test_plan_repo() -> None: + deb = "cfengine-community_3.30.0-1_amd64.deb" + rpm = "cfengine-community-3.30.0-1.el9.aarch64.rpm" + planned = [ + _planned("PACKAGES_x86_64_linux_debian_12", deb), + _planned("PACKAGES_arm_64_linux_redhat_9", rpm), + # Not in the repos + _planned("PACKAGES_x86_64_linux_ubuntu_24", "cfengine-community_ubuntu.deb"), + _planned(None, "cfengine-masterfiles-3.30.0.tar.gz"), + ] + # The signed copies in the release dir + assert plan_repo(planned, "/output") == [ + RepoFile(RELEASE / deb, REPO / "apt/packages/pool/main/C" / deb), + RepoFile(RELEASE / rpm, REPO / "yum/aarch64" / rpm), + ] + + +def test_plan_repo_debug() -> None: + planned = [_planned("PACKAGES_x86_64_linux_debian_12", "a.deb", debug=True)] + assert plan_repo(planned, "/output") == [] + + +def test_update_repos_missing_tools( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setenv("PATH", str(tmp_path)) + _ = (tmp_path / "a.deb").write_text("deb") + files = [RepoFile(tmp_path / "a.deb", tmp_path / "repo" / "a.deb")] + with pytest.raises(UserError, match="Repository tools not found"): + update_repos(files, str(tmp_path), dry_run=True) + + +def test_update_repos_not_released(tmp_path: Path) -> None: + rpm = RELEASE / "cfengine-community-3.30.0-1.el9.x86_64.rpm" + files = [RepoFile(rpm, tmp_path / "repo" / rpm.name)] + with pytest.raises(UserError, match="run cfengine dev release first"): + update_repos(files, str(tmp_path), dry_run=True) From cf29e7100509bb1a4573edc893ac29334cc6dcf8 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:49:24 +0100 Subject: [PATCH 11/13] Added cfengine dev publish command Uploads the release to S3. --bucket test uploads the repositories to the test bucket, to try installing from them. --bucket prod uploads the release files, the repositories, and the release data last, so it never links to files that are not uploaded yet. Nightlies only upload their release data. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/dev.py | 8 ++++ src/cfengine_cli/main.py | 12 +++++- src/cfengine_cli/release/args.py | 22 ++++++++++ src/cfengine_cli/release/publish.py | 64 +++++++++++++++++++++++++++++ tests/unit/test_release_publish.py | 43 +++++++++++++++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 src/cfengine_cli/release/publish.py create mode 100644 tests/unit/test_release_publish.py diff --git a/src/cfengine_cli/dev.py b/src/cfengine_cli/dev.py index fe1aebe8..8181aa11 100644 --- a/src/cfengine_cli/dev.py +++ b/src/cfengine_cli/dev.py @@ -11,6 +11,7 @@ from cfengine_cli import docs from cfengine_cli.syntax_tree import syntax_tree from cfengine_cli.release.release import release +from cfengine_cli.release.publish import publish from cfengine_cli.release.update_repo import update_repo @@ -94,6 +95,13 @@ def dispatch_dev_subcommand(subcommand, args) -> int: output_dir=args.output, dry_run=args.dry_run, ) + if subcommand == "publish": + return publish( + output_dir=args.output, + bucket=args.bucket, + release_data_only=args.release_data_only, + dry_run=args.dry_run, + ) if subcommand == "update-repo": return update_repo( version=args.version, diff --git a/src/cfengine_cli/main.py b/src/cfengine_cli/main.py index 7b041d05..95af556d 100644 --- a/src/cfengine_cli/main.py +++ b/src/cfengine_cli/main.py @@ -10,7 +10,11 @@ from cf_remote.utils import strip_user, CFRExitError from cfengine_cli.cfengine_wrapper import cfengine_commands from cfengine_cli.cfengine_wrapper.arg_parse import parse_wrapper_args -from cfengine_cli.release.args import add_release_args, add_update_repo_args +from cfengine_cli.release.args import ( + add_publish_args, + add_release_args, + add_update_repo_args, +) from cfengine_cli.version import cfengine_cli_version_string from cfengine_cli import commands from cfengine_cli.utils import UserError @@ -224,6 +228,12 @@ def _get_arg_parser(): ) add_update_repo_args(parser) + parser = dev_subparsers.add_parser( + "publish", + help="Upload the release files, repositories and release data to S3", + ) + add_publish_args(parser) + inip = subp.add_parser( "init", help="Initialize a [policy-set, policy-module, promise-type] example." ) diff --git a/src/cfengine_cli/release/args.py b/src/cfengine_cli/release/args.py index c236dbf5..04bae58a 100644 --- a/src/cfengine_cli/release/args.py +++ b/src/cfengine_cli/release/args.py @@ -46,6 +46,28 @@ def add_release_args(sp: argparse.ArgumentParser) -> None: ) +def add_publish_args(sp: argparse.ArgumentParser) -> None: + _ = sp.add_argument( + "--output", + required=True, + help="Root directory with release/, repo/ and release-data/", + ) + _ = sp.add_argument( + "--bucket", + required=True, + choices=["test", "prod"], + help="test: only the repos, to try them. prod: everything, release data last", + ) + _ = sp.add_argument( + "--release-data-only", + action="store_true", + help="Only upload the release data, e.g. for nightlies. Needs --bucket prod", + ) + _ = sp.add_argument( + "--dry-run", action="store_true", help="Only list what would be uploaded" + ) + + def add_update_repo_args(sp: argparse.ArgumentParser) -> None: _ = sp.add_argument( "--version", diff --git a/src/cfengine_cli/release/publish.py b/src/cfengine_cli/release/publish.py new file mode 100644 index 00000000..2419b9b7 --- /dev/null +++ b/src/cfengine_cli/release/publish.py @@ -0,0 +1,64 @@ +import subprocess +from pathlib import Path + +from cfengine_cli.release.release_data import RELEASE_DATA_DIR +from cfengine_cli.release.utils import check_tools +from cfengine_cli.utils import UserError + +# As in sync-packages-to-s3.sh in infra +BUCKETS = {"test": "cfengine-repotest", "prod": "cfengine-package-repos"} +RELEASE_DIRS = ("enterprise", "community_binaries", "tarballs") +# Backups made by the legacy release.py +REPO_EXCLUDES = ["--exclude", "*.old"] + + +def plan_syncs( + output_dir: str, bucket: str, release_data_only: bool +) -> list[tuple[Path, str, list[str]]]: + """Return the syncs to run, in order: local dir, S3 URL, extra options.""" + output = Path(output_dir) + s3 = f"s3://{BUCKETS[bucket]}" + if bucket == "test": + # Only the repos have a test bucket, to try installing from them + return [(output / "repo", f"{s3}/pub", REPO_EXCLUDES)] + + syncs: list[tuple[Path, str, list[str]]] = [] + if not release_data_only: + for name in RELEASE_DIRS: + syncs.append((output / "release" / name, f"{s3}/{name}", [])) + syncs.append((output / "repo", f"{s3}/pub", REPO_EXCLUDES)) + # Last, so the metadata never links to files that are not uploaded yet + syncs.append((output / RELEASE_DATA_DIR, f"{s3}/{RELEASE_DATA_DIR}", [])) + return syncs + + +def publish( + output_dir: str, bucket: str, *, release_data_only: bool, dry_run: bool +) -> int: + """Upload the release files, repos and release data to S3.""" + if release_data_only and bucket != "prod": + raise UserError("--release-data-only needs --bucket prod") + + syncs: list[tuple[Path, str, list[str]]] = [] + for directory, url, options in plan_syncs(output_dir, bucket, release_data_only): + if directory.is_dir(): + syncs.append((directory, url, options)) + else: + print(f"Skipped '{directory}', not found") + if not syncs: + raise UserError(f"Nothing to publish in '{output_dir}'") + check_tools("Upload", ("aws",)) + + for directory, url, options in syncs: + command = ["aws", "s3", "sync", str(directory), url, "--acl", "public-read"] + command += options + if dry_run: + # Lists what would be uploaded, the files exist by now + command.append("--dryrun") + # Not captured, so the progress of large uploads shows as it runs + try: + _ = subprocess.run(command, check=True) + except subprocess.CalledProcessError as e: + raise UserError(f"Command failed: {' '.join(command)}") from e + print(f"{'Checked' if dry_run else 'Uploaded'} '{directory}' to '{url}'") + return 0 diff --git a/tests/unit/test_release_publish.py b/tests/unit/test_release_publish.py new file mode 100644 index 00000000..41de6dea --- /dev/null +++ b/tests/unit/test_release_publish.py @@ -0,0 +1,43 @@ +from pathlib import Path + +import pytest + +from cfengine_cli.release.publish import plan_syncs, publish +from cfengine_cli.utils import UserError + + +def test_plan_syncs_prod() -> None: + urls = [url for _, url, _ in plan_syncs("/output", "prod", False)] + assert urls == [ + "s3://cfengine-package-repos/enterprise", + "s3://cfengine-package-repos/community_binaries", + "s3://cfengine-package-repos/tarballs", + "s3://cfengine-package-repos/pub", + # Last, so it never links to files that are not uploaded yet + "s3://cfengine-package-repos/release-data", + ] + + +def test_plan_syncs_test() -> None: + assert plan_syncs("/output", "test", False) == [ + (Path("/output/repo"), "s3://cfengine-repotest/pub", ["--exclude", "*.old"]) + ] + + +def test_publish_release_data_only_needs_prod(tmp_path: Path) -> None: + with pytest.raises(UserError, match="--release-data-only needs --bucket prod"): + _ = publish(str(tmp_path), "test", release_data_only=True, dry_run=True) + + +def test_publish_nothing(tmp_path: Path) -> None: + with pytest.raises(UserError, match="Nothing to publish"): + _ = publish(str(tmp_path), "prod", release_data_only=False, dry_run=True) + + +def test_publish_missing_upload_tools( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setenv("PATH", str(tmp_path)) + (tmp_path / "release-data").mkdir() + with pytest.raises(UserError, match="Upload tools not found: aws"): + _ = publish(str(tmp_path), "prod", release_data_only=True, dry_run=True) From 1f2794465dd90efe536a5a719a94e1516714d663 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:49:57 +0100 Subject: [PATCH 12/13] Added an end-to-end test of the cfengine dev release commands Recreates published community and enterprise releases from small fake packages, with the real packaging and signing tools, and compares the release data with the published one. Also checks the signatures, that signing is reproducible, and a master nightly. Runs as its own CI job, as it needs tools that dev machines usually lack. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- .github/workflows/make-check.yml | 20 + .prettierignore | 2 + tests/release/README.md | 21 + tests/release/compare.py | 43 ++ tests/release/data/community-3.27.3.json | 192 +++++ tests/release/data/community-3.29.0.json | 211 +++++ tests/release/data/community-releases.json | 812 ++++++++++++++++++++ tests/release/data/enterprise-3.29.0.json | 341 ++++++++ tests/release/data/enterprise-releases.json | 664 ++++++++++++++++ tests/release/e2e.sh | 194 +++++ tests/release/make_build.py | 62 ++ 11 files changed, 2562 insertions(+) create mode 100644 .prettierignore create mode 100644 tests/release/README.md create mode 100644 tests/release/compare.py create mode 100644 tests/release/data/community-3.27.3.json create mode 100644 tests/release/data/community-3.29.0.json create mode 100644 tests/release/data/community-releases.json create mode 100644 tests/release/data/enterprise-3.29.0.json create mode 100644 tests/release/data/enterprise-releases.json create mode 100644 tests/release/e2e.sh create mode 100644 tests/release/make_build.py diff --git a/.github/workflows/make-check.yml b/.github/workflows/make-check.yml index 34c0db02..51885f06 100644 --- a/.github/workflows/make-check.yml +++ b/.github/workflows/make-check.yml @@ -49,3 +49,23 @@ jobs: run: | git diff --exit-code git ls-files --other --directory --exclude-standard | sed q1 + # Not part of make check, as it needs packaging and signing tools that dev + # machines usually lack + release-e2e: + runs-on: ubuntu-26.04 + steps: + - uses: actions/checkout@v7 + - name: Set up Python + uses: actions/setup-python@v7 + with: + python-version: "3.14" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install uv + sudo apt-get update + sudo apt-get install --yes rpm debsigs apt-utils createrepo-c + - name: Run the release end-to-end test + run: | + uv sync + uv run bash tests/release/e2e.sh diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..f0518f4b --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +# Release data, kept in the published format +tests/release/data/ diff --git a/tests/release/README.md b/tests/release/README.md new file mode 100644 index 00000000..2a2e709f --- /dev/null +++ b/tests/release/README.md @@ -0,0 +1,21 @@ +# Release end-to-end test + +`e2e.sh` tests `cfengine dev release` and `cfengine dev update-repo` with the +real packaging and signing tools. It recreates published community and +enterprise releases from small fake packages, and compares the release data +with the published one. It also checks a master nightly. CI runs it +as its own job, see `.github/workflows/make-check.yml`. + +```bash +uv run bash tests/release/e2e.sh +``` + +It needs gpg, rpm, rpmbuild, rpmsign, debsigs, apt-ftparchive and +createrepo_c. It uses its own gpg key, never a real keyring. + +## Data + +The files in `data/` are release data from +`https://cfengine-package-repos.s3.amazonaws.com/release-data/`, named +`-.json` and `-releases.json`. They are excluded +from prettier, to keep the published format. diff --git a/tests/release/compare.py b/tests/release/compare.py new file mode 100644 index 00000000..3ded60d1 --- /dev/null +++ b/tests/release/compare.py @@ -0,0 +1,43 @@ +"""Compare a release-data file with the published one. + +Usage: compare.py EXPECTED ACTUAL VERSION + +Ignores what a re-release with fake packages cannot reproduce: the SHA256 of +the artifacts, and the release date of VERSION in releases.json. Compares the +rest as formatted text, so the order of keys and lists counts too. +""" + +import difflib +import json +import sys +from pathlib import Path +from typing import Any + + +def _normalized(path: str, version: str) -> list[str]: + data: dict[str, Any] = json.loads(Path(path).read_text()) + for artifacts in data.get("artifacts", {}).values(): + for artifact in artifacts: + del artifact["SHA256"] + for release in data.get("releases", []): + if release["version"] == version: + del release["release_date"] + return json.dumps(data, indent=4).splitlines(keepends=True) + + +def main(expected: str, actual: str, version: str) -> None: + diff = list( + difflib.unified_diff( + _normalized(expected, version), + _normalized(actual, version), + expected, + actual, + ) + ) + if diff: + sys.stdout.writelines(diff) + sys.exit(f"{actual} differs from {expected}") + + +if __name__ == "__main__": + main(*sys.argv[1:]) diff --git a/tests/release/data/community-3.27.3.json b/tests/release/data/community-3.27.3.json new file mode 100644 index 00000000..7899f463 --- /dev/null +++ b/tests/release/data/community-3.27.3.json @@ -0,0 +1,192 @@ +{ + "project": "community", + "version": "3.27.3 LTS", + "artifacts": { + "Binary packages": [ + { + "Title": "Debian 12", + "Arch": "x86_64", + "classexpr": "debian_12.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_debian12_x86_64/cfengine-community_3.27.3-1.debian12_amd64.deb", + "SHA256": "2d30ecb8a638cb6f09652561b4e10171acbe3e712379c829e649418296866748", + "package": "PACKAGES_x86_64_linux_debian_12" + }, + { + "Title": "Debian 12", + "Arch": "aarch64", + "classexpr": "debian_12.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_debian12_arm_64/cfengine-community_3.27.3-1.debian12_arm64.deb", + "SHA256": "54100e62cfee0480edce27e1af34f0ee4056630c03346649898138cbb8a82fca", + "package": "PACKAGES_arm_64_linux_debian_12" + }, + { + "Title": "Debian 13", + "Arch": "x86_64", + "classexpr": "debian_13.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_debian13_x86_64/cfengine-community_3.27.3-1.debian13_amd64.deb", + "SHA256": "244a5749a68764296ae148f9520b64ef62fb79ad04ed9fe17d17b2ec2f9e2ec6", + "package": "PACKAGES_x86_64_linux_debian_13" + }, + { + "Title": "Debian 13", + "Arch": "aarch64", + "classexpr": "debian_13.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_debian13_arm_64/cfengine-community_3.27.3-1.debian13_arm64.deb", + "SHA256": "958ac4b87e4c06becb5bf9a63d6b8cc07f5275827a3ebb17f7f26e41a5cd59f7", + "package": "PACKAGES_arm_64_linux_debian_13" + }, + { + "Title": "Ubuntu 20", + "Arch": "x86_64", + "classexpr": "ubuntu_20.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_ubuntu20_x86_64/cfengine-community_3.27.3-1.ubuntu20_amd64.deb", + "SHA256": "854e7e7c26311f6acff2979c5ad9ecd5f11f1d2bfda08c6ad50f87f79f3b172b", + "package": "PACKAGES_x86_64_linux_ubuntu_20" + }, + { + "Title": "Ubuntu 22", + "Arch": "x86_64", + "classexpr": "ubuntu_22.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_ubuntu22_x86_64/cfengine-community_3.27.3-1.ubuntu22_amd64.deb", + "SHA256": "a2fa9b174711dd0dcbb87988673dc2638de8e02d5f6124e354a0a15fd65c515f", + "package": "PACKAGES_x86_64_linux_ubuntu_22" + }, + { + "Title": "Ubuntu 22", + "Arch": "aarch64", + "classexpr": "ubuntu_22.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_ubuntu22_arm_64/cfengine-community_3.27.3-1.ubuntu22_arm64.deb", + "SHA256": "8081800e59cb8978a388b799e47acabc33056e1c6b3be1198ea335db83f4862c", + "package": "PACKAGES_arm_64_linux_ubuntu_22" + }, + { + "Title": "Ubuntu 24", + "Arch": "x86_64", + "classexpr": "ubuntu_24.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_ubuntu24_x86_64/cfengine-community_3.27.3-1.ubuntu24_amd64.deb", + "SHA256": "2b60920dc83d7924ab61c4af4abf988e7e7f9bde4a185c6c3f3ee35769667215", + "package": "PACKAGES_x86_64_linux_ubuntu_24" + }, + { + "Title": "Ubuntu 24", + "Arch": "aarch64", + "classexpr": "ubuntu_24.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_ubuntu24_arm_64/cfengine-community_3.27.3-1.ubuntu24_arm64.deb", + "SHA256": "59d9a60ff154a4cd66e72b27276b7892ad6f0e8197862246a2e723333af32c1c", + "package": "PACKAGES_arm_64_linux_ubuntu_24" + }, + { + "Title": "Ubuntu 26", + "Arch": "x86_64", + "classexpr": "ubuntu_26.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_ubuntu26_x86_64/cfengine-community_3.27.3-1.ubuntu26_amd64.deb", + "SHA256": "f3b2c7b4c05f2ae97164c68981348ee5cb484bf57f2bfab587837512c7117a1a", + "package": "PACKAGES_x86_64_linux_ubuntu_26" + }, + { + "Title": "Ubuntu 26", + "Arch": "aarch64", + "classexpr": "ubuntu_26.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_ubuntu26_arm_64/cfengine-community_3.27.3-1.ubuntu26_arm64.deb", + "SHA256": "0b3f6394aec32c601a346991f544c863f7601f2b6d3d959c9db89d63f2f946a4", + "package": "PACKAGES_arm_64_linux_ubuntu_26" + }, + { + "Title": "Red Hat / CentOS 7", + "Arch": "x86_64", + "classexpr": "(redhat_7|centos_7).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_rhel7_x86_64/cfengine-community-3.27.3-1.el7.x86_64.rpm", + "SHA256": "89c38aa7a692fe28744a0e8551477bcd3ea0fdf3a88bb0c355575e3da0d87da7", + "package": "PACKAGES_x86_64_linux_redhat_7" + }, + { + "Title": "Red Hat / CentOS 8", + "Arch": "x86_64", + "classexpr": "(redhat_8|centos_8).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_rhel8_x86_64/cfengine-community-3.27.3-1.el8.x86_64.rpm", + "SHA256": "460d87bf0dc10d6a43e6c668eb2351f984028462d480ed0df4f3a6b570e2af0b", + "package": "PACKAGES_x86_64_linux_redhat_8" + }, + { + "Title": "Red Hat / CentOS 9", + "Arch": "x86_64", + "classexpr": "(redhat_9|centos_9).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_rhel9_x86_64/cfengine-community-3.27.3-1.el9.x86_64.rpm", + "SHA256": "dc1498c373a7d41fdab61acdf3c2c9d1cea69e5c194b100408c02288dabdc756", + "package": "PACKAGES_x86_64_linux_redhat_9" + }, + { + "Title": "Red Hat / CentOS 10", + "Arch": "x86_64", + "classexpr": "(redhat_10|centos_10).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_rhel10_x86_64/cfengine-community-3.27.3-1.el10.x86_64.rpm", + "SHA256": "d49c0dbff05f46621b7b76f7c5b729cb11e033113726f41667597d02f75ab6a6", + "package": "PACKAGES_x86_64_linux_redhat_10" + }, + { + "Title": "Red Hat / CentOS 10", + "Arch": "aarch64", + "classexpr": "(redhat_10|centos_10).aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/agent_rhel10_arm_64/cfengine-community-3.27.3-1.el10.aarch64.rpm", + "SHA256": "f8570d169485cb6bf4bdcc1dbdee7e85811951bacc8869efe823d155bfb3507e", + "package": "PACKAGES_arm_64_linux_redhat_10" + } + ], + "Additional Assets": [ + { + "Title": "Masterfiles ready-to-install tarball", + "Arch": "no arch", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/misc/cfengine-masterfiles-3.27.3-1.pkg.tar.gz", + "SHA256": "ba3b060d8805c7be913dac7ec15b11817eb4ec585b8061a9f894fc8ef69be0be", + "package": "PACKAGES_VIRTUAL_PACKAGES_masterfiles" + }, + { + "Title": "Linux binary tarball (unsupported)", + "Arch": "x86_64", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.27.3/misc/cfengine-community-3.27.3-1.x86_64.pkg.tar.gz", + "SHA256": "575fd587e06baf346a149e8afd32543b4a400fec6af74dfd186392e24e1ac301", + "Footnote": 1, + "Instructions": "https://docs.cfengine.com/docs/3.27/getting-started-installation-general-installation-installation-enterprise-generic-tarball.html" + }, + { + "Title": "Source code tarball", + "Arch": "no arch", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/tarballs/cfengine-community-3.27.3.tar.gz", + "SHA256": "7a9d37549d8707e1ce5d3b4ae669260a848498ad456290a6618feb77d84dc9d7" + }, + { + "Title": "Masterfiles source tarball", + "Arch": "no arch", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/tarballs/cfengine-masterfiles-3.27.3.tar.gz", + "SHA256": "24606d596b2a80c1d03bd8006be8ec18dd2a6939813b336aeafe34f33e687a0d" + } + ] + }, + "footnotes": [ + "Tarball containing compiled CFEngine host (client) binaries that runs on most Linux systems but are not optimized for specific library or platform features. Appropriate for testing purposes. Not supported under the CFEngine support contract." + ] +} \ No newline at end of file diff --git a/tests/release/data/community-3.29.0.json b/tests/release/data/community-3.29.0.json new file mode 100644 index 00000000..bbba13ad --- /dev/null +++ b/tests/release/data/community-3.29.0.json @@ -0,0 +1,211 @@ +{ + "project": "community", + "version": "3.29.0 non-LTS", + "note": "Please note that non-LTS releases are unsupported, i.e. excluded from CFEngine Enterprise support contract, and we do not recommend installing them in production.", + "artifacts": { + "Binary packages": [ + { + "Title": "Debian 12", + "Arch": "x86_64", + "classexpr": "debian_12.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_debian12_x86_64/cfengine-community_3.29.0-1.debian12_amd64.deb", + "SHA256": "8c149b4f6a76dec575b23c6fef76247a778bc55a4f13d8a5608440ddd02a4655", + "package": "PACKAGES_x86_64_linux_debian_12" + }, + { + "Title": "Debian 12", + "Arch": "aarch64", + "classexpr": "debian_12.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_debian12_arm_64/cfengine-community_3.29.0-1.debian12_arm64.deb", + "SHA256": "f338bdf3ec560633a7ff92e4cab1756329804ee6fc3337ca766915759b8bd96a", + "package": "PACKAGES_arm_64_linux_debian_12" + }, + { + "Title": "Debian 13", + "Arch": "x86_64", + "classexpr": "debian_13.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_debian13_x86_64/cfengine-community_3.29.0-1.debian13_amd64.deb", + "SHA256": "754f975ad4710e38ce81ba1de7a7e9924bb84572fd6882a678cc7f21f8a14a0b", + "package": "PACKAGES_x86_64_linux_debian_13" + }, + { + "Title": "Debian 13", + "Arch": "aarch64", + "classexpr": "debian_13.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_debian13_arm_64/cfengine-community_3.29.0-1.debian13_arm64.deb", + "SHA256": "3194c99a9c9a48eaaa59ea3388d5643ffeef2bf21ffa5e1428ec07ed9e1b6773", + "package": "PACKAGES_arm_64_linux_debian_13" + }, + { + "Title": "Ubuntu 20", + "Arch": "x86_64", + "classexpr": "ubuntu_20.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_ubuntu20_x86_64/cfengine-community_3.29.0-1.ubuntu20_amd64.deb", + "SHA256": "d9730c1673acea999aa270442bdd125117f484e11e337c6317525e05082e0078", + "package": "PACKAGES_x86_64_linux_ubuntu_20" + }, + { + "Title": "Ubuntu 22", + "Arch": "x86_64", + "classexpr": "ubuntu_22.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_ubuntu22_x86_64/cfengine-community_3.29.0-1.ubuntu22_amd64.deb", + "SHA256": "f63fb559524dc631336034063e57fe8d23a14d78793d72f9c3489ca763cd2447", + "package": "PACKAGES_x86_64_linux_ubuntu_22" + }, + { + "Title": "Ubuntu 22", + "Arch": "aarch64", + "classexpr": "ubuntu_22.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_ubuntu22_arm_64/cfengine-community_3.29.0-1.ubuntu22_arm64.deb", + "SHA256": "2018ff098cce1e119811c88875fd18a68fb5cb3cb9f56b2a92a7ae7f1443f6aa", + "package": "PACKAGES_arm_64_linux_ubuntu_22" + }, + { + "Title": "Ubuntu 24", + "Arch": "x86_64", + "classexpr": "ubuntu_24.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_ubuntu24_x86_64/cfengine-community_3.29.0-1.ubuntu24_amd64.deb", + "SHA256": "a843a28199ee1e8d92e37237d7222e1ab2927a098b54dfb0a3077b42ecf88486", + "package": "PACKAGES_x86_64_linux_ubuntu_24" + }, + { + "Title": "Ubuntu 24", + "Arch": "aarch64", + "classexpr": "ubuntu_24.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_ubuntu24_arm_64/cfengine-community_3.29.0-1.ubuntu24_arm64.deb", + "SHA256": "ec8bef709b7f52cd8ef2de1a036863b0ec6ce0ea7f1925eea5bb6a78b4a362b4", + "package": "PACKAGES_arm_64_linux_ubuntu_24" + }, + { + "Title": "Ubuntu 26", + "Arch": "x86_64", + "classexpr": "ubuntu_26.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_ubuntu26_x86_64/cfengine-community_3.29.0-1.ubuntu26_amd64.deb", + "SHA256": "4906bb9d0b5bc605befd7b59897635cb23aa6463e878fb5a708576ae6a937191", + "package": "PACKAGES_x86_64_linux_ubuntu_26" + }, + { + "Title": "Ubuntu 26", + "Arch": "aarch64", + "classexpr": "ubuntu_26.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_ubuntu26_arm_64/cfengine-community_3.29.0-1.ubuntu26_arm64.deb", + "SHA256": "2ca645d61a7cc29740c05d7d03e88e067695573b5d1d0c1b028f5d4d71159dd0", + "package": "PACKAGES_arm_64_linux_ubuntu_26" + }, + { + "Title": "Red Hat / CentOS 7", + "Arch": "x86_64", + "classexpr": "(redhat_7|centos_7).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_rhel7_x86_64/cfengine-community-3.29.0-1.el7.x86_64.rpm", + "SHA256": "afe9a36dcc63c874de6d933f1493ff171dc4a4b08486430f57bce14264ccd4c2", + "package": "PACKAGES_x86_64_linux_redhat_7" + }, + { + "Title": "Red Hat / CentOS 8", + "Arch": "x86_64", + "classexpr": "(redhat_8|centos_8).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_rhel8_x86_64/cfengine-community-3.29.0-1.el8.x86_64.rpm", + "SHA256": "0be4a5553891d4a1854f8d65837637707282929442fdb57c2335a3efbdb081c0", + "package": "PACKAGES_x86_64_linux_redhat_8" + }, + { + "Title": "Red Hat / CentOS 8", + "Arch": "aarch64", + "classexpr": "(redhat_8|centos_8).aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_rhel8_arm_64/cfengine-community-3.29.0-1.el8.aarch64.rpm", + "SHA256": "debd71574ea30fefde54e5cb3a63f899ad4c11decc0ce27ff1d5f420fa365396", + "package": "PACKAGES_arm_64_linux_redhat_8" + }, + { + "Title": "Red Hat / CentOS 9", + "Arch": "x86_64", + "classexpr": "(redhat_9|centos_9).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_rhel9_x86_64/cfengine-community-3.29.0-1.el9.x86_64.rpm", + "SHA256": "a6557d3fd04c16cc9883c6eef2e9541b3011363539799c6c4db2fff1373859e7", + "package": "PACKAGES_x86_64_linux_redhat_9" + }, + { + "Title": "Red Hat / CentOS 9", + "Arch": "aarch64", + "classexpr": "(redhat_9|centos_9).aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_rhel9_arm_64/cfengine-community-3.29.0-1.el9.aarch64.rpm", + "SHA256": "67718e6b9e39a08bb27eb9971f77258a38c5bc734512344b7ed6e6f8b5ddd70a", + "package": "PACKAGES_arm_64_linux_redhat_9" + }, + { + "Title": "Red Hat / CentOS 10", + "Arch": "x86_64", + "classexpr": "(redhat_10|centos_10).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_rhel10_x86_64/cfengine-community-3.29.0-1.el10.x86_64.rpm", + "SHA256": "1a64fefbb044c64699d9d16237594f6fe654de764007e90706742fe25fb1318b", + "package": "PACKAGES_x86_64_linux_redhat_10" + }, + { + "Title": "Red Hat / CentOS 10", + "Arch": "aarch64", + "classexpr": "(redhat_10|centos_10).aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/agent_rhel10_arm_64/cfengine-community-3.29.0-1.el10.aarch64.rpm", + "SHA256": "f12f7e6397b5299256ddaf0dce6528cee40777b02d31315750d81f65008b469b", + "package": "PACKAGES_arm_64_linux_redhat_10" + } + ], + "Additional Assets": [ + { + "Title": "Masterfiles ready-to-install tarball", + "Arch": "no arch", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/misc/cfengine-masterfiles-3.29.0-1.pkg.tar.gz", + "SHA256": "2deba4a67f393c3fd48ca3bc35a50617f059ca8d8fae303b56cf1a4762fc5c2e", + "package": "PACKAGES_VIRTUAL_PACKAGES_masterfiles" + }, + { + "Title": "Linux binary tarball (unsupported)", + "Arch": "x86_64", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.29.0/misc/cfengine-community-3.29.0-1.x86_64.pkg.tar.gz", + "SHA256": "ae049043b0e470adcb2700c74b9037e8d56496ed295e1412f3da13bdc5affdf1", + "Footnote": 1, + "Instructions": "https://docs.cfengine.com/docs/3.29/getting-started-installation-general-installation-installation-enterprise-generic-tarball.html" + }, + { + "Title": "Source code tarball", + "Arch": "no arch", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/tarballs/cfengine-community-3.29.0.tar.gz", + "SHA256": "83ce77165543884de90a1ee69ae8728fd4a7c6a41e6b470dc5df48b48107d6c7" + }, + { + "Title": "Masterfiles source tarball", + "Arch": "no arch", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/tarballs/cfengine-masterfiles-3.29.0.tar.gz", + "SHA256": "db0a97ae7ee1f46430b5ad79127a7594849a222adc1934eeb3e5aa14843ff47e" + } + ] + }, + "footnotes": [ + "Tarball containing compiled CFEngine host (client) binaries that runs on most Linux systems but are not optimized for specific library or platform features. Appropriate for testing purposes. Not supported under the CFEngine support contract." + ] +} \ No newline at end of file diff --git a/tests/release/data/community-releases.json b/tests/release/data/community-releases.json new file mode 100644 index 00000000..e5fb5bc4 --- /dev/null +++ b/tests/release/data/community-releases.json @@ -0,0 +1,812 @@ +{ + "lts_branches": [ + { + "supported_until": "2028-12", + "branch_name": "nightly-3.27.x" + }, + { + "supported_until": "2028-12", + "branch_name": "3.27.x" + }, + { + "supported_until": "2027-08", + "branch_name": "nightly-3.24.x" + }, + { + "supported_until": "2027-08", + "branch_name": "3.24.x" + }, + { + "supported_until": "2025-12", + "branch_name": "nightly-3.21.x" + }, + { + "supported_until": "2025-12", + "branch_name": "3.21.x" + }, + { + "supported_until": "2024-08", + "branch_name": "nightly-3.18.x" + }, + { + "supported_until": "2024-08", + "branch_name": "3.18.x" + }, + { + "supported_until": "3000-01", + "branch_name": "nightly-master" + }, + { + "supported_until": "2022-12", + "branch_name": "nightly-3.15.x" + }, + { + "supported_until": "2022-12", + "branch_name": "3.15.x" + }, + { + "supported_until": "2022-12", + "branch_name": "master" + }, + { + "supported_until": "2019-12", + "branch_name": "nightly-3.10.x" + }, + { + "supported_until": "2021-08", + "branch_name": "nightly-3.12.x" + }, + { + "supported_until": "2021-08", + "branch_name": "3.12.x" + }, + { + "supported_until": "2019-12", + "branch_name": "3.10.x" + }, + { + "supported_until": "2018-08", + "branch_name": "3.7.x" + } + ], + "releases": [ + { + "version": "master", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/master.json", + "debug": true, + "release_date": "nightly", + "lts_branch": "nightly-master", + "alpha": true + }, + { + "version": "3.29.0", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.29.0.json", + "debug": false, + "release_date": "2026-11-06", + "latest": true, + "latest_stable": true + }, + { + "version": "3.28.0", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.28.0.json", + "debug": false, + "release_date": "2026-07-10" + }, + { + "version": "3.27.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.27.x.json", + "debug": true, + "release_date": "nightly", + "lts_branch": "nightly-3.27.x" + }, + { + "version": "3.27.3", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.27.3.json", + "debug": false, + "release_date": "2026-10-22", + "lts_branch": "3.27.x", + "latest_on_branch": true, + "latestLTS": true + }, + { + "version": "3.27.2", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.27.2.json", + "debug": false, + "release_date": "2026-10-15", + "lts_branch": "3.27.x" + }, + { + "version": "3.27.1", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.27.1.json", + "debug": false, + "release_date": "2026-05-08", + "lts_branch": "3.27.x" + }, + { + "lts_branch": "3.27.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.27.0.json", + "release_date": "2026-01-12", + "version": "3.27.0", + "debug": false + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.26.0.json", + "debug": false, + "release_date": "2025-05-20", + "version": "3.26.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.25.0.json", + "debug": false, + "release_date": "2025-01-06", + "version": "3.25.0" + }, + { + "version": "3.24.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.24.x.json", + "debug": true, + "release_date": "nightly", + "lts_branch": "nightly-3.24.x" + }, + { + "version": "3.24.6", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.24.6.json", + "debug": false, + "release_date": "2026-10-22", + "lts_branch": "3.24.x", + "latest_on_branch": true + }, + { + "version": "3.24.5", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.24.5.json", + "debug": false, + "release_date": "2026-10-15", + "lts_branch": "3.24.x" + }, + { + "version": "3.24.4", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.24.4.json", + "debug": false, + "release_date": "2026-05-08", + "lts_branch": "3.24.x" + }, + { + "lts_branch": "3.24.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.24.3.json", + "release_date": "2025-12-12", + "version": "3.24.3", + "debug": false + }, + { + "lts_branch": "3.24.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.24.2.json", + "release_date": "2025-05-15", + "version": "3.24.2", + "debug": false + }, + { + "lts_branch": "3.24.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.24.1.json", + "release_date": "2024-12-04", + "version": "3.24.1", + "debug": false + }, + { + "lts_branch": "3.24.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.24.0.json", + "release_date": "2024-08-02", + "version": "3.24.0", + "debug": false + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.23.0.json", + "debug": false, + "release_date": "2023-12-05", + "version": "3.23.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.22.0.json", + "debug": false, + "release_date": "2023-06-16", + "version": "3.22.0" + }, + { + "lts_branch": "nightly-3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.x.json", + "release_date": "2026-01-10", + "version": "3.21.x", + "debug": true + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.8.json", + "release_date": "2025-12-12", + "version": "3.21.8", + "debug": false, + "latest_on_branch": true + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.7.json", + "release_date": "2025-05-14", + "version": "3.21.7", + "debug": false + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.6.json", + "release_date": "2024-12-03", + "version": "3.21.6", + "debug": false + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.5.json", + "release_date": "2024-06-21", + "version": "3.21.5", + "debug": false + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.4.json", + "release_date": "2024-01-11", + "version": "3.21.4", + "debug": false + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.3.json", + "release_date": "2023-10-06", + "version": "3.21.3", + "debug": false + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.2.json", + "release_date": "2023-06-08", + "version": "3.21.2", + "debug": false + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.1.json", + "release_date": "2023-04-24", + "version": "3.21.1", + "debug": false + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.21.0.json", + "release_date": "2022-12-21", + "version": "3.21.0", + "debug": false + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.20.0.json", + "debug": false, + "release_date": "2022-06-30", + "version": "3.20.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.19.0.json", + "debug": false, + "release_date": "2021-12-09", + "version": "3.19.0" + }, + { + "lts_branch": "nightly-3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.x.json", + "release_date": "2024-07-23", + "version": "3.18.x", + "debug": true + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.8.json", + "release_date": "2024-06-20", + "version": "3.18.8", + "debug": false, + "latest_on_branch": true + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.7.json", + "release_date": "2024-01-11", + "version": "3.18.7", + "debug": false + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.6.json", + "release_date": "2023-10-06", + "version": "3.18.6", + "debug": false + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.5.json", + "release_date": "2023-06-08", + "version": "3.18.5", + "debug": false + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.4.json", + "release_date": "2023-04-24", + "version": "3.18.4", + "debug": false + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.3.json", + "release_date": "2022-11-18", + "version": "3.18.3", + "debug": false + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.2.json", + "release_date": "2022-06-29", + "version": "3.18.2", + "debug": false + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.1.json", + "release_date": "2021-11-29", + "version": "3.18.1", + "debug": false + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.18.0.json", + "release_date": "2021-06-24", + "version": "3.18.0", + "debug": false + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.17.0.json", + "debug": false, + "release_date": "2020-11-19", + "version": "3.17.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.16.0.json", + "debug": false, + "release_date": "2020-06-23", + "version": "3.16.0" + }, + { + "lts_branch": "nightly-3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.x.json", + "release_date": "2022-12-02", + "version": "3.15.x", + "debug": true + }, + { + "lts_branch": "3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.7.json", + "release_date": "2022-11-14", + "version": "3.15.7", + "debug": false, + "latest_on_branch": true + }, + { + "lts_branch": "3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.6.json", + "release_date": "2022-06-29", + "version": "3.15.6", + "debug": false + }, + { + "lts_branch": "3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.5.json", + "release_date": "2021-11-29", + "version": "3.15.5", + "debug": false + }, + { + "lts_branch": "3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.4.json", + "release_date": "2021-06-08", + "version": "3.15.4", + "debug": false + }, + { + "lts_branch": "3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.3.json", + "release_date": "2020-11-10", + "version": "3.15.3", + "debug": false + }, + { + "lts_branch": "3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.2.json", + "release_date": "2020-06-02", + "version": "3.15.2", + "debug": false + }, + { + "lts_branch": "3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.1.json", + "release_date": "2020-03-25", + "version": "3.15.1", + "debug": false + }, + { + "lts_branch": "3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.0.json", + "release_date": "2020-01-28", + "version": "3.15.0", + "debug": false + }, + { + "lts_branch": "master", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.15.0b1.json", + "release_date": "2019-09-17", + "beta": true, + "version": "3.15.0b1", + "debug": false + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.14.0.json", + "release_date": "2019-07-01", + "version": "3.14.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.13.0.json", + "release_date": "2018-11-23", + "version": "3.13.0" + }, + { + "lts_branch": "nightly-3.12.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.x.json", + "release_date": "2022-02-22", + "version": "3.12.x", + "debug": true + }, + { + "lts_branch": "3.12.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.7.json", + "release_date": "2021-06-08", + "version": "3.12.7", + "debug": false, + "latest_on_branch": true + }, + { + "lts_branch": "3.12.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.6.json", + "release_date": "2020-11-10", + "version": "3.12.6", + "debug": false + }, + { + "lts_branch": "3.12.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.5.json", + "release_date": "2020-06-02", + "version": "3.12.5", + "debug": false + }, + { + "lts_branch": "3.12.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.4.json", + "release_date": "2020-04-06", + "version": "3.12.4", + "debug": false + }, + { + "lts_branch": "3.12.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.3.json", + "release_date": "2020-01-30", + "version": "3.12.3", + "debug": false + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.2.json", + "release_date": "2019-05-20", + "version": "3.12.2", + "lts_branch": "3.12.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.1.json", + "release_date": "2018-11-30", + "version": "3.12.1", + "lts_branch": "3.12.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.0.json", + "release_date": "2018-06-28", + "version": "3.12.0", + "lts_branch": "3.12.x" + }, + { + "lts_branch": "3.12.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.12.0b1.json", + "release_date": "2018-05-08", + "beta": true, + "version": "3.12.0b1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.11.0.json", + "release_date": "2017-08-11", + "version": "3.11.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.11.0b1.json", + "release_date": "2017-06-14", + "version": "3.11.0b1", + "beta": true + }, + { + "lts_branch": "nightly-3.10.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.x.json", + "release_date": "2019-10-23", + "version": "3.10.x", + "debug": true + }, + { + "lts_branch": "3.10.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.7.json", + "release_date": "2019-12-06", + "version": "3.10.7", + "debug": false, + "latest_on_branch": true + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.6.json", + "release_date": "2019-05-10", + "version": "3.10.6", + "lts_branch": "3.10.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.5.json", + "release_date": "2018-11-16", + "version": "3.10.5", + "lts_branch": "3.10.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.4.json", + "release_date": "2018-05-02", + "version": "3.10.4", + "lts_branch": "3.10.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.3.json", + "release_date": "2018-02-02", + "version": "3.10.3", + "lts_branch": "3.10.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.2.json", + "release_date": "2017-08-11", + "version": "3.10.2", + "lts_branch": "3.10.x" + }, + { + "LTS": true, + "lts_branch": "3.10.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.1.json", + "release_date": "2017-03-29", + "version": "3.10.1" + }, + { + "LTS": true, + "lts_branch": "3.10.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.0.json", + "release_date": "2016-12-27", + "version": "3.10.0" + }, + { + "LTS": true, + "lts_branch": "3.10.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.10.0b1.json", + "release_date": "2016-11-08", + "beta": true, + "version": "3.10.0b1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.9.2.json", + "release_date": "2016-12-27", + "version": "3.9.2" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.9.1.json", + "release_date": "2016-08-03", + "version": "3.9.1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.9.0.json", + "release_date": "2016-06-14", + "version": "3.9.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.9.0b1.json", + "release_date": "2016-05-11", + "version": "3.9.0b1", + "beta": true + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.8.2.json", + "release_date": "2016-04-01", + "version": "3.8.2" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.8.1.json", + "release_date": "2015-02-01", + "version": "3.8.1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.8.0.json", + "release_date": "2015-12-05", + "version": "3.8.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.8.0b1.json", + "release_date": "2015-11-11", + "version": "3.8.0b1", + "beta": true + }, + { + "lts_branch": "3.7.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.8.json", + "release_date": "2018-05-02", + "version": "3.7.8", + "latest_on_branch": true + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.7.json", + "release_date": "2018-02-02", + "version": "3.7.7", + "lts_branch": "3.7.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.6.json", + "release_date": "2017-09-11", + "version": "3.7.6", + "lts_branch": "3.7.x" + }, + { + "LTS": true, + "lts_branch": "3.7.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.5.json", + "release_date": "2017-03-29", + "version": "3.7.5" + }, + { + "LTS": true, + "lts_branch": "3.7.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.4.json", + "release_date": "2016-08-03", + "version": "3.7.4" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.3.json", + "release_date": "2016-04-01", + "version": "3.7.3", + "lts_branch": "3.7.x" + }, + { + "LTS": true, + "lts_branch": "3.7.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.2.json", + "release_date": "2015-12-02", + "version": "3.7.2" + }, + { + "LTS": true, + "lts_branch": "3.7.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.1.json", + "release_date": "2015-09-09", + "version": "3.7.1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.0.json", + "release_date": "2015-07-17", + "version": "3.7.0", + "lts_branch": "3.7.x" + }, + { + "LTS": true, + "lts_branch": "3.7.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.7.0b1-1.json", + "release_date": "2015-06-17", + "beta": true, + "version": "3.7.0b1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.6.7.json", + "release_date": "2016-04-01", + "version": "3.6.7" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.6.6.json", + "release_date": "2015-07-20", + "version": "3.6.6" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.6.5-1.json", + "release_date": "2015-03-12", + "version": "3.6.5" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.6.4-1.json", + "release_date": "2015-01-27", + "version": "3.6.4" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.6.3-1.json", + "release_date": "2014-12-06", + "version": "3.6.3" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.6.2-1.json", + "release_date": "2014-10-02", + "version": "3.6.2" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.6.1-1.json", + "release_date": "2014-07-28", + "version": "3.6.1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.6.0-1.json", + "release_date": "2014-06-18", + "version": "3.6.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.5.3-1.json", + "release_date": "2013-12-09", + "version": "3.5.3" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.5.2-1.json", + "release_date": "2013-08-30", + "version": "3.5.2" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.5.1-1.json", + "release_date": "2013-07-11", + "version": "3.5.1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.5.1-3.json", + "release_date": "2013-07-18", + "version": "3.5.1-3" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.5.0-1.json", + "release_date": "2013-06-12", + "version": "3.5.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.4.5-1.json", + "release_date": "2013-06-28", + "version": "3.4.5" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.4.4-1.json", + "release_date": "2013-03-15", + "version": "3.4.4" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.4.3-1.json", + "release_date": "2013-02-19", + "version": "3.4.3" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.4.2-1.json", + "release_date": "2013-01-11", + "version": "3.4.2" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.4.1-1.json", + "release_date": "2012-12-06", + "version": "3.4.1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/community/3.4.0-1.json", + "release_date": "2012-11-26", + "version": "3.4.0" + } + ] +} \ No newline at end of file diff --git a/tests/release/data/enterprise-3.29.0.json b/tests/release/data/enterprise-3.29.0.json new file mode 100644 index 00000000..5fe3d395 --- /dev/null +++ b/tests/release/data/enterprise-3.29.0.json @@ -0,0 +1,341 @@ +{ + "project": "enterprise", + "version": "3.29.0 non-LTS (unsupported)", + "note": "Please note that non-LTS releases are unsupported, i.e. excluded from CFEngine Enterprise support contract, and we do not recommend installing them in production.", + "artifacts": { + "Policy Server": [ + { + "Title": "Debian 12", + "Arch": "x86_64", + "classexpr": "am_policy_hub.debian_12.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/debian_12_x86_64/cfengine-nova-hub_3.29.0-1.debian12_amd64.deb", + "SHA256": "16be9ca7a5ef32541038f07b506ec231ddbc06bc443f24ef0621e2975891aa63", + "package": "PACKAGES_HUB_x86_64_linux_debian_12" + }, + { + "Title": "Debian 12", + "Arch": "aarch64", + "classexpr": "am_policy_hub.debian_12.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/debian_12_arm_64/cfengine-nova-hub_3.29.0-1.debian12_arm64.deb", + "SHA256": "b6325ed891bc946bc26f3821ed0c40777b914723d2944af927ef0c142489d6ab", + "package": "PACKAGES_HUB_arm_64_linux_debian_12" + }, + { + "Title": "Debian 13", + "Arch": "x86_64", + "classexpr": "am_policy_hub.debian_13.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/debian_13_x86_64/cfengine-nova-hub_3.29.0-1.debian13_amd64.deb", + "SHA256": "a096a67743bb91271e1277d5c543753c5bd5685a78889c85274b3b07bd845597", + "package": "PACKAGES_HUB_x86_64_linux_debian_13" + }, + { + "Title": "Debian 13", + "Arch": "aarch64", + "classexpr": "am_policy_hub.debian_13.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/debian_13_arm_64/cfengine-nova-hub_3.29.0-1.debian13_arm64.deb", + "SHA256": "9b3e5d750003abe7ef287bc6dde788cfbc93979f3e15dd87b47c94d941d6f0f7", + "package": "PACKAGES_HUB_arm_64_linux_debian_13" + }, + { + "Title": "Ubuntu 22", + "Arch": "x86_64", + "classexpr": "am_policy_hub.ubuntu_22.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/ubuntu_22_x86_64/cfengine-nova-hub_3.29.0-1.ubuntu22_amd64.deb", + "SHA256": "7ff693357af603806f2b2caa5e6fde354409f4d08b5771c38cc9ceea1a2f70bb", + "package": "PACKAGES_HUB_x86_64_linux_ubuntu_22" + }, + { + "Title": "Ubuntu 22", + "Arch": "aarch64", + "classexpr": "am_policy_hub.ubuntu_22.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/ubuntu_22_arm_64/cfengine-nova-hub_3.29.0-1.ubuntu22_arm64.deb", + "SHA256": "53cf020104ba7158cee413c0d741b01ba9ee447f64e3936d28bd1aca6d9e5e08", + "package": "PACKAGES_HUB_arm_64_linux_ubuntu_22" + }, + { + "Title": "Ubuntu 24", + "Arch": "x86_64", + "classexpr": "am_policy_hub.ubuntu_24.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/ubuntu_24_x86_64/cfengine-nova-hub_3.29.0-1.ubuntu24_amd64.deb", + "SHA256": "fa0fc3a1cd9b4bdf5485e00695692027fb59b5324d600cff7dc3425c1ac0881c", + "package": "PACKAGES_HUB_x86_64_linux_ubuntu_24" + }, + { + "Title": "Ubuntu 24", + "Arch": "aarch64", + "classexpr": "am_policy_hub.ubuntu_24.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/ubuntu_24_arm_64/cfengine-nova-hub_3.29.0-1.ubuntu24_arm64.deb", + "SHA256": "0ffdcfe67f965756c977a46d9dd74d1174359cd7e517acdb3be1787262fcb2e6", + "package": "PACKAGES_HUB_arm_64_linux_ubuntu_24" + }, + { + "Title": "Ubuntu 26", + "Arch": "x86_64", + "classexpr": "am_policy_hub.ubuntu_26.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/ubuntu_26_x86_64/cfengine-nova-hub_3.29.0-1.ubuntu26_amd64.deb", + "SHA256": "727e1db2b2d95e6e5be5ac95f41f30fd0ff3cf23c8d3c54da4b0cc0463122918", + "package": "PACKAGES_HUB_x86_64_linux_ubuntu_26" + }, + { + "Title": "Ubuntu 26", + "Arch": "aarch64", + "classexpr": "am_policy_hub.ubuntu_26.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/ubuntu_26_arm_64/cfengine-nova-hub_3.29.0-1.ubuntu26_arm64.deb", + "SHA256": "d92917d5c6a476102dea0e75d96803df006854cb470f25adc001221511cb0651", + "package": "PACKAGES_HUB_arm_64_linux_ubuntu_26" + }, + { + "Title": "Red Hat / CentOS 8", + "Arch": "x86_64", + "classexpr": "am_policy_hub.(redhat_8|centos_8).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/redhat_8_x86_64/cfengine-nova-hub-3.29.0-1.el8.x86_64.rpm", + "SHA256": "7f28bc94582f1c4d845057e0ed95ed4ffa4fb375c4bef6ba696f4f73254d38fc", + "package": "PACKAGES_HUB_x86_64_linux_redhat_8" + }, + { + "Title": "Red Hat 9", + "Arch": "x86_64", + "classexpr": "am_policy_hub.redhat_9.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/redhat_9_x86_64/cfengine-nova-hub-3.29.0-1.el9.x86_64.rpm", + "SHA256": "ef6134fbbb474d8bb5c5b1fd454a97ddea050df6b39b8be2ae1698bf81311f36", + "package": "PACKAGES_HUB_x86_64_linux_redhat_9" + }, + { + "Title": "Red Hat 10", + "Arch": "x86_64", + "classexpr": "am_policy_hub.redhat_10.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/redhat_10_x86_64/cfengine-nova-hub-3.29.0-1.el10.x86_64.rpm", + "SHA256": "5df934e84861b70b98cbc49d450fb33ec6c79e7396c31337f3d0ac747d92dc58", + "package": "PACKAGES_HUB_x86_64_linux_redhat_10" + }, + { + "Title": "Red Hat 10", + "Arch": "aarch64", + "classexpr": "am_policy_hub.redhat_10.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/hub/redhat_10_arm_64/cfengine-nova-hub-3.29.0-1.el10.aarch64.rpm", + "SHA256": "a58a0f55307f575b9dec467a34d26dde30edbca4639e9b119446fffaadc67110", + "package": "PACKAGES_HUB_arm_64_linux_redhat_10" + } + ], + "Hosts (Clients)": [ + { + "Title": "Debian 12", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.debian_12.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_debian12_x86_64/cfengine-nova_3.29.0-1.debian12_amd64.deb", + "SHA256": "cf69fd97b4ce3b5129f01f9bd5734d2eaa9f19149f831ccf28d390e154a74d38", + "package": "PACKAGES_x86_64_linux_debian_12" + }, + { + "Title": "Debian 12", + "Arch": "aarch64", + "classexpr": "!am_policy_hub.debian_12.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_debian12_arm_64/cfengine-nova_3.29.0-1.debian12_arm64.deb", + "SHA256": "ff526c962fe140fabc30a1cbeaa3f0f7e73284f81b8905eea1f6245a1bfb9955", + "package": "PACKAGES_arm_64_linux_debian_12" + }, + { + "Title": "Debian 13", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.debian_13.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_debian13_x86_64/cfengine-nova_3.29.0-1.debian13_amd64.deb", + "SHA256": "0cbabc9af08a123f27c73236753511200172e61366cad62274859840bc277ec3", + "package": "PACKAGES_x86_64_linux_debian_13" + }, + { + "Title": "Debian 13", + "Arch": "aarch64", + "classexpr": "!am_policy_hub.debian_13.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_debian13_arm_64/cfengine-nova_3.29.0-1.debian13_arm64.deb", + "SHA256": "e13e19d10c4469e56d8b870ae575ef1d7255ff558a00e17154564c148eb0894f", + "package": "PACKAGES_arm_64_linux_debian_13" + }, + { + "Title": "Ubuntu 20", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.ubuntu_20.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_ubuntu20_x86_64/cfengine-nova_3.29.0-1.ubuntu20_amd64.deb", + "SHA256": "381efca090302b0fe47fed05f97702ca4a12f4ab5ecf193cc6c6cd436bff507e", + "package": "PACKAGES_x86_64_linux_ubuntu_20" + }, + { + "Title": "Ubuntu 22", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.ubuntu_22.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_ubuntu22_x86_64/cfengine-nova_3.29.0-1.ubuntu22_amd64.deb", + "SHA256": "36d3bf12fc4881c1e3a23611b9776bcf7f96e07a0446c455c2dbde20d8f487fd", + "package": "PACKAGES_x86_64_linux_ubuntu_22" + }, + { + "Title": "Ubuntu 22", + "Arch": "aarch64", + "classexpr": "!am_policy_hub.ubuntu_22.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_ubuntu22_arm_64/cfengine-nova_3.29.0-1.ubuntu22_arm64.deb", + "SHA256": "962a929a9020d0aa66e11cab0480403cae443f8c33a96418ec8c808f307ab4b5", + "package": "PACKAGES_arm_64_linux_ubuntu_22" + }, + { + "Title": "Ubuntu 24", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.ubuntu_24.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_ubuntu24_x86_64/cfengine-nova_3.29.0-1.ubuntu24_amd64.deb", + "SHA256": "2d01dac8bae6b5febbecda4e35a3be71479d351ab4186a122fef4e828926e43d", + "package": "PACKAGES_x86_64_linux_ubuntu_24" + }, + { + "Title": "Ubuntu 24", + "Arch": "aarch64", + "classexpr": "!am_policy_hub.ubuntu_24.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_ubuntu24_arm_64/cfengine-nova_3.29.0-1.ubuntu24_arm64.deb", + "SHA256": "ecf422289e9c5fad500b5d1a6b765b7c415cd757f1a7ce9f89a7f642771f4ec0", + "package": "PACKAGES_arm_64_linux_ubuntu_24" + }, + { + "Title": "Ubuntu 26", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.ubuntu_26.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_ubuntu26_x86_64/cfengine-nova_3.29.0-1.ubuntu26_amd64.deb", + "SHA256": "e28f1a6a6027df02bbbd20201e871ca7f8213fcdc4bdd2264eb5b4ba06cca5af", + "package": "PACKAGES_x86_64_linux_ubuntu_26" + }, + { + "Title": "Ubuntu 26", + "Arch": "aarch64", + "classexpr": "!am_policy_hub.ubuntu_26.aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_ubuntu26_arm_64/cfengine-nova_3.29.0-1.ubuntu26_arm64.deb", + "SHA256": "485ad8fa9317ea142f799461819edc4c0a7d4e9345e591a504294107107bccdd", + "package": "PACKAGES_arm_64_linux_ubuntu_26" + }, + { + "Title": "Red Hat / CentOS 7", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.(redhat_7|centos_7).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_rhel7_x86_64/cfengine-nova-3.29.0-1.el7.x86_64.rpm", + "SHA256": "3bafc5d59eaecbef9a6f14178a988208aebe55ebc7e74e295f2015fbe98e1b90", + "package": "PACKAGES_x86_64_linux_redhat_7" + }, + { + "Title": "Red Hat / CentOS 8.1", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.(redhat_8|centos_8).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_rhel8_x86_64/cfengine-nova-3.29.0-1.el8.x86_64.rpm", + "SHA256": "90aaad28dcd76ade16db8ed74c474b73ec17f5acc3038bf7e91ea7c85e3d1d7c", + "package": "PACKAGES_x86_64_linux_redhat_8" + }, + { + "Title": "Red Hat / CentOS 8.1", + "Arch": "aarch64", + "classexpr": "!am_policy_hub.(redhat_8|centos_8).aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_rhel8_arm_64/cfengine-nova-3.29.0-1.el8.aarch64.rpm", + "SHA256": "ea41dd919a1250a17639221f3a57565560cb50e2f4e254de7c31697e26a60dd7", + "package": "PACKAGES_arm_64_linux_redhat_8" + }, + { + "Title": "Red Hat / CentOS 9", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.(redhat_9|centos_9).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_rhel9_x86_64/cfengine-nova-3.29.0-1.el9.x86_64.rpm", + "SHA256": "5398938d0bdacfe4137af45bc40109420ac321c5967a04e56d30a05085082f26", + "package": "PACKAGES_x86_64_linux_redhat_9" + }, + { + "Title": "Red Hat / CentOS 9", + "Arch": "aarch64", + "classexpr": "!am_policy_hub.(redhat_9|centos_9).aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_rhel9_arm_64/cfengine-nova-3.29.0-1.el9.aarch64.rpm", + "SHA256": "c72cc9d9bce08d45b05a4596d52a8be2d85b622851d17292c8d8bca0161bc87a", + "package": "PACKAGES_arm_64_linux_redhat_9" + }, + { + "Title": "Red Hat / CentOS 10", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.(redhat_10|centos_10).x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_rhel10_x86_64/cfengine-nova-3.29.0-1.el10.x86_64.rpm", + "SHA256": "dd10b18a640317e28a53e54dc46a9aae796ddc5a8d25759bc2a6f25317e7cb23", + "package": "PACKAGES_x86_64_linux_redhat_10" + }, + { + "Title": "Red Hat / CentOS 10", + "Arch": "aarch64", + "classexpr": "!am_policy_hub.(redhat_10|centos_10).aarch64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/agent_rhel10_arm_64/cfengine-nova-3.29.0-1.el10.aarch64.rpm", + "SHA256": "5474b340a879e68d9d8c20a3a70a7a7e5efdfd778a1db8f840b45c89d2ca70b2", + "package": "PACKAGES_arm_64_linux_redhat_10" + }, + { + "Title": "Windows Server 2012", + "Arch": "x86_64", + "classexpr": "!am_policy_hub.windows.x86_64", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/agent/windows_x86_64/cfengine-nova-3.29.0-1-x86_64.msi", + "SHA256": "0f24d9451089d98bdb9a8d0c8e085e0e9269b39e67400e2a7356f287739866e4", + "package": "PACKAGES_x86_64_mingw" + } + ], + "Additional Assets": [ + { + "Title": "Masterfiles ready-to-install tarball", + "Arch": "no arch", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/misc/cfengine-masterfiles-3.29.0-1.pkg.tar.gz", + "SHA256": "a165e7e67a88a578ab95675716d961b6c41330549ae12163113a4dabf505f769", + "package": "PACKAGES_VIRTUAL_PACKAGES_masterfiles" + }, + { + "Title": "Linux binary tarball (unsupported)", + "Arch": "x86_64", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/misc/cfengine-nova-3.29.0-1.x86_64.pkg.tar.gz", + "SHA256": "f2f7a69cff27c7efd81b9e7d2384f6b7b673f9c252e6cf5a0828d9c30693eb27", + "Footnote": 1, + "Instructions": "https://docs.cfengine.com/docs/3.29/getting-started-installation-general-installation-installation-enterprise-generic-tarball.html" + }, + { + "Title": "Vagrant Environment", + "Arch": "Linux/Mac/Windows (Virtualbox)", + "classexpr": "!any", + "Published": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/enterprise/Enterprise-3.29.0/misc/CFEngine_Enterprise_vagrant_quickstart-3.29.0-1.tar.gz", + "SHA256": "c62d0dceed34715249105fa46ca356af3e98a5b9afdca157d2aaaf0a485bfcfe", + "Instructions": "https://docs.cfengine.com/docs/3.29/getting-started-installation-general-installation-installation-enterprise-vagrant.html" + } + ] + }, + "footnotes": [ + "Tarball containing compiled CFEngine host (client) binaries that runs on most Linux systems but are not optimized for specific library or platform features. Appropriate for testing purposes. Not supported under the CFEngine support contract." + ] +} \ No newline at end of file diff --git a/tests/release/data/enterprise-releases.json b/tests/release/data/enterprise-releases.json new file mode 100644 index 00000000..fb86404e --- /dev/null +++ b/tests/release/data/enterprise-releases.json @@ -0,0 +1,664 @@ +{ + "lts_branches": [ + { + "supported_until": "2028-12", + "branch_name": "3.27.x" + }, + { + "supported_until": "2027-08", + "branch_name": "3.24.x" + }, + { + "supported_until": "2025-12", + "branch_name": "3.21.x" + }, + { + "supported_until": "2024-08", + "branch_name": "3.18.x" + }, + { + "supported_until": "2022-12", + "branch_name": "3.15.x" + }, + { + "supported_until": "2022-12", + "branch_name": "master" + }, + { + "supported_until": "2021-08", + "branch_name": "3.12.x" + }, + { + "supported_until": "2019-12", + "branch_name": "3.10.x" + }, + { + "supported_until": "2018-08", + "branch_name": "3.7.x" + } + ], + "releases": [ + { + "version": "master", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/master.json", + "debug": true, + "release_date": "nightly", + "alpha": true + }, + { + "version": "3.29.0", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.29.0.json", + "debug": false, + "release_date": "2026-11-06", + "latest": true, + "latest_stable": true + }, + { + "version": "3.28.0", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.28.0.json", + "debug": false, + "release_date": "2026-07-10" + }, + { + "version": "3.27.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.27.x.json", + "debug": true, + "release_date": "nightly", + "lts_branch": "3.27.x" + }, + { + "version": "3.27.3", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.27.3.json", + "debug": false, + "release_date": "2026-10-22", + "lts_branch": "3.27.x", + "latest_on_branch": true, + "latestLTS": true + }, + { + "version": "3.27.2", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.27.2.json", + "debug": false, + "release_date": "2026-10-16", + "lts_branch": "3.27.x" + }, + { + "version": "3.27.1", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.27.1.json", + "debug": false, + "release_date": "2026-05-08", + "lts_branch": "3.27.x" + }, + { + "lts_branch": "3.27.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.27.0.json", + "release_date": "2026-01-12", + "version": "3.27.0", + "debug": false + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.26.0.json", + "debug": false, + "release_date": "2025-05-20", + "version": "3.26.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.25.0.json", + "debug": false, + "release_date": "2025-01-06", + "version": "3.25.0" + }, + { + "version": "3.24.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.24.x.json", + "debug": true, + "release_date": "nightly", + "lts_branch": "3.24.x" + }, + { + "version": "3.24.6", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.24.6.json", + "debug": false, + "release_date": "2026-10-22", + "lts_branch": "3.24.x", + "latest_on_branch": true + }, + { + "version": "3.24.5", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.24.5.json", + "debug": false, + "release_date": "2026-10-16", + "lts_branch": "3.24.x" + }, + { + "version": "3.24.4", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.24.4.json", + "debug": false, + "release_date": "2026-05-08", + "lts_branch": "3.24.x" + }, + { + "lts_branch": "3.24.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.24.3.json", + "release_date": "2025-12-12", + "version": "3.24.3", + "debug": false + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.24.2.json", + "debug": false, + "release_date": "2025-05-15", + "version": "3.24.2", + "lts_branch": "3.24.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.24.1.json", + "debug": false, + "release_date": "2024-12-04", + "version": "3.24.1", + "lts_branch": "3.24.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.24.0.json", + "debug": false, + "release_date": "2024-07-22", + "version": "3.24.0", + "lts_branch": "3.24.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.23.0.json", + "debug": false, + "release_date": "2023-12-05", + "version": "3.23.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.22.0.json", + "debug": false, + "release_date": "2023-06-16", + "version": "3.22.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.x.json", + "debug": true, + "release_date": "2026-01-14", + "version": "3.21.x", + "lts_branch": "3.21.x" + }, + { + "lts_branch": "3.21.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.8.json", + "release_date": "2025-12-12", + "version": "3.21.8", + "debug": false, + "latest_on_branch": true + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.7.json", + "debug": false, + "release_date": "2025-05-14", + "version": "3.21.7", + "lts_branch": "3.21.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.6.json", + "debug": false, + "release_date": "2024-12-03", + "version": "3.21.6", + "lts_branch": "3.21.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.5.json", + "debug": false, + "release_date": "2024-06-20", + "version": "3.21.5", + "lts_branch": "3.21.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.4.json", + "debug": false, + "release_date": "2024-01-11", + "version": "3.21.4", + "lts_branch": "3.21.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.3.json", + "debug": false, + "release_date": "2023-10-06", + "version": "3.21.3", + "lts_branch": "3.21.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.2.json", + "debug": false, + "release_date": "2023-06-08", + "version": "3.21.2", + "lts_branch": "3.21.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.1.json", + "debug": false, + "release_date": "2023-03-02", + "version": "3.21.1", + "lts_branch": "3.21.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.21.0.json", + "debug": false, + "release_date": "2022-12-22", + "version": "3.21.0", + "lts_branch": "3.21.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.20.0.json", + "debug": false, + "release_date": "2022-07-01", + "version": "3.20.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.19.0.json", + "debug": false, + "release_date": "2021-12-09", + "version": "3.19.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.x.json", + "debug": true, + "release_date": "2024-07-23", + "version": "3.18.x", + "lts_branch": "3.18.x" + }, + { + "lts_branch": "3.18.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.8.json", + "release_date": "2024-06-20", + "version": "3.18.8", + "debug": false, + "latest_on_branch": true + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.7.json", + "debug": false, + "release_date": "2024-01-11", + "version": "3.18.7", + "lts_branch": "3.18.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.6.json", + "debug": false, + "release_date": "2023-10-06", + "version": "3.18.6", + "lts_branch": "3.18.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.5.json", + "debug": false, + "release_date": "2023-08-31", + "version": "3.18.5", + "lts_branch": "3.18.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.4.json", + "debug": false, + "release_date": "2023-03-02", + "version": "3.18.4", + "lts_branch": "3.18.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.3.json", + "debug": false, + "release_date": "2022-11-18", + "version": "3.18.3", + "lts_branch": "3.18.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.2.json", + "debug": false, + "release_date": "2022-06-29", + "version": "3.18.2", + "lts_branch": "3.18.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.1.json", + "debug": false, + "release_date": "2021-11-26", + "version": "3.18.1", + "lts_branch": "3.18.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.18.0.json", + "debug": false, + "release_date": "2021-06-24", + "version": "3.18.0", + "lts_branch": "3.18.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.17.0.json", + "debug": false, + "release_date": "2020-11-19", + "version": "3.17.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.16.0.json", + "debug": false, + "release_date": "2020-06-23", + "version": "3.16.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.x.json", + "debug": true, + "release_date": "2022-12-02", + "version": "3.15.x", + "lts_branch": "3.15.x" + }, + { + "lts_branch": "3.15.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.7.json", + "release_date": "2022-11-14", + "version": "3.15.7", + "debug": false, + "latest_on_branch": true + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.6.json", + "debug": false, + "release_date": "2022-06-29", + "version": "3.15.6", + "lts_branch": "3.15.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.5.json", + "debug": false, + "release_date": "2021-11-26", + "version": "3.15.5", + "lts_branch": "3.15.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.4.json", + "debug": false, + "release_date": "2021-06-08", + "version": "3.15.4", + "lts_branch": "3.15.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.3.json", + "debug": false, + "release_date": "2020-11-10", + "version": "3.15.3", + "lts_branch": "3.15.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.2.json", + "debug": false, + "release_date": "2020-06-02", + "version": "3.15.2", + "lts_branch": "3.15.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.1.json", + "debug": false, + "release_date": "2020-03-25", + "version": "3.15.1", + "lts_branch": "3.15.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.0.json", + "debug": false, + "release_date": "2020-01-28", + "version": "3.15.0", + "lts_branch": "3.15.x" + }, + { + "lts_branch": "master", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.15.0b1.json", + "release_date": "2019-09-17", + "beta": true, + "version": "3.15.0b1", + "debug": false + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.14.0.json", + "debug": false, + "release_date": "2019-07-01", + "version": "3.14.0", + "re-release_date": "2019-07-29" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.13.0.json", + "version": "3.13.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.12.x.json", + "debug": true, + "release_date": "2021-06-25", + "version": "3.12.x", + "lts_branch": "3.12.x" + }, + { + "lts_branch": "3.12.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.12.7.json", + "release_date": "2021-06-08", + "version": "3.12.7", + "debug": false, + "latest_on_branch": true + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.12.6.json", + "debug": false, + "release_date": "2020-11-10", + "version": "3.12.6", + "lts_branch": "3.12.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.12.5.json", + "debug": false, + "release_date": "2020-06-02", + "version": "3.12.5", + "lts_branch": "3.12.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.12.4.json", + "debug": false, + "release_date": "2020-04-06", + "version": "3.12.4", + "lts_branch": "3.12.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.12.3.json", + "debug": false, + "release_date": "2020-01-29", + "version": "3.12.3", + "lts_branch": "3.12.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.12.2.json", + "debug": false, + "release_date": "2019-10-03", + "version": "3.12.2", + "lts_branch": "3.12.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.12.1.json", + "version": "3.12.1", + "lts_branch": "3.12.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.12.0.json", + "version": "3.12.0", + "lts_branch": "3.12.x" + }, + { + "comment": "after LTS/non-LTS split, this should become unsupported", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.11.0.json", + "version": "3.11.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.11.0b1.json", + "version": "3.11.0b1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.10.x.json", + "debug": true, + "release_date": "2019-11-27", + "version": "3.10.x", + "lts_branch": "3.10.x" + }, + { + "lts_branch": "3.10.x", + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.10.7.json", + "release_date": "2019-12-06", + "version": "3.10.7", + "debug": false, + "latest_on_branch": true + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.10.6.json", + "debug": false, + "version": "3.10.6", + "lts_branch": "3.10.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.10.5.json", + "version": "3.10.5", + "lts_branch": "3.10.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.10.4.json", + "version": "3.10.4", + "lts_branch": "3.10.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.10.3.json", + "version": "3.10.3", + "lts_branch": "3.10.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.10.2.json", + "version": "3.10.2", + "lts_branch": "3.10.x" + }, + { + "LTS": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.10.1.json", + "version": "3.10.1", + "lts_branch": "3.10.x" + }, + { + "LTS": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.10.0.json", + "version": "3.10.0", + "lts_branch": "3.10.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.9.2.json", + "version": "3.9.2" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.9.0.json", + "version": "3.9.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.9.0b1.json", + "version": "3.9.0b1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.8.2.json", + "version": "3.8.2" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.8.1.json", + "version": "3.8.1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.8.0.json", + "version": "3.8.0" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.8.0b1.json", + "version": "3.8.0b1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.7.8.json", + "version": "3.7.8", + "lts_branch": "3.7.x", + "latest_on_branch": true + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.7.7.json", + "version": "3.7.7", + "lts_branch": "3.7.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.7.6.json", + "version": "3.7.6", + "lts_branch": "3.7.x" + }, + { + "LTS": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.7.5.json", + "version": "3.7.5", + "lts_branch": "3.7.x" + }, + { + "LTS": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.7.4.json", + "version": "3.7.4", + "lts_branch": "3.7.x" + }, + { + "LTS": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.7.3.json", + "version": "3.7.3", + "lts_branch": "3.7.x" + }, + { + "LTS": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.7.2.json", + "version": "3.7.2", + "lts_branch": "3.7.x" + }, + { + "LTS": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.7.1.json", + "version": "3.7.1", + "lts_branch": "3.7.x" + }, + { + "LTS": true, + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.7.0.json", + "version": "3.7.0", + "lts_branch": "3.7.x" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.6.7.json", + "version": "3.6.7" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.6.6.json", + "version": "3.6.6" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.6.5.json", + "version": "3.6.5" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.6.4.json", + "version": "3.6.4" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.6.3.json", + "version": "3.6.3" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.6.2.json", + "version": "3.6.2" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.6.1.json", + "version": "3.6.1" + }, + { + "URL": "https://cfengine-package-repos.s3.amazonaws.com/release-data/enterprise/3.6.0.json", + "version": "3.6.0" + } + ] +} \ No newline at end of file diff --git a/tests/release/e2e.sh b/tests/release/e2e.sh new file mode 100644 index 00000000..ab333718 --- /dev/null +++ b/tests/release/e2e.sh @@ -0,0 +1,194 @@ +#!/usr/bin/env bash +# End-to-end test of cfengine dev release and update-repo, with real tools. +# +# Recreates published community and enterprise releases from fake packages, +# and compares the release data with the published one. Needs gpg, rpm, +# rpmbuild, rpmsign, debsigs, apt-ftparchive and createrepo_c, so CI runs it as +# its own job. Run from the repo root, with cfengine in PATH, e.g. via uv run. + +set -euo pipefail + +TESTS="$(pwd)/tests/release" +DATA="$TESTS/data" +# The build time of the packages, as build-in-container sets it +export SOURCE_DATE_EPOCH=1700000000 + +WORK="$(mktemp -d)" +trap 'rm -rf "$WORK"' EXIT + +# A test key, so a real keyring is never used. Created before the build time, +# as gpg refuses to make signatures older than the key. +export GNUPGHOME="$WORK/gnupg" +mkdir -m 700 "$GNUPGHOME" +gpg --batch --quiet --faked-system-time 1600000000 --passphrase '' \ + --quick-gen-key "Test " rsa3072 sign never + +echo "Building a small .deb and .rpm" +mkdir -p "$WORK/deb/DEBIAN" "$WORK/rpm/SPECS" +cat >"$WORK/deb/DEBIAN/control" <<'EOF' +Package: probe +Version: 1.0 +Architecture: all +Maintainer: Test +Description: Test package +EOF +dpkg-deb --root-owner-group --build "$WORK/deb" "$WORK/probe.deb" >/dev/null +cat >"$WORK/rpm/SPECS/probe.spec" <<'EOF' +Name: probe +Version: 1.0 +Release: 1 +Summary: Test package +License: MIT +BuildArch: noarch +%description +Test package +%files +EOF +# Its own rpm database, also used to verify signatures below. Debian hosts +# have no system one. +rpm --dbpath "$WORK/rpmdb" --initdb +rpmbuild --quiet -bb --define "_topdir $WORK/rpm" --define "_dbpath $WORK/rpmdb" \ + --define "use_source_date_epoch_as_buildtime 1" "$WORK/rpm/SPECS/probe.spec" +RPM="$WORK/rpm/RPMS/noarch/probe-1.0-1.noarch.rpm" + +gpg --armor --export contact@northern.tech >"$WORK/key.asc" +rpm --dbpath "$WORK/rpmdb" --import "$WORK/key.asc" + +# An output dir with releases.json as before the release +new_output() { + local project="$1" version="$2" output="$3" + mkdir -p "$output/release-data/$project" + python3 - "$DATA/$project-releases.json" "$version" \ + >"$output/release-data/$project/releases.json" <<'EOF' +import json, sys +data = json.load(open(sys.argv[1])) +data["releases"] = [r for r in data["releases"] if r["version"] != sys.argv[2]] +print(json.dumps(data)) +EOF +} + +release() { + local project="$1" version="$2" + shift 2 + cfengine dev release --project "$project" --version "$version" \ + --build "$WORK/build-$project-$version" --output "$@" +} + +update_repo() { + local version="$1" output="$2" + cfengine dev update-repo --version "$version" \ + --build "$WORK/build-community-$version" --output "$output" +} + +test_release() { + local project="$1" version="$2" + local out="$WORK/out-$project-$version" + + echo "== $project $version" + echo "Generating the build" + python3 "$TESTS/make_build.py" "$DATA/$project-$version.json" \ + "$WORK/probe.deb" "$RPM" "$WORK/build-$project-$version" + + new_output "$project" "$version" "$out" + release "$project" "$version" "$out" + if [ "$project" = community ]; then + update_repo "$version" "$out" + fi + + echo "Comparing the release data with the published one" + python3 "$TESTS/compare.py" "$DATA/$project-$version.json" \ + "$out/release-data/$project/$version.json" "$version" + python3 "$TESTS/compare.py" "$DATA/$project-releases.json" \ + "$out/release-data/$project/releases.json" "$version" + + echo "Verifying the package signatures" + find "$out/release" -name '*.rpm' | while read -r rpm; do + rpm --dbpath "$WORK/rpmdb" -K "$rpm" | grep -q "signatures OK" + done + find "$out/release" -name '*.deb' | while read -r deb; do + debsigs --verify "$deb" >/dev/null + done + + echo "Checking that no temporary files are left" + if find "$out" -maxdepth 1 -name '.tmp-*' | grep -q .; then + echo "Temporary files left in $out" >&2 + exit 1 + fi + + echo "Checking that signing is reproducible" + new_output "$project" "$version" "$WORK/again-$project-$version" + release "$project" "$version" "$WORK/again-$project-$version" >/dev/null + diff -r "$out/release" "$WORK/again-$project-$version/release" +} + +test_repo() { + local version="$1" + local out="$WORK/out-community-$version" + + echo "== community $version repositories" + echo "Verifying the repository signatures" + find "$out/repo" -name '*.rpm' | while read -r rpm; do + rpm --dbpath "$WORK/rpmdb" -K "$rpm" | grep -q "signatures OK" + done + find "$out/repo" -name '*.deb' | while read -r deb; do + debsigs --verify "$deb" >/dev/null + done + local stable="$out/repo/apt/packages/dists/stable" + gpg --verify "$stable/Release.gpg" "$stable/Release" 2>/dev/null + gpg --verify "$stable/InRelease" 2>/dev/null + for repomd in "$out"/repo/yum/*/repodata/repomd.xml; do + gpg --verify "$repomd.asc" "$repomd" 2>/dev/null + done +} + +test_nightly() { + local out="$WORK/out-nightly" + + echo "== community master nightly" + new_output community master "$out" + # Any build will do, the version alone makes it a nightly + cfengine dev release --project community --version master \ + --build "$WORK/build-community-3.29.0" --output "$out" + + echo "Checking that nothing is copied" + if [ -e "$out/release" ]; then + echo "Nightly copied files to $out/release" >&2 + exit 1 + fi + + echo "Checking the release data" + python3 - "$out/release-data/community" <<'EOF' +import json, sys +from pathlib import Path + +directory = Path(sys.argv[1]) +document = json.loads((directory / "master.json").read_text()) +assert "nightly_release_date" in document +# Community master is in lts_branches, so it has no non-LTS note +assert "note" not in document +# Nightlies link to the build on buildcache +buildcache = "http://buildcache.cfengine.com/packages/build-in-container" +for artifacts in document["artifacts"].values(): + for artifact in artifacts: + assert artifact["URL"].startswith(f"{buildcache}/build-community-3.29.0/") + +releases = json.loads((directory / "releases.json").read_text())["releases"] +master = next(r for r in releases if r["version"] == "master") +assert master["debug"] is True +assert master["release_date"] == "nightly" +assert master["lts_branch"] == "nightly-master" +# Nightlies never become the latest release +assert next(r for r in releases if r.get("latest"))["version"] == "3.29.0" +EOF +} + +# A non-LTS minor release, the latest +test_release community 3.29.0 +test_repo 3.29.0 +test_release enterprise 3.29.0 +# An LTS patch release on an older branch, so not the latest +test_release community 3.27.3 +# Uses the community 3.29.0 build from above +test_nightly + +echo "All release end-to-end tests passed" diff --git a/tests/release/make_build.py b/tests/release/make_build.py new file mode 100644 index 00000000..667dcc89 --- /dev/null +++ b/tests/release/make_build.py @@ -0,0 +1,62 @@ +"""Generate a fake build-in-container output from a published release document. + +Usage: make_build.py DOCUMENT DEB RPM OUTPUT_DIR + +Every artifact becomes a file named as in its URL, in the directory the build +has it in. .deb and .rpm files are copies of DEB and RPM, small real packages, +so they can be signed. Other files are a few fake bytes. +""" + +import hashlib +import json +import sys +from pathlib import Path + + +def _build_dir(artifact: dict[str, str]) -> str: + """Return the build directory of an artifact.""" + title = artifact["Title"] + if title in ( + "Source code tarball", + "Masterfiles source tarball", + "Masterfiles ready-to-install tarball", + ): + return "tarballs" + if title == "Linux binary tarball (unsupported)": + return "PACKAGES_x86_64_linux_redhat_7" + if title == "Vagrant Environment": + return "vagrant" + return artifact["package"] + + +def _build_name(artifact: dict[str, str]) -> str: + """Return the file name in the build.""" + name = artifact["URL"].rsplit("/", 1)[-1] + if artifact["Title"] == "Source code tarball": + # Published as cfengine-community-3.29.0.tar.gz, built as cfengine-3.29.0.tar.gz + return name.replace("cfengine-community-", "cfengine-", 1) + return name + + +def main(document: str, deb: str, rpm: str, output_dir: str) -> None: + data = json.loads(Path(document).read_text()) + packages = {".deb": Path(deb).read_bytes(), ".rpm": Path(rpm).read_bytes()} + output = Path(output_dir) + for artifacts in data["artifacts"].values(): + for artifact in artifacts: + name = _build_name(artifact) + path = output / _build_dir(artifact) / name + path.parent.mkdir(parents=True, exist_ok=True) + content = packages.get(path.suffix, f"fake {name}\n".encode()) + _ = path.write_bytes(content) + + for directory in output.iterdir(): + lines = [ + f"{hashlib.sha256(path.read_bytes()).hexdigest()} {path.name}\n" + for path in sorted(directory.iterdir()) + ] + _ = (directory / "sha256sums.txt").write_text("".join(lines)) + + +if __name__ == "__main__": + main(*sys.argv[1:]) From 60dbedebab7459f59fcbb3fe57fc589debc4c6c9 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 27 Nov 2026 14:50:26 +0100 Subject: [PATCH 13/13] Added a README for the cfengine dev release commands Explains what the commands do, how to run them for feature and patch releases, how the nightlies run them, and what each file is responsible for. Ticket: ENT-14700 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- src/cfengine_cli/release/README.md | 186 +++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 src/cfengine_cli/release/README.md diff --git a/src/cfengine_cli/release/README.md b/src/cfengine_cli/release/README.md new file mode 100644 index 00000000..810d376c --- /dev/null +++ b/src/cfengine_cli/release/README.md @@ -0,0 +1,186 @@ +# Releasing CFEngine + +These commands release the packages built by `build-in-container`. +They replace the legacy `release.py` and `sync-packages-to-s3.sh` in the infra repo. +Older branches, like `3.24.x` and `3.27.x`, keep using the legacy scripts until they reach EOL. +Both scripts can coexist + +## The commands + +### `cfengine dev release` + +Releases a build. Works on local files only. + +1. Reads the build and verifies its `sha256sums.txt` files. +2. Plans every file to publish. +3. Copies the files to `release/`, and signs the packages. +4. Creates the release data: `release-data//.json`. + Appends the new version to `release-data//releases.json`. + +Signing is reproducible. The signature time is the build time of the package. + +### `cfengine dev update-repo` + +Adds a community release to the local copy of the APT and YUM repositories in `repo/` on buildcache. +It regenerates and signs the repository metadata. +It adds the copies in `release/`, signed by `cfengine dev release`, and refuses unsigned ones. + +### `cfengine dev publish` + +Uploads to S3: + +- `--bucket test` uploads the repositories to `cfengine-repotest`. +- `--bucket prod` uploads the release files, the repositories, and the release data to `cfengine-package-repos`. +- `--release-data-only` uploads only the release data, for nightlies. + Their release data links to the packages on buildcache itself, not on S3. + +`--bucket test` uploads less than `--bucket prod`, as only the repositories have a test bucket. +ENT-14959 will fix this asymmetry where everything will go to a staging bucket first. + +## Directories + +The output directory, `/var/www/buildcache` on buildcache, contains: + +- `release/`: the released files, as they are published on S3 +- `repo/`: the community APT and YUM repositories +- `release-data/`: the release data, read by the downloads page and cf-remote +- `.lock`: held while writing +- `.tmp-*`: temporary files while writing + +The build directory is a `build-in-container output`. +E.g. `/var/www/buildcache/packages/build-in-container/`. + +## Requirements + +- The `contact@northern.tech` gpg key, to sign the packages and repositories. +- `gpg`, `rpm`, `rpmsign`, `debsigs`, `apt-ftparchive`, `createrepo_c` and `aws`. +- AWS credentials for both buckets. + +## Making a release + +Community and enterprise are always released together. +Every command takes `--dry-run`, to see what it would do first. +It's safe to run a failed command again. + +### Feature release + +A feature release is one new version, e.g. `3.31.0`. + +1. Set the variables: + + ```bash + VERSION=3.31.0 # Change to the version you are releasing + BUILD=/var/www/buildcache/packages/build-in-container/ # Change to its build + OUTPUT=/var/www/buildcache + ``` + +2. Release both projects, and add the community release to the repositories: + + ```bash + cfengine dev release --project community --version $VERSION --build $BUILD --output $OUTPUT + cfengine dev release --project enterprise --version $VERSION --build $BUILD --output $OUTPUT + cfengine dev update-repo --version $VERSION --build $BUILD --output $OUTPUT + ``` + +3. Upload the repositories to the test bucket, and check that installing from + them works: + + ```bash + cfengine dev publish --output $OUTPUT --bucket test + ``` + +4. When the release is announced, upload everything to production: + + ```bash + cfengine dev publish --output $OUTPUT --bucket prod + ``` + +### Patch release + +A patch release is made on each supported LTS branch at the same time. +E.g. `3.33.1` and `3.30.4`. Each version has its own build. + +1. Set the variables: + + ```bash + A_VERSION=3.33.1 # Change to the version on one LTS branch + A_BUILD=/var/www/buildcache/packages/build-in-container/ # Change to its build + B_VERSION=3.30.4 # Change to the version on the other LTS branch + B_BUILD=/var/www/buildcache/packages/build-in-container/ # Change to its build + OUTPUT=/var/www/buildcache + ``` + +2. Release both projects of both versions, and add the community releases to the repositories: + + ```bash + cfengine dev release --project community --version $A_VERSION --build $A_BUILD --output $OUTPUT + cfengine dev release --project enterprise --version $A_VERSION --build $A_BUILD --output $OUTPUT + cfengine dev update-repo --version $A_VERSION --build $A_BUILD --output $OUTPUT + cfengine dev release --project community --version $B_VERSION --build $B_BUILD --output $OUTPUT + cfengine dev release --project enterprise --version $B_VERSION --build $B_BUILD --output $OUTPUT + cfengine dev update-repo --version $B_VERSION --build $B_BUILD --output $OUTPUT + ``` + +3. Upload the repositories to the test bucket, and check that installing from them works. + This uploads both versions at once: + + ```bash + cfengine dev publish --output $OUTPUT --bucket test + ``` + +4. When the release is announced, upload everything to production: + + ```bash + cfengine dev publish --output $OUTPUT --bucket prod + ``` + +Use legacy script in infra for versions older that `3.30`. + +## Nightlies + +When a nightly build finishes, Jenkins puts its output in `/home/jenkins/output/`. +The `sync.path` systemd unit on buildcache notices it and starts `sync.service`, which runs `sync.sh` from the infra repo. +It copies the build to `/var/www/buildcache/packages/`, and releases it with the branch as the version, e.g. `master` or `3.30.x`. + +For a community master nightly: + +```bash +cfengine dev release --project community --version master --build $BUILD --output /var/www/buildcache +cfengine dev publish --output /var/www/buildcache --bucket prod --release-data-only +``` + +A nightly copies and signs nothing. +Its release data links to the build on buildcache, so only the release data is uploaded. + +## Code + +The commands are added in `main.py` and dispatched in `dev.py`. +Each starts in the function of the same name, in the file of the same name: + +- `release`: `release()` in `release.py` +- `update-repo`: `update_repo()` in `update_repo.py` +- `publish`: `publish()` in `publish.py` + +The files in this directory: + +- `args.py`: the command line options. +- `build.py`: reads the `build-in-container` output directory into a `Build`, one `PackageDir` per platform label. +- `checksums.py`: verifies the build against its `sha256sums.txt` files, and hashes files. +- `platforms.py`: what a build label means. + E.g. that `PACKAGES_arm_64_linux_ubuntu_24` is "Ubuntu 24", aarch64, with its classexpr and release directory. + Also decides the order of packages on the downloads page. +- `plan.py`: plans every file to publish as a `PlannedFile`: + where it comes from, where it goes, its URL, and how it is shown in the release data. + Most release rules live here. +- `release.py`: the `release` command. Reads, plans, copies and writes the release data. +- `copy_files.py`: copies the planned files to `release/`, and signs packages. +- `metadata.py`: the release data formats, and the logic around versions: + titles, LTS branches, support dates, and the `latest` flags in `releases.json`. +- `release_data.py`: builds the release data from the plan, and reads and writes the JSON files. +- `update_repo.py`: the `update-repo` command. + Adds packages to the APT and YUM repositories, and regenerates and signs the repository metadata. +- `publish.py`: the `publish` command. Uploads the directories to S3 in a safe order. +- `utils.py`: shared helpers. + +The unit tests live in `tests/unit/test_release_.py`. +End-to-end tests live in `tests/release/`.