diff --git a/.env.test b/.env.test index ad24921..26254ec 100644 --- a/.env.test +++ b/.env.test @@ -11,3 +11,4 @@ RUNBOAT_BUILD_DOMAIN=runboat.odoo-community.org RUNBOAT_BUILD_ENV={} RUNBOAT_GITHUB_TOKEN= RUNBOAT_LOG_CONFIG=log-config.yaml +RUNBOAT_BIULD_IMAGES={"15.0": "ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest"} diff --git a/README.md b/README.md index e37912c..e3e1a62 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,6 @@ More: - handle branch delete (delete all builds for branch) - create builds for all supported repos on startup (goes with sticky branches) - never undeploy last build of sticky branches -- make build images configurable (see `build_images.py`) - configurable kubefiles directory - even more tests diff --git a/src/runboat/build_images.py b/src/runboat/build_images.py index f9f628f..54effca 100644 --- a/src/runboat/build_images.py +++ b/src/runboat/build_images.py @@ -1,21 +1,12 @@ import re from .exceptions import BranchNotSupported - -images = { - "15.0": "ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest", - "14.0": "ghcr.io/oca/oca-ci/py3.6-odoo14.0:latest", - "13.0": "ghcr.io/oca/oca-ci/py3.6-odoo13.0:latest", - "12.0": "ghcr.io/oca/oca-ci/py3.6-odoo12.0:latest", - "11.0": "ghcr.io/oca/oca-ci/py3.5-odoo11.0:latest", - "10.0": "ghcr.io/oca/oca-ci/py2.7-odoo10.0:latest", -} - +from .settings import settings TARGET_BRANCH_RE = re.compile(r"^(\d+\.\d+)") -def get_target_branch(branch_name: str) -> str: +def get_main_branch(branch_name: str) -> str: mo = TARGET_BRANCH_RE.match(branch_name) if not mo: raise BranchNotSupported( @@ -23,15 +14,26 @@ def get_target_branch(branch_name: str) -> str: f"(it should start with an Odoo branch name)." ) key = mo.group(1) - if key not in images: + if key not in settings.build_images: raise BranchNotSupported( f"No build image configured for {key} (from {branch_name})." ) return key -check_branch_supported = get_target_branch +def is_branch_supported(branch_name: str) -> bool: + try: + return bool(get_main_branch(branch_name)) + except BranchNotSupported: + return False + + +def is_main_branch(branch_name: str) -> bool: + try: + return branch_name == get_main_branch(branch_name) + except BranchNotSupported: + return False def get_build_image(branch_name: str) -> str: - return images[get_target_branch(branch_name)] + return settings.build_images[get_main_branch(branch_name)] diff --git a/src/runboat/settings.py b/src/runboat/settings.py index 0439a37..0b93f76 100644 --- a/src/runboat/settings.py +++ b/src/runboat/settings.py @@ -18,6 +18,14 @@ class Settings(BaseSettings): build_admin_passwd: str build_domain: str build_env: Optional[dict[str, str]] + build_images: dict[str, str] = { + "15.0": "ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest", + "14.0": "ghcr.io/oca/oca-ci/py3.6-odoo14.0:latest", + "13.0": "ghcr.io/oca/oca-ci/py3.6-odoo13.0:latest", + "12.0": "ghcr.io/oca/oca-ci/py3.6-odoo12.0:latest", + "11.0": "ghcr.io/oca/oca-ci/py3.5-odoo11.0:latest", + "10.0": "ghcr.io/oca/oca-ci/py2.7-odoo10.0:latest", + } github_token: Optional[str] log_config: Optional[str] diff --git a/tests/test_build_images.py b/tests/test_build_images.py new file mode 100644 index 0000000..debf669 --- /dev/null +++ b/tests/test_build_images.py @@ -0,0 +1,24 @@ +import pytest + +from runboat.build_images import get_build_image, get_main_branch, is_branch_supported +from runboat.exceptions import BranchNotSupported + + +def test_get_main_branch(): + assert get_main_branch("15.0") == "15.0" + assert get_main_branch("15.0-ocabot-merge") == "15.0" + with pytest.raises(BranchNotSupported): + get_main_branch("8.0") + + +def test_is_branch_supported(): + assert is_branch_supported("15.0") + assert is_branch_supported("15.0-ocabot-merge") + assert not is_branch_supported("8.0") + + +def test_get_build_image(): + assert get_build_image("15.0") == "ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest" + assert get_build_image("15.0-zzz") == "ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest" + with pytest.raises(BranchNotSupported): + get_build_image("8.0")