Skip to content

Commit e683700

Browse files
Update check-version.yml (#96)
1 parent b86deaa commit e683700

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

.github/workflows/check-version.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
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 "
5049
import os
50+
import tempfile
5151
from packaging.version import parse
5252

5353
issue_version = os.environ['ISSUE_VERSION']
5454
latest_version = os.environ['LATEST_VERSION']
5555
issue_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

5859
print(f'Issue version: {issue_version}')
5960
print(f'Latest release version: {latest_version}')
6061

6162
# Ensure the issue version is parseable (e.g., if user inputs garbage)
6263
try:
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

6869
try:
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

7475
if parsed_issue_version < parsed_latest_version:
@@ -84,9 +85,16 @@ pip install --upgrade python-pirate-weather
8485

8586
If 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
9098
else:
9199
print('User is running the latest version or a newer/unreleased version.')
92-
"
100+
"

0 commit comments

Comments
 (0)