From cfbbd93a21a7fd4d5846a50dd5abf36422870b6d Mon Sep 17 00:00:00 2001 From: Bilal Qamar <59555732+BilalQamar95@users.noreply.github.com> Date: Thu, 23 Jan 2025 17:27:39 +0500 Subject: [PATCH] fix: update GitHub actions step output to correctly set generated_pr --- edx_repo_tools/pull_request_creator/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/edx_repo_tools/pull_request_creator/__init__.py b/edx_repo_tools/pull_request_creator/__init__.py index d9e9d281..3a115666 100644 --- a/edx_repo_tools/pull_request_creator/__init__.py +++ b/edx_repo_tools/pull_request_creator/__init__.py @@ -617,9 +617,16 @@ def _create_new_pull_request(self): pr.number, ) if self.output_pr_url_for_github_action: - # using print rather than logger to avoid the logger - # prepending anything past which github actions wouldn't parse - print(f'generated_pr=https://github.com/{self.repository.full_name}/pull/{pr.number} >> $GITHUB_OUTPUT') + # need to append to the special file that GitHub actions exposes + # as using print here won't set the output, it simply logs the message + github_output_path = os.environ.get("GITHUB_OUTPUT") + if not github_output_path: + logger.warning("GITHUB_OUTPUT not set, failed to write action output.") + else: + with open(github_output_path, "a", encoding="utf-8") as out_file: + out_file.write( + f"generated_pr=https://github.com/{self.repository.full_name}/pull/{pr.number}\n" + ) def delete_old_pull_requests(self): logger.info("Checking if there's any old pull requests to delete")