As an alternative, the encoding/decoding roundtrip using protobuf seems reasonable to me, catches the footgun of using floating-point version numbers (it becomes a parse error), whitespace/multiline concatenation being more obvious, and allowing comments (compared to JSON):
( cat << EOF
# yes, comments are allowed
name: "Python package"
on: "push"
build {
python_version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
steps: [
{
name: "Install dependencies"
run:
"python -m pip install --upgrade pip\n"
"pip install pytest\n"
"if [ -f 'requirements.txt' ]; then pip install -r requirements.txt; fi\n"
},
{
name: "Test with pytest"
run: "pytest\n"
}
]
}
EOF
) | protoc --encode=Config config.proto | protoc --decode=Config config.proto
name: "Python package"
on: "push"
build {
python_version: "3.6"
python_version: "3.7"
python_version: "3.8"
python_version: "3.9"
python_version: "3.10"
steps {
name: "Install dependencies"
run: "python -m pip install --upgrade pip\npip install pytest\nif [ -f \'requirements.txt\' ]; then pip install -r requirements.txt; fi\n"
}
steps {
name: "Test with pytest"
run: "pytest\n"
}
}