Skip to content

Update pip_requirements #52

Update pip_requirements

Update pip_requirements #52

Workflow file for this run

name: Check Issue Version
on:
issues:
types: [opened]
jobs:
check_version:
runs-on: ubuntu-latest
permissions:
issues: write # Needed to comment on issues
contents: read # Needed to get latest release info
steps:
- name: Parse issue form data
id: parse_issue
uses: peter-murray/issue-forms-body-parser@22e5d90e6a607073d08891bc036461971cbcfb45 # v4 # Or zentered/issue-forms-body-parser@v2
with:
issue_id: ${{ github.event.issue.number }}
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Debug: Print parsed payload

Check failure on line 22 in .github/workflows/check-version.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/check-version.yml

Invalid workflow file

You have an error in your yaml syntax on line 22
run: |
echo "Raw parsed payload: ${{ steps.parse_issue.outputs.payload }}"
shell: bash
- name: Get latest release version
id: get_latest_release
uses: pozetroninc/github-action-get-latest-release@2a61c339ea7ef0a336d1daa35ef0cb1418e7676c # v0.8.0 # Or rez0n/actions-github-release@v2.0
with:
repository: cloneofghosts/python-pirate-weather # Your repo
excludes: "prerelease,draft" # Ensure you get stable releases
- name: Clean up latest release version (remove 'v' prefix)
id: clean_release_version
run: |
RAW_LATEST_VERSION="${{ steps.get_latest_release.outputs.release }}"
# Remove 'v' prefix if it exists
CLEANED_LATEST_VERSION="${RAW_LATEST_VERSION#v}"
echo "CLEANED_LATEST_VERSION=$CLEANED_LATEST_VERSION" >> "$GITHUB_OUTPUT"
shell: bash
- name: Compare versions with Python and comment
env:
ISSUE_VERSION: ${{ steps.parse_issue.outputs.payload.version }}
LATEST_VERSION: ${{ steps.clean_release_version.outputs.CLEANED_LATEST_VERSION }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Install Python and packaging library if not already in runner image
python -m pip install packaging
# Start of Python script
import os
import tempfile
import subprocess
from packaging.version import parse
issue_version = os.environ['ISSUE_VERSION']
latest_version = os.environ['LATEST_VERSION']
issue_number = os.environ['ISSUE_NUMBER']
github_token = os.environ['GITHUB_TOKEN']
github_repository = os.environ.get('GITHUB_REPOSITORY')
print(f'Issue version: {issue_version}')
print(f'Latest release version: {latest_version}')
# Ensure the issue version is parseable (e.g., if user inputs garbage)
try:
parsed_issue_version = parse(issue_version)
except Exception as e:
print(f'Could not parse issue version: {issue_version}. Error: {e}. Skipping version comparison.')
exit(0) # Exit gracefully if version cannot be parsed
try:
parsed_latest_version = parse(latest_version)
except Exception as e:
print(f'Could not parse latest release version: {latest_version}. Error: {e}. Skipping version comparison.')
exit(0) # Exit gracefully
if parsed_issue_version < parsed_latest_version:
print('Version mismatch detected. Commenting on issue.')
# Define update_instructions as a list of lines to avoid YAML parsing issues
update_instructions_lines = [
f'It looks like you are running an older version of `python-pirate-weather` (`{issue_version}`).',
'',
f'**Please update to the latest stable version (`{latest_version}`) before reporting issues, as your issue might already be resolved.**',
'',
'You can update by running:',
'\`\`\`bash',
'pip install --upgrade python-pirate-weather',
'\`\`\`',
'',
'If the issue persists after updating, please provide the new version number in a comment.'
]
update_instructions = '\n'.join(update_instructions_lines)
# Write the comment body to a temporary file
with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as temp_file:
temp_file.write(update_instructions)
temp_file_path = temp_file.name
# Use subprocess.run to execute the gh CLI command
# This is more robust against quoting issues
try:
subprocess.run(
['gh', 'issue', 'comment', str(issue_number), '--repo', github_repository, '--body-file', temp_file_path],
check=True, # Raise an exception for non-zero exit codes
capture_output=True, # Capture stdout/stderr
text=True # Decode stdout/stderr as text
)
print(f"Successfully commented on issue #{issue_number}")
except subprocess.CalledProcessError as e:
print(f"Error commenting on issue: {e}")
print(f"Stdout: {e.stdout}")
print(f"Stderr: {e.stderr}")
finally:
os.remove(temp_file_path) # Clean up the temporary file
else:
print('User is running the latest version or a newer/unreleased version.')
shell: python # Explicitly set the shell to python