Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/deploy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ def __init__(

self._envs: list[tuple[str, str]] = [(e.name, e.dest) for e in config.envs]

self._check_scripts_exist()

def _check_scripts_exist(self) -> None:
for package in self.packages.values():
if not package.builder.is_file() or not os.access(package.builder, os.X_OK):
sys.exit(
f"Build script for package {package.config.name} ({package.builder.name}) wasn't found or it isn't executable"
)

def build(self) -> None:
self._build_packages()
self._build_envs()
Expand Down
49 changes: 49 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from deploy.build import Build
from deploy.config import Config
from pathlib import Path
Expand Down Expand Up @@ -56,6 +57,7 @@ def test_single_package(
tmp_path, base_config, config_update, script_content, expected_hash
):
(tmp_path / "build_A.sh").write_text(script_content)
(tmp_path / "build_A.sh").chmod(0o755)
base_config["builds"].append(
{
"name": "A",
Expand Down Expand Up @@ -107,7 +109,9 @@ def test_package_dependency(
expected_hash_B,
):
(tmp_path / "build_A.sh").write_text(script_content_A)
(tmp_path / "build_A.sh").chmod(0o755)
(tmp_path / "build_B.sh").write_text(script_content_B)
(tmp_path / "build_B.sh").chmod(0o755)
base_config["builds"] = [
{
"name": "A",
Expand All @@ -125,3 +129,48 @@ def test_package_dependency(
assert len(build.packages) == 2
assert build.packages["A"].buildhash == expected_hash_A
assert build.packages["B"].buildhash == expected_hash_B


def test_build_script_validity(
tmp_path,
base_config,
):
base_config["builds"] = [
{
"name": "A",
"version": "0.0",
"depends": [],
},
{
"name": "B",
"version": "0.0",
"depends": ["A"],
},
]
config = Config.model_validate(base_config)

# Test that if no files are present, the first package will error
with pytest.raises(
SystemExit,
match=re.escape(
"Build script for package A (build_A.sh) wasn't found or it isn't executable"
),
):
_ = Build(Path("/dummy"), config, extra_scripts=tmp_path, prefix=tmp_path)

# Test that if both files exist, but only the first one is executable, we'll
# error on the second
(tmp_path / "build_A.sh").write_text("")
(tmp_path / "build_A.sh").chmod(0o755)
(tmp_path / "build_B.sh").write_text("")
with pytest.raises(
SystemExit,
match=re.escape(
"Build script for package B (build_B.sh) wasn't found or it isn't executable"
),
):
_ = Build(Path("/dummy"), config, extra_scripts=tmp_path, prefix=tmp_path)

# Check that the correct configuration is correct
(tmp_path / "build_B.sh").chmod(0o755)
Build(Path("/dummy"), config, extra_scripts=tmp_path, prefix=tmp_path)