tjdests/ci/regen-workflow.py
2021-04-19 22:20:23 -04:00

34 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import sys
import json
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)