Skip to content

Commit 44c79b4

Browse files
committed
Implement script to update python versions
1 parent 60930f0 commit 44c79b4

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: update-versions
2+
on:
3+
schedule:
4+
- cron: '0 0 * * *'
5+
jobs:
6+
build:
7+
if: github.repository == 'DMOJ/runtimes-python'
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Set up Python 3.14
12+
uses: actions/setup-python@v5
13+
with:
14+
python-version: '3.14'
15+
- name: Installing dependencies
16+
run: pip install -r requirements.txt
17+
- name: Update python versions
18+
run: |
19+
sed -i '/python-version:/c\ python-version: [ '"$(python get_versions.py | tr '\n' , | sed 's/,$//;s/,/, /g')"' ]' .github/workflows/build.yml
20+
- name: Create pull request
21+
uses: peter-evans/create-pull-request@v4
22+
with:
23+
author: dmoj-build <build@dmoj.ca>
24+
committer: dmoj-build <build@dmoj.ca>
25+
commit-message: 'update python versions'
26+
title: 'update python versions'
27+
body: This PR has been auto-generated to update the python versions in `build` action.
28+
reviewers: Xyene, quantum5, kiritofeng
29+
branch: update-versions

get_versions.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import re
2+
3+
import requests
4+
from bs4 import BeautifulSoup
5+
6+
reversion = re.compile(r'\d+\.\d+(?:\.\d+)?/$')
7+
8+
9+
def main():
10+
downloads = requests.get('https://www.python.org/downloads/')
11+
downloads.raise_for_status()
12+
13+
wanted = []
14+
soup = BeautifulSoup(downloads.content, 'html.parser')
15+
version_rows = soup.find('div', class_='active-release-list-widget').find('ol', class_='list-row-container')
16+
for row in version_rows.find_all('li'):
17+
branch = row.find('span', class_='release-version').text
18+
status = row.find('span', class_='release-status').text
19+
if status in ('bugfix', 'security'):
20+
wanted.append(tuple(map(int, branch.split('.'))))
21+
22+
ftp = requests.get('https://www.python.org/ftp/python/')
23+
ftp.raise_for_status()
24+
25+
soup = BeautifulSoup(ftp.content, 'html.parser')
26+
27+
releases = {}
28+
for version in soup.find_all('a'):
29+
href = version['href']
30+
if reversion.match(href):
31+
release = tuple(map(int, href.rstrip('/').split('.')))
32+
branch = (release[0], release[1])
33+
if branch in wanted:
34+
if branch in releases:
35+
releases[branch] = max(releases[branch], release)
36+
else:
37+
releases[branch] = release
38+
39+
for _, release in sorted(releases.items()):
40+
print('.'.join(map(str, release)))
41+
42+
43+
if __name__ == '__main__':
44+
main()

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BeautifulSoup4
2+
requests

0 commit comments

Comments
 (0)