|
| 1 | +""" |
| 2 | +NGO release script |
| 3 | +- Update changelogs + validation exception file based on manifest version |
| 4 | +""" |
| 5 | +#!/usr/bin/env python3 |
| 6 | +import datetime |
| 7 | +import json |
| 8 | +import os |
| 9 | +import re |
| 10 | + |
| 11 | +package_name = 'com.unity.netcode.gameobjects' |
| 12 | + |
| 13 | +def update_changelog(new_version): |
| 14 | + changelog_entry = f'## [{new_version}] - {datetime.date.today().isoformat()}' |
| 15 | + |
| 16 | + print(changelog_entry) |
| 17 | + |
| 18 | + changelog_path = f'{package_name}/CHANGELOG.md' |
| 19 | + with open(changelog_path, 'rb') as f: |
| 20 | + changelog_text = f.read() |
| 21 | + |
| 22 | + changelog_text = re.sub(br'## \[Unreleased\]', bytes(changelog_entry, 'UTF-8'), changelog_text) |
| 23 | + |
| 24 | + with open(changelog_path, 'wb') as f: |
| 25 | + f.write(changelog_text) |
| 26 | + |
| 27 | +def update_validation_exceptions(new_version): |
| 28 | + validation_file = f'{package_name}/ValidationExceptions.json' |
| 29 | + if not os.path.exists(validation_file): |
| 30 | + return |
| 31 | + |
| 32 | + with open(validation_file, 'rb') as f: |
| 33 | + json_text = f.read() |
| 34 | + data = json.loads(json_text) |
| 35 | + updated = False |
| 36 | + for exceptionElements in ["WarningExceptions", "ErrorExceptions"]: |
| 37 | + exceptions = data.get(exceptionElements) |
| 38 | + |
| 39 | + if exceptions is not None: |
| 40 | + for exception in exceptions: |
| 41 | + if 'PackageVersion' in exception: |
| 42 | + exception['PackageVersion'] = new_version |
| 43 | + updated = True |
| 44 | + |
| 45 | + if not updated: |
| 46 | + return |
| 47 | + |
| 48 | + with open(validation_file, "w", encoding="UTF-8") as json_file: |
| 49 | + json.dump(data, json_file, ensure_ascii=False, indent=2) |
| 50 | + json_file.write("\n") # Add newline cause Py JSON does not |
| 51 | + print(f" updated `{validation_file}`") |
| 52 | + |
| 53 | + |
| 54 | +def get_manifest_json_version(filename): |
| 55 | + with open(filename, 'rb') as f: |
| 56 | + json_text = f.read() |
| 57 | + data = json.loads(json_text) |
| 58 | + |
| 59 | + return data['version'] |
| 60 | + |
| 61 | +if __name__ == '__main__': |
| 62 | + manifest_path = f'{package_name}/package.json' |
| 63 | + version = get_manifest_json_version(manifest_path) |
| 64 | + update_validation_exceptions(version) |
| 65 | + |
| 66 | + update_changelog(version) |
0 commit comments