Skip to content

Commit a816912

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. We have to remove mock_modules that are actually present now. Signed-off-by: Rich Megginson <[email protected]>
1 parent 93d8927 commit a816912

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

.github/workflows/ansible-lint.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,48 @@ jobs:
3535
pip3 install "git+https://github.com/linux-system-roles/[email protected]"
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"
43+
# cleanup after collection conversion
44+
rm -rf "$coll_dir/.ansible" .tox/ansible-plugin-scan
4245
# ansible-lint action requires a .git directory???
4346
# https://github.com/ansible/ansible-lint/blob/main/action.yml#L45
4447
mkdir -p "$coll_dir/.git"
48+
meta_req_file="${{ github.workspace }}/meta/collection-requirements.yml"
49+
test_req_file="${{ github.workspace }}/tests/collection-requirements.yml"
50+
if [ -f "$meta_req_file" ] && [ -f "$test_req_file" ]; then
51+
coll_req_file="${{ github.workspace }}/req.yml"
52+
python -c 'import sys; import yaml
53+
hsh1 = yaml.safe_load(open(sys.argv[1]))
54+
hsh2 = yaml.safe_load(open(sys.argv[2]))
55+
coll = {}
56+
for item in hsh1["collections"] + hsh2["collections"]:
57+
if isinstance(item, dict):
58+
name = item["name"]
59+
rec = item
60+
else:
61+
name = item # assume string
62+
rec = {"name": name}
63+
if name not in coll:
64+
coll[name] = rec
65+
hsh1["collections"] = list(coll.values())
66+
yaml.safe_dump(hsh1, open(sys.argv[3], "w"))' "$meta_req_file" "$test_req_file" "$coll_req_file"
67+
echo merged "$coll_req_file"
68+
cat "$coll_req_file"
69+
elif [ -f "$meta_req_file" ]; then
70+
coll_req_file="$meta_req_file"
71+
elif [ -f "$test_req_file" ]; then
72+
coll_req_file="$test_req_file"
73+
else
74+
coll_req_file=""
75+
fi
76+
echo "coll_req_file=$coll_req_file" >> $GITHUB_OUTPUT
4577
4678
- name: Run ansible-lint
47-
uses: ansible/ansible-lint@v24
79+
uses: ansible/ansible-lint@v25
4880
with:
4981
working_directory: ${{ github.workspace }}/.tox/ansible_collections/${{ env.LSR_ROLE2COLL_NAMESPACE }}/${{ env.LSR_ROLE2COLL_NAME }}
82+
requirements_file: ${{ steps.collection.outputs.coll_req_file }}

0 commit comments

Comments
 (0)