Skip to content

Commit 2081683

Browse files
ci: Corrected line encoding in Python scripts (#3679)
## Purpose of this PR This PR follows on #3677 because even though we don't need to execute release.py when packing the package (due to existing pvp exception) nor vetting test job (uses upm-ci which does not run PVP checks) we should future proof release.py and similar scripts from making this mistake. The main reason why the release.py was causing the package pack to fail on windows is that when you open a file in text mode ('w') on Windows, Python's default behavior is to convert each newline character (\n) into the platform's standard line separator, which is \r\n (CRLF). This can cause inconsistencies when the file is used in environments that expect \n (LF), such as Git. The solution was to ensure that we are specifying the newline like `with open(path, 'w', encoding='UTF-8', newline='\n') as file:` ### Jira ticket N/A ## Documentation N/A ## Testing & QA (How your changes can be verified during release Playtest) PR trigger check was green and I verified that when release.py command was included in pack job the results were green (see **[THIS](https://unity-ci.cds.internal.unity3d.com/job/56280166)** job) ## Backports Backport to `develop` branch in #3681
1 parent 8c964aa commit 2081683

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

.yamato/vetting-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{% metadata_file .yamato/project.metafile %} # All configuration that is used to create different configurations (used in for loops) is taken from this file.
22
---
33
# DESCRIPTION--------------------------------------------------------------------------
4-
# This configuration defines vetting tests for the Tools package which allows to validate if the package is in releasable state. This is important in particular because of API validation that allows to detect if we are introducing any new APIs that will force us to bump package version to new minor
4+
# This configuration defines vetting tests for the NGO package which allows to validate if the package is in releasable state. This is important in particular because of API validation that allows to detect if we are introducing any new APIs that will force us to bump package version to new minor
55
# If this test fails with new API error we should either make those API internal OR bump package version to new minor (note that the package version reflects the current package state)
66

77
# Note that we are packing the package only (no project context) so if package have any soft dependencies then project should be used to test it (to enable those APIs)
88
{% for editor in validation_editors.minimal -%}
99
vetting_test:
10-
name: MP Tools - Vetting Test (Win, {{editor}} LTS)
10+
name: NGO - Vetting Test (Win, {{editor}} LTS)
1111
agent: { type: Unity::VM, flavor: b1.large, image: package-ci/win11:v4 }
1212
commands:
1313
- npm install -g "upm-ci-utils@stable" --registry https://artifactory.prd.it.unity3d.com/artifactory/api/npm/upm-npm

Tools/scripts/BuildAutomation/connect_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def main():
3535
# Ensure the project is marked as connected
3636
content = re.sub(r"cloudEnabled:.*", "cloudEnabled: 1", content)
3737

38-
with open(args.project_settings_path, 'w') as f:
38+
with open(args.project_settings_path, 'w', encoding='UTF-8', newline='\n') as f:
3939
f.write(content)
4040

4141
print(f"[Linker] Successfully updated {args.project_settings_path} with Project ID: {args.cloud_project_ID}, Org ID: {args.organization_ID}, Project Name: {args.project_name}")

Tools/scripts/BuildAutomation/disable-enable-burst.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def create_config(settings_path):
4343
}
4444

4545
data = {'MonoBehaviour': monobehaviour}
46-
with open(config_name, 'w') as f:
46+
with open(config_name, 'w', encoding='UTF-8', newline='\n') as f:
4747
json.dump(data, f)
4848
return config_name
4949

@@ -87,7 +87,7 @@ def set_burst_AOT(config_file, status):
8787
assert config is not None, 'AOT settings not found; did the burst-enabled build finish successfully?'
8888

8989
config['MonoBehaviour']['EnableBurstCompilation'] = status
90-
with open(config_file, 'w') as f:
90+
with open(config_file, 'w', encoding='UTF-8', newline='\n') as f:
9191
json.dump(config, f)
9292

9393

Tools/scripts/BuildAutomation/manifest_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
local_path_normalized = args.local_package_path.replace(os.sep, '/')
3131
manifest_data["dependencies"][args.package_name] = f"file:{local_path_normalized}"
3232

33-
with open(args.manifest_path, 'w') as f:
33+
with open(args.manifest_path, 'w', encoding='UTF-8', newline='\n') as f:
3434
json.dump(manifest_data, f, indent=4)
3535

3636
print(f"Successfully updated manifest at '{args.manifest_path}'")

Tools/scripts/Utils/general_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def update_package_version_by_patch(package_manifest_path):
6969

7070
package_manifest['version'] = new_package_version
7171

72-
with open(package_manifest_path, 'w', encoding='UTF-8') as f:
72+
with open(package_manifest_path, 'w', encoding='UTF-8', newline='\n') as f:
7373
json.dump(package_manifest, f, indent=4)
7474

7575
return new_package_version
@@ -166,5 +166,5 @@ def update_changelog(changelog_path, new_version, add_unreleased_template=False)
166166
)
167167

168168
# Write the changes
169-
with open(changelog_path, 'w', encoding='UTF-8') as file:
169+
with open(changelog_path, 'w', encoding='UTF-8', newline='\n') as file:
170170
file.write(final_content)

0 commit comments

Comments
 (0)