Skip to content

Commit 0e5449d

Browse files
YuriiMotovtiangologithub-actions[bot]
authored
🔨 Add pre-commit hook to ensure latest release header has date (#42)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 6eef1ff commit 0e5449d

3 files changed

Lines changed: 53 additions & 6 deletions

File tree

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ repos:
4040
require_serial: true
4141
language: unsupported
4242
pass_filenames: false
43+
44+
- id: add-release-date
45+
language: unsupported
46+
name: add date to latest release header
47+
entry: uv run python scripts/add_latest_release_date.py
48+
files: ^release-notes\.md$
49+
pass_filenames: false

release-notes.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Latest Changes
44

5-
## 0.0.6
5+
## 0.0.6 (2026-04-03)
66

77
### Docs
88

@@ -23,7 +23,7 @@
2323
* ⬆ Bump rich from 14.2.0 to 14.3.3. PR [#48](https://github.com/fastapi/fastapi-new/pull/48) by [@dependabot[bot]](https://github.com/apps/dependabot).
2424
* ⬆ Bump ruff from 0.14.14 to 0.15.4. PR [#49](https://github.com/fastapi/fastapi-new/pull/49) by [@dependabot[bot]](https://github.com/apps/dependabot).
2525

26-
## 0.0.5
26+
## 0.0.5 (2026-02-16)
2727

2828
### Internal
2929

@@ -37,7 +37,7 @@
3737
* 🔧 Ensure that an edit to `uv.lock` gets the `internal` label. PR [#34](https://github.com/fastapi/fastapi-new/pull/34) by [@svlandeg](https://github.com/svlandeg).
3838
* ⬆️ Migrate to uv. PR [#33](https://github.com/fastapi/fastapi-new/pull/33) by [@DoctorJohn](https://github.com/DoctorJohn).
3939

40-
## 0.0.4
40+
## 0.0.4 (2026-01-05)
4141

4242
### Fixes
4343

@@ -49,7 +49,7 @@
4949
* ⬆ Bump actions/checkout from 5 to 6. PR [#26](https://github.com/fastapi/fastapi-new/pull/26) by [@dependabot[bot]](https://github.com/apps/dependabot).
5050
* ⬆ Bump ruff from 0.14.4 to 0.14.10. PR [#31](https://github.com/fastapi/fastapi-new/pull/31) by [@dependabot[bot]](https://github.com/apps/dependabot).
5151

52-
## 0.0.3
52+
## 0.0.3 (2025-12-29)
5353

5454
### Docs
5555

@@ -69,7 +69,7 @@
6969
* 👷 Upgrade `latest-changes` GitHub Action and pin `actions/checkout@v5`. PR [#15](https://github.com/fastapi/fastapi-new/pull/15) by [@svlandeg](https://github.com/svlandeg).
7070
* ⬆ Bump ruff from 0.14.1 to 0.14.3. PR [#7](https://github.com/fastapi/fastapi-new/pull/7) by [@dependabot[bot]](https://github.com/apps/dependabot).
7171

72-
## 0.0.2
72+
## 0.0.2 (2025-11-10)
7373

7474
### Features
7575

@@ -92,6 +92,6 @@
9292
* 👷 Update version of Smokeshow. PR [#3](https://github.com/fastapi/fastapi-new/pull/3) by [@tiangolo](https://github.com/tiangolo).
9393
* 👷 Add tests setup for CI. PR [#1](https://github.com/fastapi/fastapi-new/pull/1) by [@tiangolo](https://github.com/tiangolo).
9494

95-
## 0.0.1
95+
## 0.0.1 (2024-08-15)
9696

9797
Reserve PyPI package.

scripts/add_latest_release_date.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Check release-notes.md and add today's date to the latest release header if missing."""
2+
3+
import re
4+
import sys
5+
from datetime import date
6+
7+
RELEASE_NOTES_FILE = "release-notes.md"
8+
RELEASE_HEADER_PATTERN = re.compile(r"^## (\d+\.\d+\.\d+)\s*(\(.*\))?\s*$")
9+
10+
11+
def main() -> None:
12+
with open(RELEASE_NOTES_FILE) as f:
13+
lines = f.readlines()
14+
15+
for i, line in enumerate(lines):
16+
match = RELEASE_HEADER_PATTERN.match(line)
17+
if not match:
18+
continue
19+
20+
version = match.group(1)
21+
date_part = match.group(2)
22+
23+
if date_part:
24+
print(f"Latest release {version} already has a date: {date_part}")
25+
sys.exit(0)
26+
27+
today = date.today().isoformat()
28+
lines[i] = f"## {version} ({today})\n"
29+
print(f"Added date: {version} ({today})")
30+
31+
with open(RELEASE_NOTES_FILE, "w") as f:
32+
f.writelines(lines)
33+
sys.exit(0)
34+
35+
print("No release header found")
36+
sys.exit(1)
37+
38+
39+
if __name__ == "__main__":
40+
main()

0 commit comments

Comments
 (0)