Skip to content

Commit fdb0948

Browse files
committed
ci: bump ansible-lint to v25; provide collection requirements for ansible-lint
There is a new version of ansible-lint - v25. Newer versions of ansible-lint require the collection requirements to be installed so it can find the modules/plugins. Enhance our ansible-lint ci job to provide the collection requirements, including merging the runtime meta/collection-requirements.yml with the testing tests/collection-requirements.yml. This should somewhat mitigate the loss of ansible-plugin-scan. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent 002c01c commit fdb0948

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

.github/workflows/ansible-lint.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,46 @@ jobs:
3535
pip3 install "git+https://github.com/linux-system-roles/tox-lsr@3.4.0"
3636
3737
- name: Convert role to collection format
38+
id: collection
3839
run: |
3940
set -euxo pipefail
4041
TOXENV=collection lsr_ci_runtox
4142
coll_dir=".tox/ansible_collections/$LSR_ROLE2COLL_NAMESPACE/$LSR_ROLE2COLL_NAME"
4243
# ansible-lint action requires a .git directory???
4344
# https://github.com/ansible/ansible-lint/blob/main/action.yml#L45
4445
mkdir -p "$coll_dir/.git"
46+
meta_req_file="${{ github.workspace }}/meta/collection-requirements.yml"
47+
test_req_file="${{ github.workspace }}/tests/collection-requirements.yml"
48+
if [ -f "$meta_req_file" ] && [ -f "$test_req_file" ]; then
49+
coll_req_file="${{ github.workspace }}/req.yml"
50+
python -c 'import sys; import yaml
51+
hsh1 = yaml.safe_load(open(sys.argv[1]))
52+
hsh2 = yaml.safe_load(open(sys.argv[2]))
53+
coll = {}
54+
for item in hsh1["collections"] + hsh2["collections"]:
55+
if isinstance(item, dict):
56+
name = item["name"]
57+
rec = item
58+
else:
59+
name = item # assume string
60+
rec = {"name": name}
61+
if name not in coll:
62+
coll[name] = rec
63+
hsh1["collections"] = list(coll.values())
64+
yaml.safe_dump(hsh1, open(sys.argv[3], "w"))' "$meta_req_file" "$test_req_file" "$coll_req_file"
65+
echo merged "$coll_req_file"
66+
cat "$coll_req_file"
67+
elif [ -f "$meta_req_file" ]; then
68+
coll_req_file="$meta_req_file"
69+
elif [ -f "$test_req_file" ]; then
70+
coll_req_file="$test_req_file"
71+
else
72+
coll_req_file=""
73+
fi
74+
echo "coll_req_file=$coll_req_file" >> $GITHUB_OUTPUT
4575
4676
- name: Run ansible-lint
47-
uses: ansible/ansible-lint@v24
77+
uses: ansible/ansible-lint@v25
4878
with:
4979
working_directory: ${{ github.workspace }}/.tox/ansible_collections/${{ env.LSR_ROLE2COLL_NAMESPACE }}/${{ env.LSR_ROLE2COLL_NAME }}
80+
requirements_file: ${{ steps.collection.outputs.coll_req_file }}

0 commit comments

Comments
 (0)