From 51b1fa412d8e0e01119d4edb13558a3855e6c67c Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 5 Nov 2024 16:36:39 -0500 Subject: [PATCH] Install awx collection from branch for operator ci --- .github/workflows/ci.yml | 2 + .../rewrite-awx-operator-requirements.py | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 tools/scripts/rewrite-awx-operator-requirements.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c60d28f803e8..08479c39469d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -187,6 +187,8 @@ jobs: working-directory: awx-operator run: | python3 -m pip install -r molecule/requirements.txt + python3 -m pip install PyYAML # for awx/tools/scripts/rewrite-awx-operator-requirements.py + $(realpath ../awx/tools/scripts/rewrite-awx-operator-requirements.py) molecule/requirements.yml $(realpath ../awx) ansible-galaxy collection install -r molecule/requirements.yml sudo rm -f $(which kustomize) make kustomize diff --git a/tools/scripts/rewrite-awx-operator-requirements.py b/tools/scripts/rewrite-awx-operator-requirements.py new file mode 100755 index 000000000000..376764b0bc8d --- /dev/null +++ b/tools/scripts/rewrite-awx-operator-requirements.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import yaml +import sys + + +AWX_ENTRY = 'https://github.com/ansible/awx.git#/awx_collection/' + + +def load_yaml_file(fname): + with open(fname, 'r') as file: + data = yaml.safe_load(file) + return data + + +def write_yaml_file(fname, data): + with open(fname, 'w') as file: + yaml.dump(data, file) + + +def replace_awx(data, path): + for entry in data['collections']: + if entry['name'] == AWX_ENTRY or entry['name'] == 'awx.awx': + entry['name'] = f'file://{path}#/awx_collection/' + entry['type'] = 'git' + entry.pop('version', None) + return data + + raise ValueError(f"Failed to find {AWX_ENTRY} in {data}") + + +def run(fname, awx_path): + write_yaml_file(fname, replace_awx(load_yaml_file(fname), awx_path)) + + +if __name__ == "__main__": + if len(sys.argv) == 3: + run(sys.argv[1], sys.argv[2]) + else: + print(f"Usage: {sys.argv[0]} ", file=sys.stderr)