From 8c1bfaef3d01d7cdf0b005ddcc9387e9ef7f3c5b Mon Sep 17 00:00:00 2001 From: Philipp Herzog Date: Thu, 1 Feb 2024 17:04:36 +0100 Subject: [PATCH] feat: versions.py: allow multiple environments per branch some deployments have a multitude of environments that might share the same branch. previously, this would break our semi-established gitlab pipeline's version update step and thereby the entire ci --- ..._170638_ph_multiple_environments_per_branch.md | 1 + src/batou_ext/versions.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 CHANGES.d/20240201_170638_ph_multiple_environments_per_branch.md diff --git a/CHANGES.d/20240201_170638_ph_multiple_environments_per_branch.md b/CHANGES.d/20240201_170638_ph_multiple_environments_per_branch.md new file mode 100644 index 0000000..964cc33 --- /dev/null +++ b/CHANGES.d/20240201_170638_ph_multiple_environments_per_branch.md @@ -0,0 +1 @@ +- Change the behaviour of the batou_ext.versions updater to allow environments to share a branch diff --git a/src/batou_ext/versions.py b/src/batou_ext/versions.py index 1d5b04f..d23b94e 100644 --- a/src/batou_ext/versions.py +++ b/src/batou_ext/versions.py @@ -47,18 +47,16 @@ def environment(self): self._environment.load() return self._environment - def set_environment_from_branch(self, branch): + def update_from_branch(self, branch: str): envs = sorted(os.listdir(os.path.join(self.basedir, "environments"))) for env_name in envs: env = batou.environment.Environment(env_name) env.load() if env.branch == branch: - if self.environment_name: - raise ValueError( - f"Branch {branch} is used in multiple enviornments, " - "cannot auto-update." - ) + print(f"Updating environment: {env_name}") self.environment_name = env_name + self.set_versions() + if not self.environment_name: raise ValueError( f"Branch {branch} is not used in any environment, " @@ -157,11 +155,12 @@ def main(): if args.environment: update.environment_name = args.environment + update.set_versions() elif args.branch: - update.set_environment_from_branch(args.branch) + update.update_from_branch(args.branch) else: update.interactive() - update.set_versions() + update.set_versions() if __name__ == "__main__":