Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions tests/test_cookiecutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,31 @@ def test_default_project(cookies):
pytest.fail("Something went wrong with the project's post-generation hook")

try:
# Build all supported architectures to ensure it succeeds; we cannot test it because multi-platform builds can't be loaded into the docker daemon, but
# we will load and test the same-platform image later
env = os.environ.copy()
env.pop("VIRTUAL_ENV", None) # Clean VIRTUAL_ENV to avoid conflicts
env["PLATFORM"] = "all"

# Bootstrap the project and run the simplest checks first to optimize for a fast feedback loop
subprocess.run(
[
"task",
"-v",
"init",
"lint",
"validate",
"build",
"sbom",
"vulnscan",
],
capture_output=True,
check=True,
cwd=project,
env=env,
)

# Build and test each supported architecture individually (should be mostly cached)
# Ensure the project.yml is generated, and is valid YAML
config_path = project / ".github" / "project.yml"
with config_path.open(encoding="utf-8") as yaml_data:
project_context = yaml.safe_load(yaml_data)
assert project_context["origin"]["generated"]

# Build and test each supported architecture individually
for platform in ("linux/arm64", "linux/amd64"):
env["PLATFORM"] = platform
subprocess.run(
Expand Down Expand Up @@ -264,11 +266,24 @@ def test_default_project(cookies):
f"Unexpected exit code when running {command}; expected {expected_exit}, received {process.returncode}"
)

# Ensure the project.yml is generated, and is valid YAML
config_path = project / ".github" / "project.yml"
with config_path.open(encoding="utf-8") as yaml_data:
project_context = yaml.safe_load(yaml_data)
assert project_context["origin"]["generated"]
# Clean the repo, perform a multi-platform build, and then run the sbom and vulnscan task to ensure it all works
# We cannot functionally test a multi-platform image without pushing it to a registry and then pulling it back down because they can't directly be
# loaded into the docker daemon
env["PLATFORM"] = "all"
subprocess.run(
[
"task",
"-v",
"clean",
"build",
"sbom",
"vulnscan",
],
capture_output=True,
check=True,
cwd=project,
env=env,
)
except subprocess.CalledProcessError as error:
print(f"\n=== STDOUT ===\n{error.stdout.decode('utf-8')}")
print(f"\n=== STDERR ===\n{error.stderr.decode('utf-8')}")
Expand Down
Loading