Skip to content

Commit

Permalink
Use git ancestry to find proper parent release
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleChimera committed Jul 3, 2024
1 parent bc0c8b1 commit cf6ba28
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 7 deletions.
2 changes: 1 addition & 1 deletion release-controller/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@python_deps//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@//tools/python:py_oci_image.bzl", "py_oci_image")

deps = [
Expand Down
14 changes: 14 additions & 0 deletions release-controller/git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ def fetch(self):
cwd=self.dir,
)

def is_ancestor(self, maybe_ancestor_commit: str, descendant_commit: str) -> bool:
return 0 == subprocess.check_call(
[
"git",
"merge-base",
"--is-ancestor",
maybe_ancestor_commit,
descendant_commit,
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
cwd=self.dir,
)


# TODO: test
def push_release_tags(repo: GitRepo, release: Release):
Expand Down
24 changes: 19 additions & 5 deletions release-controller/reconciler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import time
import traceback


sys.path.append(os.path.join(os.path.dirname(__file__)))
import __fix_import_paths # isort:skip # noqa: F401 # pylint: disable=W0611
import release_index
import requests
Expand Down Expand Up @@ -89,6 +91,22 @@ def versions_to_unelect(
return [v for v in elected_versions if v not in active_releases_versions and v not in active_versions]


def find_parent_release_commit(ic_repo: GitRepo, config: release_index.Model, commit: str) -> str:
rc, rc_idx = next(
(rc, i) for i, rc in enumerate(config.root.releases) if any(v.version == commit for v in rc.versions)
)
v_idx = next(i for i, v in enumerate(config.root.releases[rc_idx].versions) if v.version == commit)
return (
config.root.releases[rc_idx + 1].versions[0].version # take first version from the previous rc
if v_idx == 0
else next(
v.version
for i, v in reversed(list(enumerate(rc.versions[: v_idx - 1])))
if i == 0 or ic_repo.is_ancestor(v.version, commit)
)
)


# https://stackoverflow.com/a/44873382
def sha256sum(filename):
h = hashlib.sha256()
Expand Down Expand Up @@ -173,11 +191,7 @@ def reconcile(self):
push_release_tags(self.ic_repo, rc)
self.notes_client.ensure(
version_name=version_name(rc_name=rc.rc_name, name=v.name),
since_commit=(
config.root.releases[rc_idx + 1].versions[0].version # take first version from the previous rc
if v_idx == 0
else rc.versions[v_idx - 1].version # take previous version from the same rc
),
since_commit=find_parent_release_commit(self.ic_repo, config, v.version),
git_revision=v.version,
tag_teams_on_create=v_idx == 0,
)
Expand Down
55 changes: 54 additions & 1 deletion release-controller/test_reconciler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from mock_google_docs import ReleaseNotesClientMock
from publish_notes import PublishNotesClient
from pydantic_yaml import parse_yaml_raw_as
from reconciler import oldest_active_release
from reconciler import find_parent_release_commit, oldest_active_release
from reconciler import Reconciler
from reconciler import ReconcilerState
from reconciler import version_package_checksum
Expand Down Expand Up @@ -297,3 +297,56 @@ def mock_download_files(url: str, timeout: int = 10): # pylint: disable=unused-
assert requests.get.call_count == 3 # pylint: disable=no-member

assert repr(e.value) == repr(RuntimeError("checksums do not match"))


def test_find_parent_release_commit():
ic_repo = git_repo.GitRepo(f"https://github.com/dfinity/ic.git", main_branch="master")
test_cases = [
SimpleNamespace(
name="parent is not the directly preceding release version",
input="48c500d1501e4165fc183e508872a2ef13fd0bef",
want="246d0ce0784d9990c06904809722ce5c2c816269",
index=parse_yaml_raw_as(
release_index.Model,
"""
releases:
- rc_name: rc--2024-06-12_23-01
versions:
- name: base
version: 246d0ce0784d9990c06904809722ce5c2c816269
- name: storage-layer-disabled
version: 2dfe3a1864d1b9a6df462e9503adf351036e7965
- name: cycle-hotfix
version: 48c500d1501e4165fc183e508872a2ef13fd0bef
""",
),
),
SimpleNamespace(
name="parent is not the directly preceding release version",
input="246d0ce0784d9990c06904809722ce5c2c816269",
want="d19fa446ab35780b2c6d8b82ea32d808cca558d5",
index=parse_yaml_raw_as(
release_index.Model,
"""
releases:
- rc_name: rc--2024-06-12_23-01
versions:
- name: base
version: 246d0ce0784d9990c06904809722ce5c2c816269
- name: storage-layer-disabled
version: 2dfe3a1864d1b9a6df462e9503adf351036e7965
- name: cycle-hotfix
version: 48c500d1501e4165fc183e508872a2ef13fd0bef
- rc_name: rc--2024-06-05_23-01
versions:
- name: base
version: d19fa446ab35780b2c6d8b82ea32d808cca558d5
- name: storage-layer-disabled
version: 08f32722df2f56f1e5c1e603fee0c87c40b77cba
""",
),
),
]

for tc in test_cases:
assert find_parent_release_commit(ic_repo, tc.index, tc.input) == tc.want

0 comments on commit cf6ba28

Please sign in to comment.