Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tools/create_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def compute_done_milestones(self, version: str) -> set[str]:

# 1. Preparation
if self.github.find_pr_for_branch(
f"{self.github.actor()}:{BRANCH_PREFIX}/{version}", self.config.main_branch
f"{self.git.owner('origin')}:{BRANCH_PREFIX}/{version}",
self.config.main_branch,
):
done.add("Preparation")

Expand Down Expand Up @@ -888,12 +889,14 @@ def stage_publish_release(self, version: str) -> None:
return
if self.config.github_actions:
s.ok("Asking user to publish the release")
release = self.github.release(version)
url = release["html_url"]
raise self.assign_to_user(
s,
version,
task="Publication",
action="publish the release",
instruction=f"All checks passed and assets signed. Please [publish the release](https://github.com/{self.github.repository()}/releases/tag/{version}) manually.",
instruction=f"All checks passed and assets signed. Please [publish the release]({url}) manually.",
)
s.ok("Not implemented yet")

Expand Down
14 changes: 14 additions & 0 deletions tools/lib/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ def release_id(self, tag: str) -> int:
return rid
raise ValueError(f"Release {tag} not found in {self.repository()}")

def get_release(self, tag: str) -> Any:
"""Get the full release object for a tag, or None if not found."""
rid = self.get_release_id(tag)
if rid is None:
return None
return self.api_uncached(f"/repos/{self.repository()}/releases/{rid}")

def release(self, tag: str) -> Any:
"""Get the full release object for a tag."""
release = self.get_release(tag)
if release is not None:
return release
raise ValueError(f"Release {tag} not found in {self.repository()}")

def actor(self) -> str:
"""Returns the GitHub username for the current repository."""
github_actor = os.getenv("GITHUB_ACTOR")
Expand Down
67 changes: 63 additions & 4 deletions tools/release_e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def api_post(
params: dict[str, Any] | None = None,
) -> Any:
if url.endswith("/pulls"):
head_user, head_ref = (
json["head"].split(":", 1)
if ":" in json["head"]
else ("toktok-releaser", json["head"])
)
pr = {
"title": json["title"],
"body": json["body"],
Expand All @@ -104,7 +109,11 @@ def api_post(
"node_id": f"node{len(self._prs)}",
"html_url": f"url{len(self._prs)}",
"state": "open",
"head": {"sha": "sha123", "ref": json["head"]},
"head": {
"sha": "sha123",
"ref": head_ref,
"user": {"login": head_user},
},
"milestone": None,
"draft": json.get("draft", False),
"merged_at": None,
Expand All @@ -123,6 +132,7 @@ def api_post(
"prerelease": json["prerelease"],
"draft": json["draft"],
"published_at": None,
"html_url": f"https://github.com/TokTok/ci-tools/releases/edit/{json['tag_name']}",
}
self._releases.append(release)
return release
Expand Down Expand Up @@ -217,7 +227,8 @@ def find_pr_for_branch(
) -> github.PullRequest | None:
for pr_data in self._prs:
if pr_data["state"] == state or state == "all":
if pr_data["head"]["ref"] == head.split(":")[-1]:
pr_head = f"{pr_data['head']['user']['login']}:{pr_data['head']['ref']}"
if pr_head == head:
return github.PullRequest.fromJSON(pr_data)
return None

Expand Down Expand Up @@ -312,7 +323,7 @@ def checkout(self, name: str) -> None:
self._current_branch = name

def owner(self, remote: str) -> str:
return "bot"
return "human"

def last_commit_message(self, branch: str) -> str:
return self._log[-1] if self._log else ""
Expand Down Expand Up @@ -415,6 +426,7 @@ def test_full_release_lifecycle(self) -> None:
"tag_name": "v1.0.0",
"published_at": None,
"body": "Existing draft notes",
"html_url": "https://github.com/TokTok/ci-tools/releases/edit/v1.0.0",
}
)

Expand Down Expand Up @@ -487,11 +499,16 @@ def mock_action_runs(branch: str, sha: str) -> list[github.ActionRun]:
pass

# Verify intermediate dashboard state
self.assertIn("[x] Create release branch and PR", gh._issues[1]["body"])
self.assertIn("**Current Step: Finalize release**", gh._issues[1]["body"])
self.assertIn(
"Action Required:** All checks passed and assets signed",
gh._issues[1]["body"],
)
self.assertIn(
"https://github.com/TokTok/ci-tools/releases/edit/v1.0.0",
gh._issues[1]["body"],
)

# Simulate user published release, re-assign bot, and re-run
gh._releases[0]["published_at"] = "2026-02-06T00:00:00Z"
Expand All @@ -503,6 +520,41 @@ def mock_action_runs(branch: str, sha: str) -> list[github.ActionRun]:
self.assertEqual(gh._issues[1]["state"], "closed")
self.assertIn("[x] Finalize release", gh._issues[1]["body"])

def test_mismatched_actor_and_owner(self) -> None:
"""Verify that the dashboard works when actor and owner are different."""
config = self.make_config()
gh = FakeGitHub()
gh._user = {"login": "releaser-bot"}
gh.add_issue(
1,
"Release tracking issue",
"### Release notes\nCool notes\nProduction release",
)
gh.add_milestone(1, "v1.0.0")

gt = FakeGit()

# Simulate owner being different from actor
def mock_owner(remote: str) -> str:
return "TokTok"

setattr(gt, "owner", mock_owner)

releaser = Releaser(config, gt, gh)

with self.release_mocks(gh, gt):
# We only care about the preparation stage for this test
releaser.stage_init()
version = releaser.stage_version()
releaser.stage_branch(version)
releaser.stage_pull_request(version)
releaser.update_dashboard(version)

# Check that the checkbox is marked
self.assertIn("[x] Create release branch and PR", gh._issues[1]["body"])
# Verify the PR head in our fake storage
self.assertEqual(gh._prs[0]["head"]["user"]["login"], "TokTok")

def test_invalid_issue_title(self) -> None:
config = self.make_config()
gh = FakeGitHub()
Expand All @@ -528,6 +580,7 @@ def test_prerelease_lifecycle(self) -> None:
"published_at": "2026-02-06T00:00:00Z",
"prerelease": True,
"draft": False,
"html_url": "https://github.com/TokTok/ci-tools/releases/edit/v1.0.0-rc.1",
}
)

Expand Down Expand Up @@ -578,7 +631,11 @@ def test_existing_pr_update(self) -> None:
"node_id": "node555",
"html_url": "url555",
"state": "open",
"head": {"sha": "sha123", "ref": "release/v1.0.0"},
"head": {
"sha": "sha123",
"ref": "release/v1.0.0",
"user": {"login": "human"},
},
"milestone": {"number": 1},
"draft": True,
"merged_at": None,
Expand Down Expand Up @@ -660,6 +717,7 @@ def test_release_ci_failure(self) -> None:
"tag_name": "v1.0.0",
"published_at": None,
"body": "Existing draft notes",
"html_url": "https://github.com/TokTok/ci-tools/releases/edit/v1.0.0",
}
)

Expand Down Expand Up @@ -698,6 +756,7 @@ def test_release_ci_timeout(self) -> None:
"tag_name": "v1.0.0",
"published_at": None,
"body": "Existing draft notes",
"html_url": "https://github.com/TokTok/ci-tools/releases/edit/v1.0.0",
}
)

Expand Down
Loading