|
12 | 12 |
|
13 | 13 | def update_changelog(new_version): |
14 | 14 | changelog_entry = f'## [{new_version}] - {datetime.date.today().isoformat()}' |
15 | | - |
| 15 | + changelog_path = f'{package_name}/CHANGELOG.md' |
16 | 16 | print(changelog_entry) |
| 17 | + |
| 18 | + if not os.path.exists(changelog_path): |
| 19 | + print(f"Error: CHANGELOG.md file not found at {changelog_path}") |
| 20 | + return |
17 | 21 |
|
18 | | - changelog_path = f'{package_name}/CHANGELOG.md' |
19 | 22 | with open(changelog_path, 'rb') as f: |
20 | 23 | changelog_text = f.read() |
21 | | - |
22 | | - changelog_text = re.sub(br'## \[Unreleased\]', bytes(changelog_entry, 'UTF-8'), changelog_text) |
| 24 | + |
| 25 | + changelog_text_decoded = changelog_text.decode("utf-8") |
| 26 | + if '## [Unreleased]' in changelog_text_decoded: |
| 27 | + # Replace the `Unreleased` section with the new version entry |
| 28 | + print("Found `## [Unreleased]` section. Updating it.") |
| 29 | + changelog_text = re.sub(br'## \[Unreleased\]', bytes(changelog_entry, 'UTF-8'), changelog_text) |
| 30 | + else: |
| 31 | + # `Unreleased` section does not exist, so prepend the new entry at the top |
| 32 | + print("No `## [Unreleased]` section found. Prepending the new entry.") |
| 33 | + changelog_text = bytes(f"{changelog_entry}\n\n", 'UTF-8') + changelog_text |
23 | 34 |
|
24 | 35 | with open(changelog_path, 'wb') as f: |
25 | 36 | f.write(changelog_text) |
@@ -59,6 +70,7 @@ def get_manifest_json_version(filename): |
59 | 70 | return data['version'] |
60 | 71 |
|
61 | 72 | if __name__ == '__main__': |
| 73 | + print(f"Current working directory: {os.getcwd()}") |
62 | 74 | manifest_path = f'{package_name}/package.json' |
63 | 75 | version = get_manifest_json_version(manifest_path) |
64 | 76 | update_validation_exceptions(version) |
|
0 commit comments