forked from tjcsl/ion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregen-workflow.py
executable file
·34 lines (25 loc) · 1.26 KB
/
regen-workflow.py
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
#!/usr/bin/env python3
import json
import os
import sys
try:
import yaml
except ImportError:
sys.exit("Please install pyyaml. (In some package managers, this is called python-yaml or python3-yaml.)")
# Why is this script necessary? Well, the different jobs run in the CI build have a lot of shared steps.
# To avoid duplication, the CI YAML file relies on a lot of anchors (look up "YAML anchors" for details) to
# riuse pieces of information
# Unfortunately, GitHub does not support YAML anchors in workflow files:
# https://github.community/t/support-for-yaml-anchors/16128/33
# The only way to get it to work is to have an intermediary script like this.
repo_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
with open(os.path.join(repo_dir, "ci/spec.yml")) as f:
loader = yaml.SafeLoader(f)
loader.bool_values = dict(yaml.SafeLoader.bool_values)
# GitHub Actions has an "on" key that gets translated to 'true' without this.
loader.bool_values.update({"on": "on"})
ci_spec = loader.get_single_data()
ci_spec.pop(".anchors", None)
with open(os.path.join(repo_dir, ".github/workflows/ci.yml"), "w") as f:
f.write("# WARNING: Do not edit this file manually! Edit ci/spec.yml and run ci/regen-workflow.py.\n\n")
json.dump(ci_spec, f)