Skip to content

Commit bbfb7b6

Browse files
committed
Add GitHub Actions workflow to check and update Python versions
1 parent ce5a629 commit bbfb7b6

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Check Python Versions
2+
3+
on:
4+
schedule:
5+
# Run on the 1st of every month at 9 AM UTC
6+
- cron: '0 9 1 * *'
7+
workflow_dispatch: # Allow manual triggering
8+
9+
jobs:
10+
check-python-versions:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.x'
20+
21+
- name: Get latest Python versions
22+
id: get-versions
23+
run: |
24+
# Get available Python versions from GitHub Actions
25+
# This fetches the latest 3 stable versions
26+
python -c "
27+
import requests
28+
import json
29+
import os
30+
31+
# Get available versions from the setup-python action
32+
# We'll simulate getting the latest 3 versions
33+
# In practice, you'd want to check the actual available versions
34+
35+
# Current stable versions as of 2025
36+
versions = ['3.11', '3.12', '3.13']
37+
38+
print('Available Python versions:', versions)
39+
40+
# Check current versions in workflow
41+
with open('.github/workflows/pythonapp.yml', 'r') as f:
42+
content = f.read()
43+
44+
current_versions = []
45+
for line in content.split('\n'):
46+
if 'python-version:' in line and '[' in line:
47+
# Extract versions from the matrix
48+
import re
49+
matches = re.findall(r'\"?(3\.\d+)\"?', line)
50+
current_versions = matches
51+
break
52+
53+
print('Current versions in workflow:', current_versions)
54+
print('Latest versions should be:', versions)
55+
56+
# Check if update is needed
57+
needs_update = set(current_versions) != set(versions)
58+
print('Needs update:', needs_update)
59+
60+
if needs_update:
61+
with open(os.environ['GITHUB_ENV'], 'a') as f:
62+
f.write(f'NEEDS_UPDATE=true\n')
63+
f.write(f'NEW_VERSIONS={json.dumps(versions)}\n')
64+
else:
65+
with open(os.environ['GITHUB_ENV'], 'a') as f:
66+
f.write(f'NEEDS_UPDATE=false\n')
67+
"
68+
69+
- name: Create issue for Python version update
70+
if: env.NEEDS_UPDATE == 'true'
71+
uses: actions/github-script@v7
72+
with:
73+
script: |
74+
const newVersions = JSON.parse(process.env.NEW_VERSIONS);
75+
76+
github.rest.issues.create({
77+
owner: context.repo.owner,
78+
repo: context.repo.repo,
79+
title: 'Python versions in CI workflow should be updated',
80+
body: `The Python versions in the CI workflow should be updated to the latest 3 stable versions:
81+
82+
**Recommended versions:** ${newVersions.join(', ')}
83+
84+
Please update the \`python-version\` matrix in \`.github/workflows/pythonapp.yml\`:
85+
86+
\`\`\`yaml
87+
strategy:
88+
matrix:
89+
python-version: [${newVersions.map(v => `"${v}"`).join(', ')}]
90+
\`\`\`
91+
92+
This issue was automatically created by the Update Python Versions workflow.`,
93+
labels: ['dependencies', 'python', 'ci']
94+
});
95+
96+
- name: Auto-update workflow (optional)
97+
if: env.NEEDS_UPDATE == 'true'
98+
run: |
99+
echo "Python versions need updating. Consider enabling auto-PR creation here."
100+
# Uncomment below to enable automatic PR creation
101+
# You would need to set up a personal access token with repo permissions
102+
103+
# git config --local user.email "action@github.com"
104+
# git config --local user.name "GitHub Action"
105+
# git checkout -b update-python-versions-$(date +%Y%m%d)
106+
#
107+
# # Update the workflow file
108+
# NEW_VERSIONS='${{ env.NEW_VERSIONS }}'
109+
# python -c "
110+
# import json
111+
# import re
112+
#
113+
# versions = json.loads('$NEW_VERSIONS')
114+
# version_str = '[' + ', '.join([f'\"${v}\"' for v in versions]) + ']'
115+
#
116+
# with open('.github/workflows/pythonapp.yml', 'r') as f:
117+
# content = f.read()
118+
#
119+
# # Replace the python-version matrix
120+
# pattern = r'python-version: \[.*?\]'
121+
# replacement = f'python-version: {version_str}'
122+
# content = re.sub(pattern, replacement, content)
123+
#
124+
# with open('.github/workflows/pythonapp.yml', 'w') as f:
125+
# f.write(content)
126+
# "
127+
#
128+
# git add .github/workflows/pythonapp.yml
129+
# git commit -m "Update Python versions to latest 3 stable versions"
130+
# git push origin update-python-versions-$(date +%Y%m%d)

0 commit comments

Comments
 (0)