Skip to content

Commit

Permalink
fix(src/image/prepare_single_image_build_matrix.py): release identifi…
Browse files Browse the repository at this point in the history
…cation
  • Loading branch information
clay-lake committed Dec 10, 2024
1 parent fa1fa37 commit 1f06b73
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/image/prepare_single_image_build_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def main():
# so let's remove this field since we don't need it for the builds
del build["release"]

release_to = "true" if "release" in image_trigger else ""
release_to = "true" if builds else ""

write_github_output(release_to, builds, args.revision_data_dir)

Expand Down
45 changes: 45 additions & 0 deletions tests/data/image_all_eol_tracks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: 1

release:
latest:
end-of-life: "2030-05-01T00:00:00Z"
candidate: 1.2-22.04_beta
test:
end-of-life: "2030-05-01T00:00:00Z"
beta: 1.1-22.04_beta

upload:
- source: "canonical/rocks-toolbox"
commit: 17916dd5de270e61a6a3fd3f4661a6413a50fd6f
directory: mock_rock/1.0
release:
1.0-22.04:
end-of-life: "2000-05-01T00:00:00Z"
risks:
- candidate
- edge
- beta
- source: "canonical/rocks-toolbox"
commit: 17916dd5de270e61a6a3fd3f4661a6413a50fd6f
directory: mock_rock/1.1
release:
1.1-22.04:
end-of-life: "2000-05-01T00:00:00Z"
risks:
- candidate
- edge
- beta
1-22.04:
end-of-life: "2000-05-01T00:00:00Z"
risks:
- candidate
- edge
- beta
- source: "canonical/rocks-toolbox"
commit: 17916dd5de270e61a6a3fd3f4661a6413a50fd6f
directory: mock_rock/1.2
release:
1.2-22.04:
end-of-life: "2000-05-01T00:00:00Z"
risks:
- beta
45 changes: 45 additions & 0 deletions tests/data/image_with_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: 1

release:
latest:
end-of-life: "2030-05-01T00:00:00Z"
candidate: 1.2-22.04_beta
test:
end-of-life: "2030-05-01T00:00:00Z"
beta: 1.1-22.04_beta

upload:
- source: "canonical/rocks-toolbox"
commit: 17916dd5de270e61a6a3fd3f4661a6413a50fd6f
directory: mock_rock/1.0
release:
1.0-22.04:
end-of-life: "2024-05-01T00:00:00Z"
risks:
- candidate
- edge
- beta
- source: "canonical/rocks-toolbox"
commit: 17916dd5de270e61a6a3fd3f4661a6413a50fd6f
directory: mock_rock/1.1
release:
1.1-22.04:
end-of-life: "2030-05-01T00:00:00Z"
risks:
- candidate
- edge
- beta
1-22.04:
end-of-life: "2030-05-01T00:00:00Z"
risks:
- candidate
- edge
- beta
- source: "canonical/rocks-toolbox"
commit: 17916dd5de270e61a6a3fd3f4661a6413a50fd6f
directory: mock_rock/1.2
release:
1.2-22.04:
end-of-life: "2030-05-01T00:00:00Z"
risks:
- beta
37 changes: 37 additions & 0 deletions tests/data/image_without_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 1

upload:
- source: "canonical/rocks-toolbox"
commit: 17916dd5de270e61a6a3fd3f4661a6413a50fd6f
directory: mock_rock/1.0
release:
1.0-22.04:
end-of-life: "2024-05-01T00:00:00Z"
risks:
- candidate
- edge
- beta
- source: "canonical/rocks-toolbox"
commit: 17916dd5de270e61a6a3fd3f4661a6413a50fd6f
directory: mock_rock/1.1
release:
1.1-22.04:
end-of-life: "2030-05-01T00:00:00Z"
risks:
- candidate
- edge
- beta
1-22.04:
end-of-life: "2030-05-01T00:00:00Z"
risks:
- candidate
- edge
- beta
- source: "canonical/rocks-toolbox"
commit: 17916dd5de270e61a6a3fd3f4661a6413a50fd6f
directory: mock_rock/1.2
release:
1.2-22.04:
end-of-life: "2030-05-01T00:00:00Z"
risks:
- beta
66 changes: 66 additions & 0 deletions tests/integration/test_prepare_single_image_build_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# from pathlib import Path
# import pytest

# from src.image.utils.schema.triggers import ImageTriggerValidationError
# import yaml
# from glob import glob
from src.image.prepare_single_image_build_matrix import main as prepare_build_matrix
import pytest
import re
import shutil
import sys

from .. import DATA_DIR


@pytest.fixture
def prep_execution(tmpdir, monkeypatch, request):

image_trigger_sample = getattr(request, "param", None)

# configure files/env requried for the test
github_output = tmpdir / "github_output"
monkeypatch.setenv("GITHUB_OUTPUT", str(github_output))

revision_data_dir = tmpdir / "revision-data"
revision_data_dir.mkdir()

oci_trigger_dir = tmpdir / "image_trigger"
oci_trigger_dir.mkdir()
shutil.copy(
image_trigger_sample,
oci_trigger_dir / "image.yaml",
)

# patch the arv for the test. script.py can be anything
args = (
f"--oci-path {oci_trigger_dir} --revision-data-dir {revision_data_dir}".split(
" "
)
)
monkeypatch.setattr(sys, "argv", ["script.py"] + args)

return revision_data_dir, github_output


@pytest.mark.parametrize(
"prep_execution, release_to",
[
(DATA_DIR / "image_with_release.yaml", True),
(DATA_DIR / "image_without_release.yaml", True),
(DATA_DIR / "image_all_eol_tracks.yaml", False),
],
indirect=["prep_execution"],
)
def test_release_to(prep_execution, release_to):
"""Test state of release-to in github output after running prepare_single_image_build_matrix"""
_, github_output = prep_execution

# run main from prepare_single_image_build_matrix
prepare_build_matrix()

github_output_content = github_output.read_text("utf8")
print(github_output_content)
assert re.search(
"^release-to=" + "true" if release_to else "", github_output_content, re.M
), "Invalid release-to value"

0 comments on commit 1f06b73

Please sign in to comment.