| 
									
										
										
										
											2024-09-17 07:53:43 -07:00
										 |  |  | from datetime import datetime | 
					
						
							|  |  |  | from pathlib import Path | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-27 18:30:41 +00:00
										 |  |  | from olmocr.version import VERSION | 
					
						
							| 
									
										
										
										
											2024-09-17 07:53:43 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							|  |  |  |     changelog = Path("CHANGELOG.md") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with changelog.open() as f: | 
					
						
							|  |  |  |         lines = f.readlines() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     insert_index: int = -1 | 
					
						
							|  |  |  |     for i in range(len(lines)): | 
					
						
							|  |  |  |         line = lines[i] | 
					
						
							|  |  |  |         if line.startswith("## Unreleased"): | 
					
						
							|  |  |  |             insert_index = i + 1 | 
					
						
							|  |  |  |         elif line.startswith(f"## [v{VERSION}]"): | 
					
						
							|  |  |  |             print("CHANGELOG already up-to-date") | 
					
						
							|  |  |  |             return | 
					
						
							|  |  |  |         elif line.startswith("## [v"): | 
					
						
							|  |  |  |             break | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if insert_index < 0: | 
					
						
							|  |  |  |         raise RuntimeError("Couldn't find 'Unreleased' section") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     lines.insert(insert_index, "\n") | 
					
						
							|  |  |  |     lines.insert( | 
					
						
							|  |  |  |         insert_index + 1, | 
					
						
							| 
									
										
										
										
											2025-01-29 15:30:39 -08:00
										 |  |  |         f"## [v{VERSION}](https://github.com/allenai/olmocr/releases/tag/v{VERSION}) - " f"{datetime.now().strftime('%Y-%m-%d')}\n", | 
					
						
							| 
									
										
										
										
											2024-09-17 07:53:43 -07:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with changelog.open("w") as f: | 
					
						
							|  |  |  |         f.writelines(lines) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  |     main() |