devops.release
Release tooling: versions, CI gate, publication and reviewers.
- class devops.release.GitHubClient(api_url=None, token=None, timeout=30)[source]
Bases:
objectSend JSON requests to the GitHub REST API.
The API URL comes from
GITHUB_API_URLand the token fromGH_TOKENorGITHUB_TOKEN, as set by GitHub Actions.- request(path, *, query=None, data=None, allow_missing=False)[source]
Send a GET request, or a POST request if
datais given.- Parameters:
- Returns:
Any – The decoded JSON response, or None for an allowed 404.
- Raises:
ReleaseError – If the request fails or the response is not valid JSON.
- Return type:
Any
- exception devops.release.ReleaseError(message)[source]
Bases:
ExceptionException raised when a release step cannot continue safely.
- Parameters:
message (str)
- Return type:
None
- devops.release.check_release_refs(version, config)[source]
Fail if the tag or the
release/<version>branch already exists.Git errors are raised, never read as “the reference is missing”.
- Parameters:
- Raises:
ReleaseError – If the version is malformed or the tag or branch exists.
- Return type:
None
- devops.release.extract_reviewers(notes, repository)[source]
Return the human PR authors of a repository in release-note order.
- Parameters:
- Returns:
list[str] – Unique logins without bots.
- Return type:
Examples
>>> notes = "* fix: x by @ape33 in https://github.com/o/r/pull/1" >>> extract_reviewers(notes, "o/r") ['ape33']
- devops.release.publish_release(client, repository, version)[source]
Tag
HEADand publish a stable GitHub release with generated notes.A re-run after a partial failure finishes the missing steps. An existing tag on another commit, or a release that is not published and stable, stops the run instead of being replaced.
- Parameters:
client (GitHubClient) – The GitHub client.
repository (str) – The repository as
owner/name.version (str) – The release tag.
- Returns:
str – The release commit SHA.
- Raises:
ReleaseError – If the tag or release cannot be created or verified.
- Return type:
- devops.release.resolve_version(head_ref, title, *, prepare, config)[source]
Return the release tag for a release or hotfix pull request.
A release branch is
release/<prefix>X.Y.Zand its PR title must beRelease-X.Y.Z. A hotfix branch ishotfix/<name>and its PR title must start withHotfix-X.Y.Z.- Parameters:
head_ref (str) – The source branch of the pull request.
title (str | None) – The pull request title. None skips the release title check.
prepare (bool) – Also check that the tag is new and that a hotfix follows the latest tag. Use it before the release; leave it off after the merge.
config (GitConfig) – The Git configuration with the tag prefix.
- Returns:
str – The release tag, for example
v1.2.3.- Raises:
ReleaseError – If the branch, title or version is not valid for a release.
- Return type:
- devops.release.wait_for_ci(client, repository, sha, config, *, echo=<built-in function print>, sleep=<built-in function sleep>, clock=<built-in function monotonic>)[source]
Block until every configured workflow succeeded on the release commit.
Only push runs on the release branch for this exact commit count, and the newest run of each workflow decides. Any other conclusion than
successfails at once; a missing or running workflow fails when the timeout is reached.- Parameters:
client (GitHubClient) – The GitHub client.
repository (str) – The repository as
owner/name.sha (str) – The full commit SHA.
config (ReleaseConfig) – The release configuration with workflows, branch and timing.
echo (Callable[[str], None]) – Prints progress messages.
sleep (Callable[[float], None]) – Waits between polls.
clock (Callable[[], float]) – Returns monotonic time in seconds.
- Raises:
ReleaseError – If a workflow did not succeed or the timeout is reached.
- Return type:
None
Modules
Wait until CI succeeded on the release commit before publishing. |
|
Errors raised by the release tooling. |
|
Minimal GitHub REST client for the release tooling. |
|
Tag the release commit and publish its GitHub release, safe to re-run. |
|
Check that a release tag and its release branch are still free. |
|
Pick release reviewers from generated GitHub release notes. |
|
Resolve the release version from the release branch or hotfix PR title. |