Skip to content

Commit

Permalink
ci: add ansible-lint workflow
Browse files Browse the repository at this point in the history
Add a simple workflow to run ansible-lint on push and for pull requests.

ansible-lint requires a "ansible_collections/<namespace>/<name>/"
structure to recognize the collection and its bits, so check out the
code in that way. Also export few environment variables to locate all
the bits.

Sadly currently (ansible-lint v6.22.0) the action does not respect its
"working_directory" for all the steps, failing in its initial setup
steps; a potential fix has been proposed [1], so create a local
workaround to get the action to run in the meanwhile.

[1] ansible/ansible-lint#3905

Signed-off-by: Pino Toscano <[email protected]>
  • Loading branch information
ptoscano committed Nov 23, 2023
1 parent 6f39cc7 commit f482eb7
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
name: ansible-lint
on: # yamllint disable-line rule:truthy
push:
branches:
- main
- master
pull_request:

jobs:
ansibe-lint:
name: Ansible Lint
runs-on: ubuntu-latest
steps:

# ansible-lint requires the collection to be in a directory in the form
# .../ansible_collections/NAMESPACE/COLLECTION_NAME/

- name: Check out code
uses: actions/checkout@v4
with:
path: ansible_collections/redhat/insights

- name: Workaround ansible-lint action bug
run: |
# create a symlink to the .git directory of the checkout
# in the local directory: the current ansible-lint action (v6.22.0)
# does not use its "working_directory" for all its steps;
# https://github.com/ansible/ansible-lint/pull/3905
ln -s ansible_collections/redhat/insights/.git .
- name: Set Ansible environment variables (#1)
run: |
echo "ANSIBLE_COLLECTIONS_PATH=$PWD" >> "$GITHUB_ENV"
- name: Set Ansible environment variables (#2)
# yamllint disable rule:line-length
run: |
echo "ANSIBLE_ACTION_PLUGINS=$PWD/plugins/action" >> "$GITHUB_ENV"
echo "ANSIBLE_INVENTORY_PLUGINS=$PWD/plugins/inventory" >> "$GITHUB_ENV"
echo "ANSIBLE_LIBRARY=$PWD/plugins/modules" >> "$GITHUB_ENV"
# yamllint enable rule:line-length
working-directory: ansible_collections/redhat/insights

- name: Run ansible-lint
uses: ansible/ansible-lint@v6
with:
working_directory: ansible_collections/redhat/insights

0 comments on commit f482eb7

Please sign in to comment.