Skip to content

Commit ec87085

Browse files
authored
Merge pull request #13263 from pytest-dev/fix-prepare-release
Fix prepare-release-pr script
2 parents 4933d92 + 55db923 commit ec87085

File tree

4 files changed

+25
-32
lines changed

4 files changed

+25
-32
lines changed

.github/workflows/prepare-release-pr.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ jobs:
3030
- uses: actions/checkout@v4
3131
with:
3232
fetch-depth: 0
33-
persist-credentials: false
33+
# persist-credentials is needed in order for us to push the release branch.
34+
persist-credentials: true
3435

3536
- name: Set up Python
3637
uses: actions/setup-python@v5
@@ -47,13 +48,15 @@ jobs:
4748
env:
4849
BRANCH: ${{ github.event.inputs.branch }}
4950
PRERELEASE: ${{ github.event.inputs.prerelease }}
51+
GH_TOKEN: ${{ github.token }}
5052
run: |
51-
tox -e prepare-release-pr -- "$BRANCH" ${{ github.token }} --prerelease="$PRERELEASE"
53+
tox -e prepare-release-pr -- "$BRANCH" --prerelease="$PRERELEASE"
5254
5355
- name: Prepare release PR (major release)
5456
if: github.event.inputs.major == 'yes'
5557
env:
5658
BRANCH: ${{ github.event.inputs.branch }}
5759
PRERELEASE: ${{ github.event.inputs.prerelease }}
60+
GH_TOKEN: ${{ github.token }}
5861
run: |
59-
tox -e prepare-release-pr -- "$BRANCH" ${{ github.token }} --major --prerelease="$PRERELEASE"
62+
tox -e prepare-release-pr -- "$BRANCH" --major --prerelease="$PRERELEASE"

RELEASING.rst

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ Both automatic and manual processes described above follow the same steps from t
137137
in https://github.com/pytest-dev/pytest/actions/workflows/deploy.yml, using the ``release-MAJOR.MINOR.PATCH`` branch
138138
as source.
139139

140+
Using the command-line::
141+
142+
$ gh workflow run deploy.yml -R pytest-dev/pytest --ref=release-{VERSION} -f version={VERSION}
143+
140144
This job will require approval from ``pytest-dev/core``, after which it will publish to PyPI
141145
and tag the repository.
142146

scripts/prepare-release-pr.py

+14-25
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
1111
After that, it will create a release using the `release` tox environment, and push a new PR.
1212
13-
**Token**: currently the token from the GitHub Actions is used, pushed with
14-
`pytest bot <pytestbot@gmail.com>` commit author.
13+
Note: the script uses the `gh` command-line tool, so `GH_TOKEN` must be set in the environment.
1514
"""
1615

1716
from __future__ import annotations
@@ -25,7 +24,6 @@
2524

2625
from colorama import Fore
2726
from colorama import init
28-
from github3.repos import Repository
2927

3028

3129
class InvalidFeatureRelease(Exception):
@@ -54,17 +52,7 @@ class InvalidFeatureRelease(Exception):
5452
"""
5553

5654

57-
def login(token: str) -> Repository:
58-
import github3
59-
60-
github = github3.login(token=token)
61-
owner, repo = SLUG.split("/")
62-
return github.repository(owner, repo)
63-
64-
65-
def prepare_release_pr(
66-
base_branch: str, is_major: bool, token: str, prerelease: str
67-
) -> None:
55+
def prepare_release_pr(base_branch: str, is_major: bool, prerelease: str) -> None:
6856
print()
6957
print(f"Processing release for branch {Fore.CYAN}{base_branch}")
7058

@@ -131,22 +119,25 @@ def prepare_release_pr(
131119
check=True,
132120
)
133121

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

141128
body = PR_BODY.format(version=version)
142-
repo = login(token)
143-
pr = repo.create_pull(
144-
f"Prepare release {version}",
145-
base=base_branch,
146-
head=release_branch,
147-
body=body,
129+
run(
130+
[
131+
"gh",
132+
"pr",
133+
"new",
134+
f"--base={base_branch}",
135+
f"--head={release_branch}",
136+
f"--title=Release {version}",
137+
f"--body={body}",
138+
],
139+
check=True,
148140
)
149-
print(f"Pull request {Fore.CYAN}{pr.url}{Fore.RESET} created.")
150141

151142

152143
def find_next_version(
@@ -174,14 +165,12 @@ def main() -> None:
174165
init(autoreset=True)
175166
parser = argparse.ArgumentParser()
176167
parser.add_argument("base_branch")
177-
parser.add_argument("token")
178168
parser.add_argument("--major", action="store_true", default=False)
179169
parser.add_argument("--prerelease", default="")
180170
options = parser.parse_args()
181171
prepare_release_pr(
182172
base_branch=options.base_branch,
183173
is_major=options.major,
184-
token=options.token,
185174
prerelease=options.prerelease,
186175
)
187176

tox.ini

+1-4
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,8 @@ usedevelop = True
188188
passenv = *
189189
deps =
190190
colorama
191-
github3.py
192191
pre-commit>=2.9.3
193-
wheel
194-
# https://github.com/twisted/towncrier/issues/340
195-
towncrier<21.3.0
192+
towncrier
196193
commands = python scripts/release.py {posargs}
197194

198195
[testenv:prepare-release-pr]

0 commit comments

Comments
 (0)