Skip to content

Commit

Permalink
Fix prepare-release-pr script
Browse files Browse the repository at this point in the history
The script is [currently failing with](https://github.com/pytest-dev/pytest/actions/runs/13615071695/job/38057071681):

```
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/pytest-dev/pytest.git/'
```

Decided to remove the usage of `github3` and use the `gh` command-line tool directly, which simplifies the script, integrates nicely with GH, and enables to run it locally seamlessly.
  • Loading branch information
nicoddemus committed Mar 2, 2025
1 parent bc4abe4 commit 79f0733
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
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"
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 <[email protected]>` 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}:[email protected]/{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

0 comments on commit 79f0733

Please sign in to comment.