3838 - name : Compare versions with Python and comment
3939 env :
4040 ISSUE_VERSION : ${{ steps.parse_issue.outputs.payload.version }}
41- # Use the cleaned version here
4241 LATEST_VERSION : ${{ steps.clean_release_version.outputs.CLEANED_LATEST_VERSION }}
4342 ISSUE_NUMBER : ${{ github.event.issue.number }}
4443 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -48,27 +47,29 @@ jobs:
4847
4948 python -c "
5049import os
50+ import tempfile
5151from packaging.version import parse
5252
5353issue_version = os.environ['ISSUE_VERSION']
5454latest_version = os.environ['LATEST_VERSION']
5555issue_number = os.environ['ISSUE_NUMBER']
56- github_token = os.environ['GITHUB_TOKEN'] # Access GitHub Token
56+ github_token = os.environ['GITHUB_TOKEN']
57+ github_repository = os.environ.get('GITHUB_REPOSITORY')
5758
5859print(f'Issue version : {issue_version}')
5960print(f'Latest release version : {latest_version}')
6061
6162# Ensure the issue version is parseable (e.g., if user inputs garbage)
6263try :
6364 parsed_issue_version = parse(issue_version)
64- except Exception :
65- print(f'Could not parse issue version : {issue_version}. Skipping version comparison.')
65+ except Exception as e :
66+ print(f'Could not parse issue version : {issue_version}. Error: {e}. Skipping version comparison.')
6667 exit(0) # Exit gracefully if version cannot be parsed
6768
6869try :
6970 parsed_latest_version = parse(latest_version)
70- except Exception :
71- print(f'Could not parse latest release version : {latest_version}. Skipping version comparison.')
71+ except Exception as e :
72+ print(f'Could not parse latest release version : {latest_version}. Error: {e}. Skipping version comparison.')
7273 exit(0) # Exit gracefully
7374
7475if parsed_issue_version < parsed_latest_version :
@@ -84,9 +85,16 @@ pip install --upgrade python-pirate-weather
8485
8586If the issue persists after updating, please provide the new version number in a comment.
8687' ''
87- # Use GitHub CLI to add a comment
88+ # Write the comment body to a temporary file
89+ with tempfile.NamedTemporaryFile(mode=' w', delete=False, encoding='utf-8') as temp_file:
90+ temp_file.write(update_instructions)
91+ temp_file_path = temp_file.name
92+
93+ # Use GitHub CLI to add a comment from the temporary file
8894 # Ensure gh CLI is authenticated with the GITHUB_TOKEN
89- os.system(f' echo \"{update_instructions}\" | gh issue comment {issue_number} --repo {os.environ.get("GITHUB_REPOSITORY")} --body-file -')
95+ # GITHUB_TOKEN is automatically available to gh CLI in GitHub Actions
96+ os.system(f'gh issue comment {issue_number} --repo {github_repository} --body-file \"{temp_file_path}\"')
97+ os.remove(temp_file_path) # Clean up the temporary file
9098else :
9199 print('User is running the latest version or a newer/unreleased version.')
92- "
100+ "
0 commit comments