Skip to content

Commit 390398e

Browse files
committed
Update dependencies via CI cron
1 parent 77f12cd commit 390398e

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import os
2+
import re
3+
import urllib.request
4+
5+
import atoma
6+
7+
try:
8+
from rich import print
9+
except ImportError:
10+
pass
11+
12+
DEFINITIONS_FILE = "winbuild/build_prepare.py"
13+
14+
DEPENDENCIES = [
15+
# Name, GitHub slug, version prefix
16+
("fribidi", "fribidi/fribidi", "v"),
17+
("harfbuzz", "harfbuzz/harfbuzz", ""),
18+
("openjpeg", "uclouvain/openjpeg", "v"),
19+
]
20+
21+
22+
def update_version(name: str, slug: str, version_prefix: str) -> str | None:
23+
url = f"https://github.com/{slug}/tags.atom"
24+
print(url)
25+
contents = urllib.request.urlopen(url).read()
26+
feed = atoma.parse_atom_bytes(contents)
27+
link = feed.entries[0].links[0].href
28+
print(link)
29+
new_tag = link.rsplit("/", 1)[1]
30+
print(f"{new_tag=}")
31+
new_version = new_tag.removeprefix(version_prefix)
32+
print(f"{new_version=}")
33+
34+
with open(DEFINITIONS_FILE) as f:
35+
content = f.read()
36+
content_new = re.sub(
37+
rf"https://github.com/{slug}/archive/{version_prefix}\d+\.\d+\.\d+.zip",
38+
f"https://github.com/{slug}/archive/{version_prefix}{new_version}.zip",
39+
content,
40+
)
41+
content_new = re.sub(
42+
rf"{name}-\d+\.\d+\.\d+",
43+
rf"{name}-{new_version}",
44+
content_new,
45+
)
46+
changes_made = content != content_new
47+
print(f"{changes_made=}")
48+
print()
49+
50+
if changes_made:
51+
# Write the file out again
52+
with open(DEFINITIONS_FILE, "w") as f:
53+
f.write(content_new)
54+
return f"{name} to {new_version}"
55+
56+
return None
57+
58+
59+
def main() -> None:
60+
updates = []
61+
for name, slug, v_in_tag in DEPENDENCIES:
62+
update = update_version(name, slug, v_in_tag)
63+
if update:
64+
updates.append(update)
65+
66+
if updates:
67+
commit_message = "Update " + ", ".join(updates)
68+
print(commit_message)
69+
70+
github_env_file = os.getenv("GITHUB_ENV")
71+
if github_env_file:
72+
with open(github_env_file, "a") as f:
73+
f.write(f"COMMIT_MESSAGE={commit_message}")
74+
else:
75+
print("No updates")
76+
77+
78+
if __name__ == "__main__":
79+
main()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: "Update dependencies"
2+
3+
on:
4+
schedule:
5+
- cron: "30 19 * * *" # daily at 19:30 UTC
6+
push:
7+
paths:
8+
- ".github/workflows/update-dependencies.py"
9+
- ".github/workflows/update-dependencies.yml"
10+
pull_request:
11+
paths:
12+
- ".github/workflows/update-dependencies.py"
13+
- ".github/workflows/update-dependencies.yml"
14+
workflow_dispatch:
15+
16+
env:
17+
FORCE_COLOR: 1
18+
19+
jobs:
20+
update_dependencies:
21+
# TODO if: github.repository_owner == 'python-pillow'
22+
name: Update dependencies
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v3
29+
with:
30+
python-version: "3.10"
31+
cache: pip
32+
cache-dependency-path: .github/workflows/update-dependencies.py
33+
34+
- name: "Check for updates"
35+
run: |
36+
python -m pip install atoma
37+
python .github/workflows/update-dependencies.py
38+
39+
- name: "Check if there are changes"
40+
id: "changes"
41+
uses: UnicornGlobal/[email protected]
42+
43+
# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
44+
- name: "Create PR"
45+
if: steps.changes.outputs.changed == 1
46+
uses: "peter-evans/create-pull-request@v3"
47+
with:
48+
commit-message: >-
49+
Update dependencies
50+
title: ${{ env.COMMIT_MESSAGE }}
51+
body: ""
52+
labels: "Dependency"
53+
branch: "update/dependencies"
54+
delete-branch: true

0 commit comments

Comments
 (0)