Improve configurability and detection of supported branches
This commit is contained in:
parent
f6a6c9575f
commit
b56983195d
5 changed files with 49 additions and 15 deletions
|
|
@ -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"}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
24
tests/test_build_images.py
Normal file
24
tests/test_build_images.py
Normal file
|
|
@ -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")
|
||||
Loading…
Reference in a new issue