devops.release

Release tooling: versions, CI gate, publication and reviewers.

class devops.release.GitHubClient(api_url=None, token=None, timeout=30)[source]

Bases: object

Send JSON requests to the GitHub REST API.

The API URL comes from GITHUB_API_URL and the token from GH_TOKEN or GITHUB_TOKEN, as set by GitHub Actions.

Parameters:
  • api_url (str | None)

  • token (str | None)

  • timeout (float)

request(path, *, query=None, data=None, allow_missing=False)[source]

Send a GET request, or a POST request if data is given.

Parameters:
  • path (str) – The API path, for example /repos/owner/name/releases.

  • query (dict[str, Any] | None) – Query parameters.

  • data (dict[str, Any] | None) – The JSON body of a POST request.

  • allow_missing (bool) – Return None instead of raising when GitHub answers 404.

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: Exception

Exception 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:
  • version (str) – The release tag, for example v1.2.3.

  • config (GitConfig) – The Git configuration with the tag prefix.

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:
  • notes (str) – Release notes as generated by GitHub.

  • repository (str) – The repository as owner/name; PRs of other repositories are skipped.

Returns:

list[str] – Unique logins without bots.

Return type:

list[str]

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 HEAD and 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:

str

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.Z and its PR title must be Release-X.Y.Z. A hotfix branch is hotfix/<name> and its PR title must start with Hotfix-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:

str

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 success fails 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

ci

Wait until CI succeeded on the release commit before publishing.

errors

Errors raised by the release tooling.

github

Minimal GitHub REST client for the release tooling.

publish

Tag the release commit and publish its GitHub release, safe to re-run.

refs

Check that a release tag and its release branch are still free.

reviewers

Pick release reviewers from generated GitHub release notes.

version

Resolve the release version from the release branch or hotfix PR title.