Skip to content

Commit 5aa289e

Browse files
committed
Improve GitHub release workflow
This changes the existing script to just generate the release notes and delegate the actual publishing to the `softprops/action-gh-release@v1` action. This allows us to delete the custom code, which failed recently in https://github.com/pytest-dev/pytest/actions/runs/7370258570/job/20056477756.
1 parent 12b9bd5 commit 5aa289e

File tree

4 files changed

+24
-50
lines changed

4 files changed

+24
-50
lines changed

.github/workflows/deploy.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,14 @@ jobs:
8282
python -m pip install --upgrade pip
8383
pip install --upgrade tox
8484
85-
- name: Publish GitHub release notes
86-
env:
87-
GH_RELEASE_NOTES_TOKEN: ${{ github.token }}
85+
- name: Generate release notes
8886
run: |
8987
sudo apt-get install pandoc
90-
tox -e publish-gh-release-notes
88+
tox -e generate-gh-release-notes -- ${{ github.event.inputs.version }} scripts/latest-release-notes.md
89+
90+
- name: Publish GitHub Release
91+
uses: softprops/action-gh-release@v1
92+
with:
93+
body_path: scripts/latest-release-notes.md
94+
files: dist/*
95+
tag_name: ${{ github.event.inputs.version }}

scripts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
latest-release-notes.md

scripts/publish-gh-release-notes.py renamed to scripts/generate-gh-release-notes.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# mypy:disallow-untyped-defs
12
"""
23
Script used to publish GitHub release notes extracted from CHANGELOG.rst.
34
@@ -19,27 +20,18 @@
1920
2021
Requires Python3.6+.
2122
"""
22-
import os
2323
import re
2424
import sys
2525
from pathlib import Path
2626

27-
import github3
2827
import pypandoc
2928

3029

31-
def publish_github_release(slug, token, tag_name, body):
32-
github = github3.login(token=token)
33-
owner, repo = slug.split("/")
34-
repo = github.repository(owner, repo)
35-
return repo.create_release(tag_name=tag_name, body=body)
36-
37-
3830
def parse_changelog(tag_name):
3931
p = Path(__file__).parent.parent / "doc/en/changelog.rst"
4032
changelog_lines = p.read_text(encoding="UTF-8").splitlines()
4133

42-
title_regex = re.compile(r"pytest (\d\.\d+\.\d+) \(\d{4}-\d{2}-\d{2}\)")
34+
title_regex = re.compile(r"pytest (\d\.\d+\.\d+\w*) \(\d{4}-\d{2}-\d{2}\)")
4335
consuming_version = False
4436
version_lines = []
4537
for line in changelog_lines:
@@ -64,36 +56,17 @@ def convert_rst_to_md(text):
6456

6557

6658
def main(argv):
67-
if len(argv) > 1:
68-
tag_name = argv[1]
69-
else:
70-
tag_name = os.environ.get("GITHUB_REF")
71-
if not tag_name:
72-
print("tag_name not given and $GITHUB_REF not set", file=sys.stderr)
73-
return 1
74-
if tag_name.startswith("refs/tags/"):
75-
tag_name = tag_name[len("refs/tags/") :]
76-
77-
token = os.environ.get("GH_RELEASE_NOTES_TOKEN")
78-
if not token:
79-
print("GH_RELEASE_NOTES_TOKEN not set", file=sys.stderr)
80-
return 1
81-
82-
slug = os.environ.get("GITHUB_REPOSITORY")
83-
if not slug:
84-
print("GITHUB_REPOSITORY not set", file=sys.stderr)
85-
return 1
86-
87-
rst_body = parse_changelog(tag_name)
88-
md_body = convert_rst_to_md(rst_body)
89-
if not publish_github_release(slug, token, tag_name, md_body):
90-
print("Could not publish release notes:", file=sys.stderr)
91-
print(md_body, file=sys.stderr)
92-
return 5
59+
if len(argv) != 3:
60+
print("Usage: generate-gh-release-notes VERSION FILE")
61+
return 2
9362

63+
version, filename = argv[1:3]
64+
print(f"Generating GitHub release notes for version {version}")
65+
rst_body = parse_changelog(version)
66+
md_body = convert_rst_to_md(rst_body)
67+
Path(filename).write_text(md_body, encoding="UTF-8")
9468
print()
95-
print(f"Release notes for {tag_name} published successfully:")
96-
print(f"https://github.com/{slug}/releases/tag/{tag_name}")
69+
print(f"Done: {filename}")
9770
print()
9871
return 0
9972

tox.ini

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,13 @@ passenv = {[testenv:release]passenv}
177177
deps = {[testenv:release]deps}
178178
commands = python scripts/prepare-release-pr.py {posargs}
179179

180-
[testenv:publish-gh-release-notes]
181-
description = create GitHub release after deployment
180+
[testenv:generate-gh-release-notes]
181+
description = generate release notes that can be published as GitHub Release
182182
basepython = python3
183183
usedevelop = True
184-
passenv =
185-
GH_RELEASE_NOTES_TOKEN
186-
GITHUB_REF
187-
GITHUB_REPOSITORY
188184
deps =
189-
github3.py
190185
pypandoc
191-
commands = python scripts/publish-gh-release-notes.py {posargs}
186+
commands = python scripts/generate-gh-release-notes.py {posargs}
192187

193188
[flake8]
194189
max-line-length = 120

0 commit comments

Comments
 (0)