Skip to content

Commit 9772133

Browse files
authored
improve changelog/release handling (#321)
* move changelog&version check to pre-commit and separate CI job that is not required for merging * add --allow-future * allow later release number in changelog
1 parent 5f008c3 commit 9772133

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

.github/workflows/ci.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
runs-on: ubuntu-latest
3131
strategy:
3232
matrix:
33-
python-version: ['3.9', '3.10', '3.11', '3.12', 3.13]
33+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
3434
fail-fast: false
3535
steps:
3636
- uses: actions/checkout@v4
@@ -62,10 +62,21 @@ jobs:
6262
- name: Run tests
6363
run: python -m tox -e flake8_7 -- --onlyfuzz --no-cov -n auto
6464

65+
check_release:
66+
runs-on: ubuntu-latest
67+
strategy:
68+
fail-fast: false
69+
steps:
70+
- uses: actions/checkout@v4
71+
- name: Set up Python 3
72+
uses: actions/setup-python@v5
73+
- name: Test changelog & version
74+
run: python tests/check_changelog_and_version.py
75+
6576
release:
6677
runs-on: ubuntu-latest
67-
needs: [pyright, test]
68-
if: github.repository == 'python-trio/flake8-async' && github.ref == 'refs/heads/main'
78+
needs: [pyright, test, check_release]
79+
if: github.repository == 'python-trio/flake8-async' && github.ref == 'refs/heads/main'
6980
steps:
7081
- uses: actions/checkout@v4
7182
- name: Set up Python 3
@@ -77,5 +88,4 @@ jobs:
7788
TWINE_USERNAME: __token__
7889
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
7990
run: |
80-
python tests/test_changelog_and_version.py --ensure-tag
8191
python -m build && twine upload --skip-existing dist/*

.pre-commit-config.yaml

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ default_language_version:
33
python: python3.12
44
# pyright requires internet connection to run, which the pre-commit ci app doesn't have.
55
# it instead runs in a github action
6+
# check-release-changelog is run as a dedicated job
67
ci:
7-
skip: [pyright]
8+
skip: [pyright, check-release-changelog]
89

910
repos:
1011
- repo: https://github.com/astral-sh/ruff-pre-commit
@@ -100,3 +101,16 @@ repos:
100101
rev: v1.0.0
101102
hooks:
102103
- id: sphinx-lint
104+
105+
- repo: local
106+
hooks:
107+
- id: check-release-changelog
108+
name: check-release-changelog
109+
language: system
110+
entry: python3 tests/check_changelog_and_version.py --allow-future-in-changelog
111+
files: flake8_async/__init__.py|docs/changelog.rst
112+
113+
- repo: meta
114+
hooks:
115+
- id: check-hooks-apply
116+
- id: check-useless-excludes

docs/usage.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ adding the following to your ``.pre-commit-config.yaml``:
3333
minimum_pre_commit_version: '2.9.0'
3434
repos:
3535
- repo: https://github.com/python-trio/flake8-async
36-
rev: 23.2.5
36+
rev: 24.11.4
3737
hooks:
3838
- id: flake8-async
3939
# args: [--enable=ASYNC, --disable=ASYNC9, --autofix=ASYNC]

tests/test_changelog_and_version.py tests/check_changelog_and_version.py

+26-10
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
ROOT_PATH = Path(__file__).parent.parent
1515
CHANGELOG = ROOT_PATH / "docs" / "changelog.rst"
16-
README = ROOT_PATH / "README.md"
16+
USAGE = ROOT_PATH / "docs" / "usage.rst"
1717
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
1818

19+
ALLOW_FUTURE = "--allow-future-in-changelog" in sys.argv
20+
1921
T = TypeVar("T", bound="Version")
2022

2123

@@ -44,6 +46,7 @@ def get_releases() -> Iterable[Version]:
4446
valid_pattern = re.compile(r"^(\d\d\.\d?\d\.\d?\d)$")
4547
header_pattern = re.compile(r"^=+$")
4648
last_line_was_date = False
49+
last_line: str | None = None
4750
with open(CHANGELOG, encoding="utf-8") as f:
4851
lines = f.readlines()
4952
for line in lines:
@@ -54,15 +57,21 @@ def get_releases() -> Iterable[Version]:
5457
elif version_match:
5558
yield Version.from_string(version_match.group(1))
5659
last_line_was_date = True
57-
else:
58-
# stop lines such as `Future\n=====` making it through to main/
59-
assert not header_pattern.match(line), line
60+
# only allow `Future\n=====` when run in pre-commit
61+
elif header_pattern.match(line):
62+
assert ALLOW_FUTURE, "FUTURE header with no --allow-future-in-changelog. "
63+
assert last_line is not None
64+
assert last_line.lower().strip() == "future"
65+
last_line = line
6066

6167

6268
def test_last_release_against_changelog() -> None:
63-
"""Ensure we have the latest version covered in 'changelog.rst'."""
69+
"""Ensure we have the latest version covered in 'changelog.rst'.
70+
71+
If changelog version is greater, the __init__ gets bumped in update_version().
72+
"""
6473
latest_release = next(iter(get_releases()))
65-
assert latest_release == VERSION
74+
assert latest_release >= VERSION, f"{latest_release}, {VERSION}"
6675

6776

6877
def test_version_increments_are_correct() -> None:
@@ -98,20 +107,27 @@ def update_version() -> None:
98107
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
99108
subs = (f'__version__ = "{VERSION}"', f'__version__ = "{last_version}"')
100109
INIT_FILE.write_text(INIT_FILE.read_text().replace(*subs))
110+
print("updated VERSION in __init__.py")
101111

102112
# Similarly, update the pre-commit config example in the README
103-
current = README.read_text()
113+
current = USAGE.read_text()
104114
wanted = re.sub(
105-
pattern=r"^ rev: (\d+\.\d+\.\d+)$",
106-
repl=f" rev: {last_version}",
115+
pattern=r"^ rev: (\d+\.\d+\.\d+)$",
116+
repl=f" rev: {last_version}",
107117
string=current,
108118
flags=re.MULTILINE,
109119
)
120+
if last_version != VERSION:
121+
assert current != wanted, "version changed but regex didn't substitute"
110122
if current != wanted:
111-
README.write_text(wanted)
123+
USAGE.write_text(wanted)
124+
print("updated rev in pre-commit example")
112125

113126

114127
if __name__ == "__main__":
128+
test_last_release_against_changelog()
129+
test_version_increments_are_correct()
130+
115131
update_version()
116132
if "--ensure-tag" in sys.argv:
117133
ensure_tagged()

0 commit comments

Comments
 (0)