diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d516a21..48d5598 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,3 +40,11 @@ repos: require_serial: true language: unsupported pass_filenames: false + + + - id: add-release-date + language: unsupported + name: add date to latest release header + entry: uv run python scripts/add_latest_release_date.py + files: ^release-notes\.md$ + pass_filenames: false diff --git a/release-notes.md b/release-notes.md index ef67cad..5470302 100644 --- a/release-notes.md +++ b/release-notes.md @@ -32,7 +32,7 @@ * ⬆ Bump actions/checkout from 5 to 6. PR [#20](https://github.com/fastapi/annotated-doc/pull/20) by [@dependabot[bot]](https://github.com/apps/dependabot). * 👷 Upgrade `latest-changes` GitHub Action and pin `actions/checkout@v5`. PR [#21](https://github.com/fastapi/annotated-doc/pull/21) by [@svlandeg](https://github.com/svlandeg). -## 0.0.4 +## 0.0.4 (2025-11-10) ### Fixes @@ -48,7 +48,7 @@ * ⬆ Bump actions/upload-artifact from 4 to 5. PR [#14](https://github.com/fastapi/annotated-doc/pull/14) by [@dependabot[bot]](https://github.com/apps/dependabot). * ⬆ Bump actions/download-artifact from 5 to 6. PR [#13](https://github.com/fastapi/annotated-doc/pull/13) by [@dependabot[bot]](https://github.com/apps/dependabot). -## 0.0.3 +## 0.0.3 (2025-10-24) ### Docs @@ -60,7 +60,7 @@ * 🔧 Add PEP-639 license metadata. PR [#11](https://github.com/fastapi/annotated-doc/pull/11) by [@bollwyvl](https://github.com/bollwyvl). -## 0.0.2 +## 0.0.2 (2025-10-22) ### Features @@ -74,6 +74,6 @@ * 🔧 Add configs for `.github`. PR [#1](https://github.com/fastapi/annotated-doc/pull/1) by [@tiangolo](https://github.com/tiangolo). * 🔧 Update latest-changes config to point to `main` as the main branch. PR [#2](https://github.com/fastapi/annotated-doc/pull/2) by [@tiangolo](https://github.com/tiangolo). -## 0.0.1 +## 0.0.1 (2023-12-11) Reserve PyPI package. diff --git a/scripts/add_latest_release_date.py b/scripts/add_latest_release_date.py new file mode 100644 index 0000000..2e5e420 --- /dev/null +++ b/scripts/add_latest_release_date.py @@ -0,0 +1,40 @@ +"""Check release-notes.md and add today's date to the latest release header if missing.""" + +import re +import sys +from datetime import date + +RELEASE_NOTES_FILE = "release-notes.md" +RELEASE_HEADER_PATTERN = re.compile(r"^## (\d+\.\d+\.\d+)\s*(\(.*\))?\s*$") + + +def main() -> None: + with open(RELEASE_NOTES_FILE) as f: + lines = f.readlines() + + for i, line in enumerate(lines): + match = RELEASE_HEADER_PATTERN.match(line) + if not match: + continue + + version = match.group(1) + date_part = match.group(2) + + if date_part: + print(f"Latest release {version} already has a date: {date_part}") + sys.exit(0) + + today = date.today().isoformat() + lines[i] = f"## {version} ({today})\n" + print(f"Added date: {version} ({today})") + + with open(RELEASE_NOTES_FILE, "w") as f: + f.writelines(lines) + sys.exit(0) + + print("No release header found") + sys.exit(1) + + +if __name__ == "__main__": + main()