From 5e7919eaf4dad53c0c4b6862a1e1caf6eba4a52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Wed, 24 Nov 2021 23:32:25 +0100 Subject: [PATCH] Validate build settings at startup time --- src/runboat/models.py | 4 ---- src/runboat/settings.py | 11 +++++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/runboat/models.py b/src/runboat/models.py index 6fa36b4..6bc8aed 100644 --- a/src/runboat/models.py +++ b/src/runboat/models.py @@ -182,10 +182,6 @@ class Build(BaseModel): build_settings = settings.get_build_settings( commit_info.repo, commit_info.target_branch ) - if len(build_settings) > 1: - raise NotImplementedError( - "Having more than one build per commit is not supported yet." - ) deployment_vars = k8s.make_deployment_vars( k8s.DeploymentMode.deployment, name, diff --git a/src/runboat/settings.py b/src/runboat/settings.py index 0837ffb..953b8ce 100644 --- a/src/runboat/settings.py +++ b/src/runboat/settings.py @@ -1,8 +1,7 @@ import re from typing import Optional -from pydantic import BaseSettings -from pydantic.main import BaseModel +from pydantic import BaseModel, BaseSettings, validator from .exceptions import RepoOrBranchNotSupported @@ -16,6 +15,14 @@ class RepoSettings(BaseModel): branch: str # regex builds: list[BuildSettings] + @validator("builds") + def validate_builds(cls, v: list[BuildSettings]) -> list[BuildSettings]: + if len(v) != 1: + raise ValueError( + "One and only one build settings is allowed per repo/branch entry." + ) + return v + class Settings(BaseSettings): # Configuration for supported repositories and branches.