-
Notifications
You must be signed in to change notification settings - Fork 789
Expand file tree
/
Copy pathgenerate-auto-publish-workflows.py
More file actions
110 lines (93 loc) · 3.15 KB
/
generate-auto-publish-workflows.py
File metadata and controls
110 lines (93 loc) · 3.15 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
#!/usr/bin/env python3
"""
Script to generate auto publication workflows for given specs
"""
import re
from pathlib import Path
# -----------------------------------------------------------------------------
# List of properties that can appear to describe a spec.
# -----------------------------------------------------------------------------
PROPERTIES = [
"shortname",
"publicationStatus",
"tokenName",
]
# -----------------------------------------------------------------------------
# List of specs for which an auto-publish script needs to be created.
# -----------------------------------------------------------------------------
SPECS = [
{
"shortname": "css-color-4",
"publicationStatus": "CRD",
},
{
"shortname": "css-color-5",
"publicationStatus": "WD",
},
{
"shortname": "css-color-hdr-1",
"publicationStatus": "WD",
},
{
"shortname": "css-fonts-4",
"publicationStatus": "WD",
},
{
"shortname": "css-fonts-5",
"publicationStatus": "WD",
},
{
"shortname": "css-2026",
"publicationStatus": "NOTE",
},
{
"shortname": "css-2027",
"publicationStatus": "NOTE",
},
]
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
def main():
script_path = Path(__file__).parent
template_path = script_path / "auto-publish-template.yml"
workflows_dir = script_path / "workflows"
workflows_dir.mkdir(parents=True, exist_ok=True)
template = template_path.read_text(encoding="utf-8")
# Replace the large comment header block (#####...#####)
template = re.sub(
r"#{5,}.*?#{5,}",
"""######################################################################
# IMPORTANT: Do not edit this file directly!
#
# This workflow was automatically generated through the
# generate-auto-publish-workflows.py script. To update the workflow,
# make changes to the template file and run the script again.
######################################################################""",
template,
flags=re.S,
)
for spec in SPECS:
spec = spec.copy()
# Derive shortname from source if not provided
if "shortname" not in spec or not spec["shortname"]:
spec["shortname"] = spec["source"].split(".")[0].replace("_", "-")
# Derive tokenName if not provided
if "tokenName" not in spec or not spec["tokenName"]:
token = (
spec["shortname"]
.upper()
.replace("-", "_")
)
spec["tokenName"] = f"TR_TOKEN_{token}"
# Apply template substitutions
content = template
for prop in PROPERTIES:
value = spec.get(prop, "")
content = content.replace(f"{{{{{prop}}}}}", value)
# Write workflow file
filename = workflows_dir / f"{spec['shortname']}.yml"
filename.write_text(content, encoding="utf-8", newline="\n")
print(f"Generated {filename}")
if __name__ == "__main__":
main()