-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_release_workflows.py
More file actions
75 lines (59 loc) · 2.09 KB
/
Copy pathtest_release_workflows.py
File metadata and controls
75 lines (59 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Regression tests for release workflow packaging contracts."""
from __future__ import annotations
import os
import subprocess
from pathlib import Path
import yaml
REPO_ROOT = Path(__file__).resolve().parents[1]
BINARIES_WORKFLOW = REPO_ROOT / ".github" / "workflows" / "binaries.yml"
def _nfpm_step() -> dict:
workflow = yaml.safe_load(BINARIES_WORKFLOW.read_text())
return next(
step
for step in workflow["jobs"]["nfpm"]["steps"]
if step.get("name") == "Build .deb and .rpm"
)
def test_nfpm_workflow_uses_distinct_package_filenames():
step = _nfpm_step()
script = step["run"]
assert "mkdir -p dist release" in script
assert 'release/capacium_${VERSION}.deb' in script
assert 'release/capacium_${VERSION}.rpm' in script
assert step["env"]["RELEASE_TAG"] == "${{ github.ref_name }}"
workflow = yaml.safe_load(BINARIES_WORKFLOW.read_text())
upload = next(
candidate
for candidate in workflow["jobs"]["nfpm"]["steps"]
if candidate.get("name") == "Upload .deb and .rpm"
)
assert upload["with"]["files"].splitlines() == [
"release/capacium_*.deb",
"release/capacium_*.rpm",
]
def test_nfpm_step_fixture_produces_deb_and_rpm(tmp_path):
step = _nfpm_step()
binary = tmp_path / "cap-Linux-X64" / "cap"
binary.parent.mkdir(parents=True)
binary.write_text("fixture")
fake_nfpm = tmp_path / "nfpm"
fake_nfpm.write_text(
"#!/usr/bin/env python3\n"
"import pathlib, sys\n"
"target = sys.argv[sys.argv.index('--target') + 1]\n"
"path = pathlib.Path(target)\n"
"path.parent.mkdir(parents=True, exist_ok=True)\n"
"path.write_text('fixture package')\n"
)
fake_nfpm.chmod(0o755)
env = {
"PATH": os.environ["PATH"],
"RELEASE_TAG": "v0.16.0",
}
subprocess.run(
["bash", "-euo", "pipefail", "-c", step["run"]],
cwd=tmp_path,
env=env,
check=True,
)
assert (tmp_path / "release" / "capacium_0.16.0.deb").is_file()
assert (tmp_path / "release" / "capacium_0.16.0.rpm").is_file()