-
Notifications
You must be signed in to change notification settings - Fork 0
224 lines (181 loc) · 9.38 KB
/
check-versions.yml
File metadata and controls
224 lines (181 loc) · 9.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Check Python Versions
on:
schedule:
- cron: '0 0 * * 0' # Weekly on Sunday at midnight UTC
workflow_dispatch:
jobs:
check-versions:
name: Check for Python version updates
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Check current Python versions
id: check
run: |
echo "Checking Python versions from official images..."
# Initialize arrays
declare -A current_versions
declare -A new_versions
# Current minor versions we support
MINOR_VERSIONS=("3.9" "3.10" "3.11" "3.12" "3.13" "3.14")
# Check each version
for minor in "${MINOR_VERSIONS[@]}"; do
# Determine debian version
if [[ "$minor" == "3.9" || "$minor" == "3.10" ]]; then
debian="bullseye"
else
debian="bookworm"
fi
echo "Checking Python ${minor} (${debian})..."
# Get actual version from official image
version=$(docker run --rm python:${minor}-slim-${debian} python --version 2>&1 | grep -oP 'Python \K[\d.]+' || echo "")
if [ -n "$version" ]; then
current_versions[$minor]=$version
echo " Found: $version"
else
echo " ERROR: Could not detect version for ${minor}"
current_versions[$minor]="unknown"
fi
done
# Check for Python 3.15 (future version)
echo "Checking for Python 3.15..."
if docker pull python:3.15-slim-bookworm 2>/dev/null; then
version=$(docker run --rm python:3.15-slim-bookworm python --version 2>&1 | grep -oP 'Python \K[\d.]+' || echo "")
if [ -n "$version" ]; then
echo " NEW VERSION FOUND: Python 3.15 ($version)"
current_versions["3.15"]=$version
echo "new_minor_version=3.15" >> $GITHUB_OUTPUT
fi
else
echo " Python 3.15 not yet available"
fi
# Save versions to file for next step
for minor in "${!current_versions[@]}"; do
echo "${minor}=${current_versions[$minor]}" >> /tmp/versions.txt
done
# Output for debugging
cat /tmp/versions.txt
- name: Update README with versions
id: update-readme
run: |
echo "Updating README with current versions..."
# Read versions
declare -A versions
while IFS='=' read -r minor version; do
versions[$minor]=$version
done < /tmp/versions.txt
# Create backup
cp README.md README.md.backup
# Update the table in README
# This updates the "Python Source" column with actual versions
for minor in "${!versions[@]}"; do
version="${versions[$minor]}"
if [[ "$minor" == "3.9" || "$minor" == "3.10" ]]; then
debian="bullseye"
else
debian="bookworm"
fi
# Check if this is the latest Python version (has ":latest" tag)
# Currently 3.14, but will be 3.15, 3.16, etc. in the future
if grep -q "| ${minor} | \`:${minor}\` or \`:latest\` |" README.md; then
# Handle version with :latest tag
# First try to update existing version
sed -i "s/| ${minor} | \`:${minor}\` or \`:latest\` | \`python:${minor}-slim-${debian}\` ([^)]*) |/| ${minor} | \`:${minor}\` or \`:latest\` | \`python:${minor}-slim-${debian}\` (${version}) |/g" README.md
# If no existing version, add it
sed -i "s/| ${minor} | \`:${minor}\` or \`:latest\` | \`python:${minor}-slim-${debian}\` |/| ${minor} | \`:${minor}\` or \`:latest\` | \`python:${minor}-slim-${debian}\` (${version}) |/g" README.md
else
# Handle regular version without :latest tag
# First try to update existing version
sed -i "s/| ${minor} | \`:${minor}\` | \`python:${minor}-slim-${debian}\` ([^)]*) |/| ${minor} | \`:${minor}\` | \`python:${minor}-slim-${debian}\` (${version}) |/g" README.md
# If no existing version, add it
sed -i "s/| ${minor} | \`:${minor}\` | \`python:${minor}-slim-${debian}\` |/| ${minor} | \`:${minor}\` | \`python:${minor}-slim-${debian}\` (${version}) |/g" README.md
fi
done
# Check if there were changes
if ! diff -q README.md README.md.backup > /dev/null 2>&1; then
echo "changes_detected=true" >> $GITHUB_OUTPUT
echo "Changes detected in README"
# Show diff
echo "Diff:"
diff README.md.backup README.md || true
else
echo "changes_detected=false" >> $GITHUB_OUTPUT
echo "No changes detected"
fi
rm README.md.backup
- name: Update workflow matrix if new minor version found
if: steps.check.outputs.new_minor_version
run: |
NEW_VERSION="${{ steps.check.outputs.new_minor_version }}"
echo "Adding Python ${NEW_VERSION} to workflow matrix..."
# Read the version from temp file
VERSION=$(grep "^${NEW_VERSION}=" /tmp/versions.txt | cut -d= -f2)
# Add to build.yml matrix
WORKFLOW_FILE=".github/workflows/build.yml"
# Insert new version in matrix (before the last item)
# Find the line with "3.14" and add the new version after it
sed -i "/python_version: \"3.14\"/a\\ - python_version: \"${NEW_VERSION}\"\n debian_version: \"bookworm\"" $WORKFLOW_FILE
# Update the test matrix
sed -i "s/python_version: \[\"3.9\", \"3.10\", \"3.11\", \"3.12\", \"3.13\", \"3.14\"\]/python_version: [\"3.9\", \"3.10\", \"3.11\", \"3.12\", \"3.13\", \"3.14\", \"${NEW_VERSION}\"]/" $WORKFLOW_FILE
# Update latest tag logic (3.14 -> new version)
sed -i "s/matrix.python_version == '3.14'/matrix.python_version == '${NEW_VERSION}'/" $WORKFLOW_FILE
echo "Workflow updated to include Python ${NEW_VERSION}"
# Update README table to add new minor version
echo "Adding Python ${NEW_VERSION} to README table..."
# Find the current "latest" version line (currently 3.14)
CURRENT_LATEST=$(grep -E "\\| [0-9.]+ \\| \`:[0-9.]+\` or \`:latest\`" README.md | sed -E 's/.*\| ([0-9.]+) \| .*/\1/' | head -1)
if [ -n "$CURRENT_LATEST" ]; then
echo "Current latest version: ${CURRENT_LATEST}"
# Remove ":latest" tag from current latest version
sed -i "s/| ${CURRENT_LATEST} | \`:${CURRENT_LATEST}\` or \`:latest\` |/| ${CURRENT_LATEST} | \`:${CURRENT_LATEST}\` |/g" README.md
# Get the distroless version for the current latest (to use as template)
DISTROLESS=$(grep "| ${CURRENT_LATEST} |" README.md | sed -E 's/.*gcr.io\/distroless\/(python3-debian[0-9]+).*/\1/' | head -1)
DISTROLESS="gcr.io/distroless/${DISTROLESS}"
# Add new row after current latest with :latest tag
# The new version will use bookworm (Debian 12) as it's a recent Python version
NEW_ROW="| ${NEW_VERSION} | \`:${NEW_VERSION}\` or \`:latest\` | \`python:${NEW_VERSION}-slim-bookworm\` (${VERSION}) | \`debian:bookworm-slim\` | \`${DISTROLESS}\` |"
# Insert new row after the previous latest (GNU sed syntax)
sed -i "/| ${CURRENT_LATEST} |/a\\${NEW_ROW}" README.md
echo "Added new row for Python ${NEW_VERSION} with :latest tag"
echo "Removed :latest tag from Python ${CURRENT_LATEST}"
else
echo "Warning: Could not find current latest version in README"
fi
- name: Create Pull Request
id: cpr
if: steps.update-readme.outputs.changes_detected == 'true' || steps.check.outputs.new_minor_version
uses: peter-evans/create-pull-request@v8
with:
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
commit-message: |
chore: Update Python versions
- Updated README with current Python versions
${{ steps.check.outputs.new_minor_version && format('- Added Python {0} to build matrix', steps.check.outputs.new_minor_version) || '' }}
branch: update-python-versions
delete-branch: true
title: 'chore: Update Python versions'
body: |
## Python Version Update
This PR updates the Python version information:
### Changes
- ✅ Updated README with current Python versions from official images
${{ steps.check.outputs.new_minor_version && format('- ✅ **NEW**: Added Python {0} to build matrix', steps.check.outputs.new_minor_version) || '' }}
### Version Details
```
$(cat /tmp/versions.txt)
```
### Auto-merge enabled
This PR will automatically merge when all required status checks pass.
---
🤖 Auto-generated by weekly version check workflow
labels: dependencies,automated
- name: Enable auto-merge
if: steps.cpr.outputs.pull-request-number
run: |
gh pr merge ${{ steps.cpr.outputs.pull-request-number }} --auto --squash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}