zrhoffman commented on a change in pull request #6699:
URL: https://github.com/apache/trafficcontrol/pull/6699#discussion_r837920304
##########
File path: .github/actions/pr-to-update-go/pr_to_update_go/go_pr_maker.py
##########
@@ -396,18 +398,25 @@ def set_go_version(self, go_version: str, commit_message:
str,
print(f'Updated {go_version_file} on {self.repo.name}')
env_path = os.path.join(os.path.dirname(getenv(ENV_ENV_FILE)),
".env")
- content = f"GO_VERSION={go_version}\n"
sha = self.file_contents(env_path, source_branch_name).sha
+ with open(env_path, encoding='UTF-8') as env_stream:
+ previous_env_content = env_stream.read()
+ dotenv.set_key(dotenv_path=env_path, key_to_set=GO_VERSION_KEY,
value_to_set=go_version,
+ quote_mode='never')
+ with open(env_path, encoding='UTF-8') as env_stream:
+ env_content = env_stream.read()
commit = self.repo.update_file(
branch=source_branch_name,
- content=content,
+ content=env_content,
path=env_path,
message=commit_message,
sha=sha
)["commit"]
if not isinstance(commit, Commit):
raise TypeError("'commit' property of file update
response was not a Commit")
print(f"Updated {env_path} on {self.repo.name}")
+ with open(env_path, encoding='UTF-8', mode='w') as env_stream:
+ env_stream.write(previous_env_content)
Review comment:
>> We aren't doing that for the `GO_VERSION` file as far as I can tell
> Right, because the update to the `GO_VERSION` file is never written to the
disk, the branch is updated directly using the GitHub API. `.env` is only
written to make use of the `dotenv` package (is writing to the disk necessary
to get the updated file contents?).
As of 7256b2bc55, the contents of both `GO_VERSION` and `.env` are read from
the filesystem, then committed together and reverted in the filesystem
afterwards.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]