Skip to content

Commit

Permalink
Use git notes info populated by commit annotator to generate notes (#811
Browse files Browse the repository at this point in the history
)

Co-authored-by: CI Automation <[email protected]>
Co-authored-by: sa-github-api <[email protected]>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent 09221a6 commit 57440f4
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 486 deletions.
68 changes: 17 additions & 51 deletions release-controller/release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import typing
from dataclasses import dataclass
from git_repo import GitRepo
from util import bazel_binary
from commit_annotator import GUESTOS_CHANGED_NOTES_NAMESPACE

import markdown

Expand Down Expand Up @@ -309,18 +309,12 @@ def get_change_description_for_commit(
commiter = ic_repo.get_commit_info("%an", commit_hash)

ic_repo.checkout(commit_hash)
guestos_targets_all = get_guestos_targets_with_bazel(ic_repo) + INCLUDE_CHANGES
guestos_targets_filtered = [
t
for t in guestos_targets_all
if t in INCLUDE_CHANGES or not any(re.match(f, t) for f in EXCLUDE_CHANGES_FILTERS)
]

file_changes = ic_repo.file_changes_for_commit(commit_hash)

exclusion_reasons = []
guestos_change = any(f["file_path"] in guestos_targets_all for f in file_changes)
if guestos_change and not any(f["file_path"] in guestos_targets_filtered for f in file_changes):
guestos_change = is_guestos_change(ic_repo, commit_hash)
if guestos_change and not any(
f for f in file_changes if not any(re.match(filter, f["file_path"]) for filter in EXCLUDE_CHANGES_FILTERS)
):
exclusion_reasons.append("filtered out by package filters")

ownership = {}
Expand Down Expand Up @@ -489,46 +483,18 @@ def format_change(change: Change):
return notes


def bazel_query(ic_repo: GitRepo, query):
"""Bazel query package for GuestOS."""
bazel_query = [
bazel_binary(),
"query",
query,
]
p = subprocess.run(
["gitlab-ci/container/container-run.sh"] + bazel_query,
cwd=ic_repo.dir,
text=True,
stdout=subprocess.PIPE,
check=False,
)
if p.returncode != 0:
print("Failure running Bazel through container. Attempting direct run.", file=sys.stderr)
try:
p = subprocess.run(
bazel_query,
cwd=ic_repo.dir,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True,
)
except subprocess.CalledProcessError as e:
print(p.stdout)
print(p.stderr)
raise e
return [l[::-1].replace(":", "/", 1)[::-1].removeprefix("//") for l in p.stdout.splitlines()]


def get_guestos_targets_with_bazel(ic_repo: GitRepo):
"""Get the packages that are related to the GuestOS image using Bazel."""
guestos_packages_all = bazel_query(
ic_repo,
"deps(//ic-os/guestos/envs/prod:update-img.tar.zst) union deps(//ic-os/setupos/envs/prod:disk-img.tar.zst)",
)

return guestos_packages_all
def is_guestos_change(ic_repo: GitRepo, commit: str) -> bool:
"""Check if GuestOS changed for the commit by querying git notes populated by commit annotator."""
changed = ic_repo.get_note(GUESTOS_CHANGED_NOTES_NAMESPACE, commit)
if not changed:
raise ValueError(f"Could not find targets for commit {commit}")
changed = changed.strip()
if changed == "True":
return True
elif changed == "False":
return False
else:
raise ValueError(f"Invalid value for changed note {changed}")


def main():
Expand Down
65 changes: 33 additions & 32 deletions release-controller/test_reconciler.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,13 @@ def mock_download_files(url: str, timeout: int = 10): # pylint: disable=unused-


def test_find_base_release():
ic_repo = git_repo.GitRepo(
f"https://github.com/dfinity/ic.git", main_branch="master", repo_cache_dir=pathlib.Path("/tmp/reconciler-cache")
)
index = parse_yaml_raw_as(
release_index.Model,
"""
with tempfile.TemporaryDirectory() as repo_cache_dir:
ic_repo = git_repo.GitRepo(
"https://github.com/dfinity/ic.git", main_branch="master", repo_cache_dir=pathlib.Path(repo_cache_dir)
)
index = parse_yaml_raw_as(
release_index.Model,
"""
releases:
- rc_name: rc--2024-07-10_23-01
versions:
Expand Down Expand Up @@ -414,29 +415,29 @@ def test_find_base_release():
- name: hotfix-bitcoin-query-stats
version: 4e9b02fc3c0fa377b2fba44b15841d6ef73593a3
""",
)

assert find_base_release(ic_repo, index, "48c500d1501e4165fc183e508872a2ef13fd0bef") == (
"246d0ce0784d9990c06904809722ce5c2c816269",
"release-2024-06-12_23-01-base",
)
assert find_base_release(ic_repo, index, "246d0ce0784d9990c06904809722ce5c2c816269") == (
"d19fa446ab35780b2c6d8b82ea32d808cca558d5",
"release-2024-06-05_23-01-base",
)
assert find_base_release(ic_repo, index, "9866a6f5cb43c54e3d87fa02a4eb80d0f159dddb") == (
"2c4566b7b7af453167785504ba3c563e09f38504",
"release-2024-05-09_23-02-base",
)
assert find_base_release(ic_repo, index, "63acf4f88b20ec0c6384f4e18f0f6f69fc5d9b9f") == (
"0a51fd74f08b2e6f23d6e1d60f1f52eb73b40ccc",
"release-2024-04-17_23-01-query-stats",
)
assert find_base_release(ic_repo, index, "0d2b3965c813cd3a39ceedacd97fa2eee8760074") == (
"a3831c87440df4821b435050c8a8fcb3745d86f6",
"release-2024-07-10_23-01-base",
)
assert find_base_release(ic_repo, index, "ec35ebd252d4ffb151d2cfceba3a86c4fb87c6d6") == (
"5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d",
"release-2024-05-15_23-02-base",
)
)

assert find_base_release(ic_repo, index, "48c500d1501e4165fc183e508872a2ef13fd0bef") == (
"246d0ce0784d9990c06904809722ce5c2c816269",
"release-2024-06-12_23-01-base",
)
assert find_base_release(ic_repo, index, "246d0ce0784d9990c06904809722ce5c2c816269") == (
"d19fa446ab35780b2c6d8b82ea32d808cca558d5",
"release-2024-06-05_23-01-base",
)
assert find_base_release(ic_repo, index, "9866a6f5cb43c54e3d87fa02a4eb80d0f159dddb") == (
"2c4566b7b7af453167785504ba3c563e09f38504",
"release-2024-05-09_23-02-base",
)
assert find_base_release(ic_repo, index, "63acf4f88b20ec0c6384f4e18f0f6f69fc5d9b9f") == (
"0a51fd74f08b2e6f23d6e1d60f1f52eb73b40ccc",
"release-2024-04-17_23-01-query-stats",
)
assert find_base_release(ic_repo, index, "0d2b3965c813cd3a39ceedacd97fa2eee8760074") == (
"a3831c87440df4821b435050c8a8fcb3745d86f6",
"release-2024-07-10_23-01-base",
)
assert find_base_release(ic_repo, index, "ec35ebd252d4ffb151d2cfceba3a86c4fb87c6d6") == (
"5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d",
"release-2024-05-15_23-02-base",
)
Loading

0 comments on commit 57440f4

Please sign in to comment.