13
13
from materialize import buildkite , git
14
14
from materialize .mz_version import MzVersion
15
15
16
+ """
17
+ Git revisions that are based on commits listed as keys require at least the version specified in the value.
18
+ Note that specified versions do not necessarily need to be already published.
19
+ Commits must be ordered descending by their date.
20
+ """
21
+ MIN_ANCESTOR_MZ_VERSION_PER_COMMIT : dict [str , MzVersion ] = {
22
+ # insert newer commits at the top
23
+ }
24
+
16
25
17
26
def resolve_ancestor_image_tag () -> str :
18
27
image_tag , context = _resolve_ancestor_image_tag ()
@@ -53,9 +62,21 @@ def _resolve_ancestor_image_tag_when_in_buildkite() -> tuple[str, str]:
53
62
f"previous release because on release branch { tagged_release_version } " ,
54
63
)
55
64
else :
65
+ latest_published_version = get_latest_published_version ()
66
+ override_commit = _get_override_commit_instead_of_version (
67
+ latest_published_version
68
+ )
69
+
70
+ if override_commit is not None :
71
+ # use the commit instead of the latest release
72
+ return (
73
+ _commit_to_image_tag (override_commit ),
74
+ f"commit override instead of latest release ({ latest_published_version } )" ,
75
+ )
76
+
56
77
# return the latest release
57
78
return (
58
- _version_to_image_tag (get_latest_published_version () ),
79
+ _version_to_image_tag (latest_published_version ),
59
80
"latest release because not in a pull request and not on a release branch" ,
60
81
)
61
82
@@ -74,8 +95,20 @@ def _resolve_ancestor_image_tag_when_running_locally() -> tuple[str, str]:
74
95
)
75
96
elif git .is_on_main_branch ():
76
97
# return the latest release
98
+ latest_published_version = get_latest_published_version ()
99
+ override_commit = _get_override_commit_instead_of_version (
100
+ latest_published_version
101
+ )
102
+
103
+ if override_commit is not None :
104
+ # use the commit instead of the latest release
105
+ return (
106
+ _commit_to_image_tag (override_commit ),
107
+ f"commit override instead of latest release ({ latest_published_version } )" ,
108
+ )
109
+
77
110
return (
78
- _version_to_image_tag (get_latest_published_version () ),
111
+ _version_to_image_tag (latest_published_version ),
79
112
"latest release because on local main branch" ,
80
113
)
81
114
else :
@@ -125,6 +158,29 @@ def get_previous_published_version(release_version: MzVersion) -> MzVersion:
125
158
excluded_versions .add (previous_published_version )
126
159
127
160
161
+ def _get_override_commit_instead_of_version (
162
+ latest_published_version : MzVersion ,
163
+ ) -> str | None :
164
+ """
165
+ If a commit specifies a mz version as prerequisite (to avoid regressions) that is newer than the
166
+ provided latest version (i.e., prerequisite not satisfied by the latest version), then return
167
+ that commit's hash if the commit contained in the current state.
168
+ Otherwise, return none.
169
+ """
170
+ for (
171
+ commit_hash ,
172
+ min_required_mz_version ,
173
+ ) in MIN_ANCESTOR_MZ_VERSION_PER_COMMIT .items ():
174
+ if latest_published_version >= min_required_mz_version :
175
+ continue
176
+
177
+ if git .contains_commit (commit_hash ):
178
+ # commit would require at least min_required_mz_version
179
+ return commit_hash
180
+
181
+ return None
182
+
183
+
128
184
def _image_of_release_version_exists (version : MzVersion ) -> bool :
129
185
return _mz_image_tag_exists (_version_to_image_tag (version ))
130
186
0 commit comments