prepare_changelog.py 959 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. from datetime import datetime
  2. from pathlib import Path
  3. from olmocr.version import VERSION
  4. def main():
  5. changelog = Path("CHANGELOG.md")
  6. with changelog.open() as f:
  7. lines = f.readlines()
  8. insert_index: int = -1
  9. for i in range(len(lines)):
  10. line = lines[i]
  11. if line.startswith("## Unreleased"):
  12. insert_index = i + 1
  13. elif line.startswith(f"## [v{VERSION}]"):
  14. print("CHANGELOG already up-to-date")
  15. return
  16. elif line.startswith("## [v"):
  17. break
  18. if insert_index < 0:
  19. raise RuntimeError("Couldn't find 'Unreleased' section")
  20. lines.insert(insert_index, "\n")
  21. lines.insert(
  22. insert_index + 1,
  23. f"## [v{VERSION}](https://github.com/allenai/olmocr/releases/tag/v{VERSION}) - " f"{datetime.now().strftime('%Y-%m-%d')}\n",
  24. )
  25. with changelog.open("w") as f:
  26. f.writelines(lines)
  27. if __name__ == "__main__":
  28. main()