3
3
from git import Repo
4
4
5
5
from lib .base_logger import logger
6
- from scripts .release .constants import triggered_by_git_tag , is_evg_patch , is_running_in_evg , get_version_id
6
+ from scripts .release .constants import triggered_by_git_tag , is_evg_patch , is_running_in_evg , get_version_id , \
7
+ DEFAULT_REPOSITORY_PATH
7
8
from scripts .release .version import calculate_next_version
8
9
9
10
COMMIT_SHA_LENGTH = 8
@@ -17,7 +18,7 @@ class BuildScenario(StrEnum):
17
18
DEVELOPMENT = "development" # Local build on a developer machine
18
19
19
20
@classmethod
20
- def infer_scenario_from_environment (cls ) -> "BuildScenario" :
21
+ def infer_scenario_from_environment (cls , repository_path : str = DEFAULT_REPOSITORY_PATH ) -> "BuildScenario" :
21
22
"""Infer the build scenario from environment variables."""
22
23
git_tag = triggered_by_git_tag ()
23
24
is_patch = is_evg_patch ()
@@ -31,9 +32,9 @@ def infer_scenario_from_environment(cls) -> "BuildScenario":
31
32
elif is_patch or is_evg :
32
33
scenario = BuildScenario .PATCH
33
34
logger .info (f"Build scenario: { scenario } (patch_id: { patch_id } )" )
34
- elif is_evg :
35
+ elif is_evg and not is_patch :
35
36
scenario = BuildScenario .STAGING
36
- logger .info (f"Build scenario: { scenario } (patch_id : { patch_id } ) " )
37
+ logger .info (f"Build scenario: { scenario } (version_id : { get_staging_version_id ( repository_path ) } " )
37
38
else :
38
39
scenario = BuildScenario .DEVELOPMENT
39
40
logger .info (f"Build scenario: { scenario } " )
@@ -55,7 +56,7 @@ def get_version(self, repository_path: str, changelog_sub_path: str, initial_com
55
56
raise ValueError (f"version_id environment variable is not set for `{ self } ` build scenario" )
56
57
return patch_id
57
58
case BuildScenario .STAGING :
58
- return repo . head . object . hexsha [: COMMIT_SHA_LENGTH ]
59
+ return get_staging_version_id ( repository_path )
59
60
case BuildScenario .RELEASE :
60
61
return calculate_next_version (repo , changelog_sub_path , initial_commit_sha , initial_version )
61
62
case BuildScenario .MANUAL_RELEASE :
@@ -64,3 +65,8 @@ def get_version(self, repository_path: str, changelog_sub_path: str, initial_com
64
65
return None
65
66
66
67
raise ValueError (f"Unknown build scenario: { self } " )
68
+
69
+
70
+ def get_staging_version_id (repository_path : str ):
71
+ repo = Repo (repository_path )
72
+ return repo .head .object .hexsha [:COMMIT_SHA_LENGTH ]
0 commit comments