ocket8888 commented on a change in pull request #6699:
URL: https://github.com/apache/trafficcontrol/pull/6699#discussion_r837793353



##########
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:
       Why does it write the old content back over the file? We aren't doing 
that for the `GO_VERSION` file as far as I can tell




-- 
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]


Reply via email to