-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathupdate-workflow
More file actions
executable file
·89 lines (73 loc) · 2.74 KB
/
Copy pathupdate-workflow
File metadata and controls
executable file
·89 lines (73 loc) · 2.74 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
#!/usr/bin/env python3
# Copyright © Michal Čihař <michal@weblate.org>
#
# 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-15",
"windows-latest": "windows-2025",
}
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
if "permissions" not in data:
data["permissions"] = {"contents": "read"}
modified = True
if events := data.get("on"):
# Convert legacy style on list to modern layout
if isinstance(events, list):
data["on"] = events = dict.fromkeys(events)
modified = True
# Include dependabot in ignored branches to match renovate
# The dependabot might trigger security updates which renovate does not
# yet see.
if (
(push_event := events.get("push"))
and (branches := push_event.get("branches-ignore"))
and "renovate/**" in branches
and "dependabot/**" not in branches
):
branches.append("dependabot/**")
modified = True
for job_name in data["jobs"]:
job = data["jobs"][job_name]
# Avoid using *-latest OS, pin it instead
if "runs-on" in job and job["runs-on"] in RUNS_UPDATE:
job["runs-on"] = RUNS_UPDATE[job["runs-on"]]
modified = True
if "steps" in job:
for step in job["steps"]:
uses = step.get("uses", "")
if uses.startswith("actions/checkout@"):
if "with" not in step:
step["with"] = {}
if "persist-credentials" not in step["with"]:
step["with"]["persist-credentials"] = "token" in step["with"]
modified = True
if uses.startswith("astral-sh/setup-uv@"):
if "with" not in step:
step["with"] = {}
if "version" not in step["with"]:
step["with"]["version"] = "0.9.5"
modified = True
# Revert workaround for https://github.com/mgedmin/check-manifest/issues/177
if step.get("run") == "uvx --with pip check-manifest -v":
step["run"] = "uvx check-manifest -v"
modified = True
if step.get("run", "").startswith("uvx --with pip pyroma"):
step["run"] = f"uvx {step['run'].removeprefix('uvx --with pip ')}"
modified = True
if modified:
with open(sys.argv[1], "w") as handle:
yaml.dump(data, handle)
subprocess.run(
["uvx", "prek", "run", "--files", sys.argv[1]], check=False, capture_output=True
)