|
13 | 13 | import subprocess |
14 | 14 | import platform |
15 | 15 |
|
16 | | -package_name = 'com.unity.netcode.gameobjects' |
17 | | - |
18 | | -def update_changelog(new_version): |
19 | | - """ |
20 | | - Cleans the [Unreleased] section of the changelog by removing empty subsections, |
21 | | - then replaces the '[Unreleased]' tag with the new version and release date. |
22 | | - """ |
23 | | - |
24 | | - changelog_entry = f'## [{new_version}] - {datetime.date.today().isoformat()}' |
25 | | - changelog_path = f'{package_name}/CHANGELOG.md' |
26 | | - print("Latest CHANGELOG entry will be modified to: " + changelog_entry) |
27 | | - |
28 | | - with open(changelog_path, 'r', encoding='UTF-8') as f: |
29 | | - changelog_text = f.read() |
30 | | - |
31 | | - # This pattern finds a line starting with '###', followed by its newline, |
32 | | - # and then two more lines that contain only whitespace. |
33 | | - # The re.MULTILINE flag allows '^' to match the start of each line. |
34 | | - pattern = re.compile(r"^###.*\n\n\n", re.MULTILINE) |
35 | | - |
36 | | - # Replace every match with an empty string. The goal is to remove empty CHANGELOG subsections. |
37 | | - cleaned_content = pattern.sub('', changelog_text) |
38 | | - |
39 | | - # Replace the [Unreleased] section with the new version + cleaned subsections |
40 | | - changelog_text = re.sub(r'## \[Unreleased\]', changelog_entry, cleaned_content) |
41 | | - |
42 | | - # Write the changes |
43 | | - with open(changelog_path, 'w', encoding='UTF-8', newline='\n') as file: |
44 | | - file.write(changelog_text) |
45 | | - |
46 | | - |
47 | | -def update_validation_exceptions(new_version): |
48 | | - """ |
49 | | - Updates the ValidationExceptions.json file with the new package version. |
50 | | - """ |
51 | | - |
52 | | - validation_file = f'{package_name}/ValidationExceptions.json' |
53 | | - |
54 | | - # If files do not exist, exit |
55 | | - if not os.path.exists(validation_file): |
56 | | - return |
57 | | - |
58 | | - # Update the PackageVersion in the exceptions |
59 | | - with open(validation_file, 'rb') as f: |
60 | | - json_text = f.read() |
61 | | - data = json.loads(json_text) |
62 | | - updated = False |
63 | | - for exceptionElements in ["WarningExceptions", "ErrorExceptions"]: |
64 | | - exceptions = data.get(exceptionElements) |
65 | | - |
66 | | - if exceptions is not None: |
67 | | - for exception in exceptions: |
68 | | - if 'PackageVersion' in exception: |
69 | | - exception['PackageVersion'] = new_version |
70 | | - updated = True |
71 | | - |
72 | | - # If no exceptions were updated, we do not need to write the file |
73 | | - if not updated: |
74 | | - return |
75 | | - |
76 | | - with open(validation_file, 'w', encoding='UTF-8', newline='\n') as json_file: |
77 | | - json.dump(data, json_file, ensure_ascii=False, indent=2) |
78 | | - json_file.write("\n") # Add newline cause Py JSON does not |
79 | | - print(f" updated `{validation_file}`") |
80 | | - |
81 | | - |
82 | | -def get_manifest_json_version(filename): |
83 | | - """ |
84 | | - Reads the package.json file and returns the version specified in it. |
85 | | - """ |
86 | | - with open(filename, 'rb') as f: |
87 | | - json_text = f.read() |
88 | | - data = json.loads(json_text) |
89 | | - |
90 | | - return data['version'] |
91 | | - |
| 16 | +UTILS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), './Utils')) |
| 17 | +sys.path.insert(0, UTILS_DIR) |
| 18 | +from general_utils import get_package_version_from_manifest, update_changelog, update_validation_exceptions # nopep8 |
| 19 | +from config import getNetcodePackageName, getPackageManifestPath, getPackageValidationExceptionsPath # nopep8 |
92 | 20 |
|
93 | 21 | if __name__ == '__main__': |
94 | | - manifest_path = f'{package_name}/package.json' |
95 | | - package_version = get_manifest_json_version(manifest_path) |
| 22 | + |
| 23 | + ngo_package_name = getNetcodePackageName() |
| 24 | + ngo_manifest_path = getPackageManifestPath() |
| 25 | + ngo_validation_exceptions_path = getPackageValidationExceptionsPath() |
| 26 | + ngo_package_version = get_package_version_from_manifest(ngo_manifest_path) |
| 27 | + |
| 28 | + if not os.path.exists(ngo_manifest_path): |
| 29 | + print(f" Path does not exist: {ngo_manifest_path}") |
| 30 | + sys.exit(1) |
| 31 | + |
| 32 | + if ngo_package_version is None: |
| 33 | + print(f"Package version not found at {ngo_manifest_path}") |
| 34 | + sys.exit(1) |
96 | 35 |
|
97 | 36 | # Update the ValidationExceptions.json file |
98 | 37 | # with the new package version OR remove it if not a release branch |
99 | | - update_validation_exceptions(package_version) |
| 38 | + update_validation_exceptions(ngo_validation_exceptions_path, ngo_package_version) |
100 | 39 | # Clean the CHANGELOG and add latest entry |
101 | | - update_changelog(package_version) |
| 40 | + # package version is already know as is always corresponds to current package state |
| 41 | + update_changelog(ngo_package_version) |
0 commit comments