diff --git a/scripts/release/build/build_scenario.py b/scripts/release/build/build_scenario.py index 2fb27e173..5997e2cbe 100644 --- a/scripts/release/build/build_scenario.py +++ b/scripts/release/build/build_scenario.py @@ -3,7 +3,8 @@ from git import Repo from lib.base_logger import logger -from scripts.release.constants import triggered_by_git_tag, is_evg_patch, is_running_in_evg, get_version_id +from scripts.release.constants import triggered_by_git_tag, is_evg_patch, is_running_in_evg, get_version_id, \ + DEFAULT_REPOSITORY_PATH from scripts.release.version import calculate_next_version COMMIT_SHA_LENGTH = 8 @@ -17,7 +18,7 @@ class BuildScenario(StrEnum): DEVELOPMENT = "development" # Local build on a developer machine @classmethod - def infer_scenario_from_environment(cls) -> "BuildScenario": + def infer_scenario_from_environment(cls, repository_path: str = DEFAULT_REPOSITORY_PATH) -> "BuildScenario": """Infer the build scenario from environment variables.""" git_tag = triggered_by_git_tag() is_patch = is_evg_patch() @@ -28,13 +29,12 @@ def infer_scenario_from_environment(cls) -> "BuildScenario": # Release scenario and the git tag will be used for promotion process only scenario = BuildScenario.RELEASE logger.info(f"Build scenario: {scenario} (git_tag: {git_tag})") + elif is_evg and not is_patch: + scenario = BuildScenario.STAGING + logger.info(f"Build scenario: {scenario} (version_id: {get_staging_version_id(repository_path)}") elif is_patch or is_evg: scenario = BuildScenario.PATCH logger.info(f"Build scenario: {scenario} (patch_id: {patch_id})") - # TODO: Uncomment the following lines when starting to work on staging builds - # elif is_evg: - # scenario = BuildScenario.STAGING - # logger.info(f"Build scenario: {scenario} (patch_id: {patch_id})") else: scenario = BuildScenario.DEVELOPMENT logger.info(f"Build scenario: {scenario}") @@ -56,7 +56,7 @@ def get_version(self, repository_path: str, changelog_sub_path: str, initial_com raise ValueError(f"version_id environment variable is not set for `{self}` build scenario") return patch_id case BuildScenario.STAGING: - return repo.head.object.hexsha[:COMMIT_SHA_LENGTH] + return get_staging_version_id(repository_path) case BuildScenario.RELEASE: return calculate_next_version(repo, changelog_sub_path, initial_commit_sha, initial_version) case BuildScenario.MANUAL_RELEASE: @@ -65,3 +65,8 @@ def get_version(self, repository_path: str, changelog_sub_path: str, initial_com return None raise ValueError(f"Unknown build scenario: {self}") + + +def get_staging_version_id(repository_path: str): + repo = Repo(repository_path) + return repo.head.object.hexsha[:COMMIT_SHA_LENGTH]