-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
update-workflow
executable file
·66 lines (53 loc) · 1.78 KB
/
update-workflow
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
#!/usr/bin/env python3
# Copyright © Michal Čihař <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0
"""Synchronizes GitHub workflows for Weblate repositories."""
import subprocess
import sys
import ruamel.yaml
RUNS_UPDATE = {
"ubuntu-latest": "ubuntu-24.04",
"macos-latest": "macos-14",
"windows-latest": "windows-2022",
}
PYTHON_VERSION = "3.13"
yaml = ruamel.yaml.YAML()
yaml.indent = 2
yaml.preserve_quotes = False
yaml.width = sys.maxsize
with open(sys.argv[1]) as handle:
data = yaml.load(handle)
modified = False
for job_name in data["jobs"]:
job = data["jobs"][job_name]
# Avoid using *-latest OS, pin it instead
if job["runs-on"] in RUNS_UPDATE:
job["runs-on"] = RUNS_UPDATE[job["runs-on"]]
modified = True
# Use latest stable Python version for all workflows
for step in job["steps"]:
uses = step.get("uses", "")
if uses.startswith("actions/setup-python@"):
try:
float(step["with"]["python-version"])
except (KeyError, ValueError):
continue
step["with"]["python-version"] = PYTHON_VERSION
modified = True
if uses.startswith("astral-sh/setup-uv@"):
try:
float(step["with"]["cache-suffix"])
except (KeyError, ValueError):
continue
step["with"]["cache-suffix"] = PYTHON_VERSION
modified = True
if uses.startswith("actions/checkout@") and uses != "actions/checkout@v4":
step["uses"] = "actions/checkout@v4"
modified = True
if modified:
with open(sys.argv[1], "w") as handle:
yaml.dump(data, handle)
subprocess.run(
["pre-commit", "run", "--files", sys.argv[1]], check=False, capture_output=True
)