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
9 changes: 6 additions & 3 deletions .github/workflows/prepare-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
# persist-credentials is needed in order for us to push the release branch.
persist-credentials: true

- name: Set up Python
uses: actions/setup-python@v5
Expand All @@ -47,13 +48,15 @@ jobs:
env:
BRANCH: ${{ github.event.inputs.branch }}
PRERELEASE: ${{ github.event.inputs.prerelease }}
GH_TOKEN: ${{ github.token }}
run: |
tox -e prepare-release-pr -- "$BRANCH" ${{ github.token }} --prerelease="$PRERELEASE"
tox -e prepare-release-pr -- "$BRANCH" --prerelease="$PRERELEASE"

- name: Prepare release PR (major release)
if: github.event.inputs.major == 'yes'
env:
BRANCH: ${{ github.event.inputs.branch }}
PRERELEASE: ${{ github.event.inputs.prerelease }}
GH_TOKEN: ${{ github.token }}
run: |
tox -e prepare-release-pr -- "$BRANCH" ${{ github.token }} --major --prerelease="$PRERELEASE"
tox -e prepare-release-pr -- "$BRANCH" --major --prerelease="$PRERELEASE"
4 changes: 4 additions & 0 deletions RELEASING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ Both automatic and manual processes described above follow the same steps from t
in https://github.com/pytest-dev/pytest/actions/workflows/deploy.yml, using the ``release-MAJOR.MINOR.PATCH`` branch
as source.

Using the command-line::

$ gh workflow run deploy.yml -R pytest-dev/pytest --ref=release-{VERSION} -f version={VERSION}

This job will require approval from ``pytest-dev/core``, after which it will publish to PyPI
and tag the repository.

Expand Down
39 changes: 14 additions & 25 deletions scripts/prepare-release-pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

After that, it will create a release using the `release` tox environment, and push a new PR.

**Token**: currently the token from the GitHub Actions is used, pushed with
`pytest bot <pytestbot@gmail.com>` commit author.
Note: the script uses the `gh` command-line tool, so `GH_TOKEN` must be set in the environment.
"""

from __future__ import annotations
Expand All @@ -25,7 +24,6 @@

from colorama import Fore
from colorama import init
from github3.repos import Repository


class InvalidFeatureRelease(Exception):
Expand Down Expand Up @@ -54,17 +52,7 @@ class InvalidFeatureRelease(Exception):
"""


def login(token: str) -> Repository:
import github3

github = github3.login(token=token)
owner, repo = SLUG.split("/")
return github.repository(owner, repo)


def prepare_release_pr(
base_branch: str, is_major: bool, token: str, prerelease: str
) -> None:
def prepare_release_pr(base_branch: str, is_major: bool, prerelease: str) -> None:
print()
print(f"Processing release for branch {Fore.CYAN}{base_branch}")

Expand Down Expand Up @@ -131,22 +119,25 @@ def prepare_release_pr(
check=True,
)

oauth_url = f"https://{token}:x-oauth-basic@github.com/{SLUG}.git"
run(
["git", "push", oauth_url, f"HEAD:{release_branch}", "--force"],
["git", "push", "origin", f"HEAD:{release_branch}", "--force"],
check=True,
)
print(f"Branch {Fore.CYAN}{release_branch}{Fore.RESET} pushed.")

body = PR_BODY.format(version=version)
repo = login(token)
pr = repo.create_pull(
f"Prepare release {version}",
base=base_branch,
head=release_branch,
body=body,
run(
[
"gh",
"pr",
"new",
f"--base={base_branch}",
f"--head={release_branch}",
f"--title=Release {version}",
f"--body={body}",
],
check=True,
)
print(f"Pull request {Fore.CYAN}{pr.url}{Fore.RESET} created.")


def find_next_version(
Expand Down Expand Up @@ -174,14 +165,12 @@ def main() -> None:
init(autoreset=True)
parser = argparse.ArgumentParser()
parser.add_argument("base_branch")
parser.add_argument("token")
parser.add_argument("--major", action="store_true", default=False)
parser.add_argument("--prerelease", default="")
options = parser.parse_args()
prepare_release_pr(
base_branch=options.base_branch,
is_major=options.major,
token=options.token,
prerelease=options.prerelease,
)

Expand Down
5 changes: 1 addition & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,8 @@ usedevelop = True
passenv = *
deps =
colorama
github3.py
pre-commit>=2.9.3
wheel
# https://github.com/twisted/towncrier/issues/340
towncrier<21.3.0
towncrier
commands = python scripts/release.py {posargs}

[testenv:prepare-release-pr]
Expand Down