CI: Update matrix.py so all code is contained in functions.

Refactor matrix.py so all the logic is contained inside either
helper functions or a new main function. Run the new main function
by default. This lets other GitHub actions use functions in the
python code without generating the whole matrix.
This commit is contained in:
Andrew Hopkins 2023-09-05 16:32:50 -07:00 committed by William Lallemand
parent 4f77690366
commit b2a7840a28

18
.github/matrix.py vendored
View File

@ -15,12 +15,6 @@ import sys
import urllib.request
from os import environ
if len(sys.argv) == 2:
ref_name = sys.argv[1]
else:
print("Usage: {} <ref_name>".format(sys.argv[0]), file=sys.stderr)
sys.exit(1)
#
# this CI is used for both development and stable branches of HAProxy
#
@ -29,8 +23,6 @@ else:
# "haproxy-" - stable branches
# otherwise - development branch (i.e. "latest" ssl variants, "latest" github images)
#
print("Generating matrix for branch '{}'.".format(ref_name))
def clean_ssl(ssl):
return ssl.replace("_VERSION", "").lower()
@ -101,6 +93,8 @@ def get_asan_flags(cc):
'CPU_CFLAGS.generic="-O1"',
]
def main(ref_name):
print("Generating matrix for branch '{}'.".format(ref_name))
matrix = []
@ -258,3 +252,11 @@ print(json.dumps(matrix, indent=4, sort_keys=True))
if environ.get("GITHUB_OUTPUT") is not None:
with open(environ.get("GITHUB_OUTPUT"), "a") as f:
print("matrix={}".format(json.dumps({"include": matrix})), file=f)
if __name__ == "__main__":
if len(sys.argv) == 2:
ref_name = sys.argv[1]
main(ref_name)
else:
print("Usage: {} <ref_name>".format(sys.argv[0]), file=sys.stderr)
sys.exit(1)