Skip to content

Commit 034fe03

Browse files
ci: provide mechanism to override ancestor release
1 parent 90621af commit 034fe03

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

misc/python/materialize/docker.py

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
from materialize import buildkite, git
1414
from materialize.mz_version import MzVersion
1515

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+
1625

1726
def resolve_ancestor_image_tag() -> str:
1827
image_tag, context = _resolve_ancestor_image_tag()
@@ -53,9 +62,21 @@ def _resolve_ancestor_image_tag_when_in_buildkite() -> tuple[str, str]:
5362
f"previous release because on release branch {tagged_release_version}",
5463
)
5564
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+
5677
# return the latest release
5778
return (
58-
_version_to_image_tag(get_latest_published_version()),
79+
_version_to_image_tag(latest_published_version),
5980
"latest release because not in a pull request and not on a release branch",
6081
)
6182

@@ -74,8 +95,20 @@ def _resolve_ancestor_image_tag_when_running_locally() -> tuple[str, str]:
7495
)
7596
elif git.is_on_main_branch():
7697
# 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+
77110
return (
78-
_version_to_image_tag(get_latest_published_version()),
111+
_version_to_image_tag(latest_published_version),
79112
"latest release because on local main branch",
80113
)
81114
else:
@@ -125,6 +158,29 @@ def get_previous_published_version(release_version: MzVersion) -> MzVersion:
125158
excluded_versions.add(previous_published_version)
126159

127160

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+
128184
def _image_of_release_version_exists(version: MzVersion) -> bool:
129185
return _mz_image_tag_exists(_version_to_image_tag(version))
130186

0 commit comments

Comments
 (0)