prepare-release-pr.py


Overview

`prepare-release-pr.py` is a utility script designed to automate part of the release process for the `pytest` project. It is intended to be run manually from the GitHub Actions interface but can also be executed locally. The script streamlines the creation of a release pull request (PR) by:

This script requires the `gh` CLI tool and an environment variable `GH_TOKEN` set for authentication.


Detailed Explanation of Components

Exception Classes

InvalidFeatureRelease(Exception)


Constants


Functions

prepare_release_pr(base_branch: str, is_major: bool, prerelease: str) -> None

Primary function that orchestrates the release PR preparation.

**Parameters:**

**Returns:** None

**Description:**

  1. Checks out the remote base branch.

  2. Scans the changelog directory for .feature.rst and .breaking.rst files to detect if this is a feature release.

  3. Calls find_next_version() to calculate the next version string based on the release type.

  4. Configures Git user information to a bot identity.

  5. Creates a new release branch named release-{version}.

  6. Decides on the release template depending on the release type:

    • Major release: release.major.rst

    • Prerelease: release.pre.rst

    • Feature (minor) release: release.minor.rst

    • Patch release: release.patch.rst

  7. Runs the tox environment named release to perform the release tasks.

  8. Pushes the new release branch to origin.

  9. Creates a draft pull request using the gh CLI with the new release branch as the head and the base branch as the target.

**Usage Example:**

prepare_release_pr("main", is_major=False, prerelease="")

find_next_version(base_branch: str, is_major: bool, is_feature_release: bool, prerelease: str) -> str

Calculates the next semantic version string based on existing git tags and release type.

**Parameters:**

**Returns:** `str` - A string representing the next version number, e.g., `"7.0.0"`, `"6.2.0rc1"`, `"6.1.3"`.

**Description:**

**Important Implementation Detail:**

**Example:**

If the latest tag is `6.1.3`:


main() -> None

Entry point for command-line execution.

**CLI Usage Example:**

python prepare-release-pr.py main --major --prerelease rc1

Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

flowchart TD
    A[main()] --> B[parse command-line args]
    B --> C[prepare_release_pr(base_branch, is_major, prerelease)]

    subgraph prepare_release_pr
        C --> D[git checkout origin/base_branch]
        D --> E[scan changelog/*.feature.rst, *.breaking.rst]
        E --> F{is_feature_release?}
        F --> G[find_next_version(base_branch, is_major, is_feature_release, prerelease)]
        G --> H[create release branch release-{version}]
        H --> I[configure git user as pytest bot]
        I --> J[determine release template]
        J --> K[tox -e release -- ...]
        K --> L[git push origin release branch]
        L --> M[create draft PR with gh CLI]
    end

Summary

`prepare-release-pr.py` automates the initial stages of the pytest project release process by:

It tightly integrates with the git repository, changelog files, tox environments, and GitHub workflows, serving as a critical tool for managing releases smoothly and consistently.


End of Documentation for prepare-release-pr.py