Probe the RPM filename nfpm actually publishes (#175)
ci/woodpecker/push/deploy-fedora43 Pipeline was successful
ci/woodpecker/push/deploy-fedora44 Pipeline was successful
ci/woodpecker/push/deploy-fedora42 Pipeline was successful
ci/woodpecker/push/deploy-almalinux8 Pipeline was successful
ci/woodpecker/push/deploy-almalinux9 Pipeline was successful
ci/woodpecker/push/deploy-fedora43 Pipeline was successful
ci/woodpecker/push/deploy-fedora44 Pipeline was successful
ci/woodpecker/push/deploy-fedora42 Pipeline was successful
ci/woodpecker/push/deploy-almalinux8 Pipeline was successful
ci/woodpecker/push/deploy-almalinux9 Pipeline was successful
nfpm re-renders semver versions into the RPM filename, so `2025.08.03` ships as `2025.8.3`. The existence probe asked artifactapi for the raw metadata version, always got a 404, and rebuilt and republished `nzbget_exporter` and `unkin-ca-certificates` on every pipeline run. - add `nfpm_rpm_version`/`rpm_file_name` mirroring nfpm rendering - build the probe filename through `rpm_file_name` - drop dead `normalize_version` and `get_package_full_name` - cover the nfpm rendering table and the probed URL in tests Reviewed-on: #175 Co-authored-by: unkin-agent <unkin-agent@unkin.net> Co-committed-by: unkin-agent <unkin-agent@unkin.net>
This commit was merged in pull request #175.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
"""Tests for the RPM filename tools/build reconstructs when probing artifactapi.
|
||||
|
||||
The expected values below were captured from the real nfpm; they are the names
|
||||
the publish step actually uploads, so the existence probe has to ask for
|
||||
exactly these or it 404s and rebuilds forever.
|
||||
"""
|
||||
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
REPO_ROOT = Path(__file__).parent.parent
|
||||
|
||||
_loader = importlib.machinery.SourceFileLoader(
|
||||
"rpmbuilder_build", str(REPO_ROOT / "tools" / "build")
|
||||
)
|
||||
_spec = importlib.util.spec_from_loader(_loader.name, _loader)
|
||||
build = importlib.util.module_from_spec(_spec)
|
||||
_loader.exec_module(build)
|
||||
|
||||
|
||||
# nfpm output for `version: <input>` with release 1, arch amd64
|
||||
NFPM_VERSIONS = [
|
||||
("2025.08.03", "2025.8.3"),
|
||||
("2025.07.13", "2025.7.13"),
|
||||
("1.05.0", "1.5.0"),
|
||||
("10.02.01", "10.2.1"),
|
||||
("0.0.09", "0.0.9"),
|
||||
("0.6.1", "0.6.1"),
|
||||
("1.2.3", "1.2.3"),
|
||||
("1.05", "1.5.0"),
|
||||
("08", "8.0.0"),
|
||||
("1.0.0-rc1", "1.0.0~rc1"),
|
||||
("1.05.0-rc1", "1.5.0~rc1"),
|
||||
("1.0.0-rc.1", "1.0.0~rc.1"),
|
||||
# not semver: nfpm leaves these verbatim, so we must too
|
||||
("1.02.3.4", "1.02.3.4"),
|
||||
("2025.08.03.01", "2025.08.03.01"),
|
||||
("1.2.3.4", "1.2.3.4"),
|
||||
("1.0.0-rc.01", "1.0.0-rc.01"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("version,expected", NFPM_VERSIONS)
|
||||
def test_nfpm_rpm_version(version, expected):
|
||||
assert build.nfpm_rpm_version(version) == expected
|
||||
|
||||
|
||||
def test_rpm_file_name_matches_nfpm_output():
|
||||
assert (
|
||||
build.rpm_file_name("nzbget_exporter", "2025.08.03", "1.el9", "amd64")
|
||||
== "nzbget_exporter-2025.8.3-1.el9.x86_64.rpm"
|
||||
)
|
||||
|
||||
|
||||
def test_check_package_exists_probes_published_filename(monkeypatch):
|
||||
"""A zero-padded version must not probe a filename nfpm can never produce."""
|
||||
probed = []
|
||||
|
||||
class _Session:
|
||||
def get(self, url, timeout=None):
|
||||
probed.append(url)
|
||||
return type("R", (), {"status_code": 404})()
|
||||
|
||||
monkeypatch.setattr(build, "_artifactapi_session", _Session())
|
||||
|
||||
assert not build.check_package_exists(
|
||||
"nzbget_exporter", "2025.08.03", "1.el9", "almalinux/el9", "amd64"
|
||||
)
|
||||
expected = (
|
||||
"https://artifactapi.k8s.syd1.au.unkin.net/api/v2/remotes/rpm-vendor-el9"
|
||||
"/files/Packages/nzbget_exporter-2025.8.3-1.el9.x86_64.rpm"
|
||||
)
|
||||
assert probed == [expected]
|
||||
Reference in New Issue
Block a user