ansible-collection-prometheus/.github/workflows/ansible-ci.yml
gardar fc426d4d8e
feat(ci): avoid defining supported ansible versions by discovering them from collection
Signed-off-by: gardar <gardar@users.noreply.github.com>
2023-01-13 01:36:41 +00:00

71 lines
2.6 KiB
YAML

---
name: Ansible CI
on: [push, pull_request]
env:
ANSIBLE_FORCE_COLOR: true
jobs:
ansible-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Lint collection
uses: ansible/ansible-lint-action@main
discover-ansible-versions:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.supported-ansible-versions.outputs.result }}
steps:
- uses: actions/checkout@v3
- name: Get Ansible versions that the collection supports
id: supported-ansible-versions
uses: mikefarah/yq@master
with:
cmd: yq -o json -I=0 '.requires_ansible | split(",") | .[] |= sub("(.*)", "stable-${1}")' meta/runtime.yml
ansible-test-sanity:
uses: ./.github/workflows/ansible-test-sanity.yml
needs:
- ansible-lint
- discover-ansible-versions
with:
ansible-core-versions: ${{ needs.discover-ansible-versions.outputs.versions }}
discover-ansible-tests:
runs-on: ubuntu-latest
needs: ansible-lint
outputs:
molecule-tests: ${{ steps.set-tests.outputs.ansible-test-molecule }}
integration-tests: ${{ steps.set-tests.outputs.ansible-test-integration }}
steps:
- name: Check out codebase
uses: actions/checkout@v3
- name: Discover tests
id: set-tests
run: |
echo ansible-test-molecule="[`for x in $(find tests/integration/targets -maxdepth 1 -mindepth 1 -type d -iname "molecule-*" -printf "%f\n"); do echo '{"test":\"'"${x}"'\","name":\"'"${x#*-}\"'"}'; done | tr '\n' ',' | sed '$s/,$//'`]" >> $GITHUB_OUTPUT
echo ansible-test-integration="[`for x in $(find tests/integration/targets -maxdepth 1 -mindepth 1 -type d -not -iname "molecule-*" -printf "%f\n"); do echo '{"test":\"'"${x}"'\","name":\"'"${x}\"'"}'; done | tr '\n' ',' | sed '$s/,$//'`]" >> $GITHUB_OUTPUT
ansible-test-molecule:
uses: ./.github/workflows/ansible-test-integration.yml
needs:
- discover-ansible-tests
- discover-ansible-versions
if: needs.discover-ansible-tests.outputs.molecule-tests != '[]'
with:
targets: ${{ needs.discover-ansible-tests.outputs.molecule-tests }}
ansible-core-versions: ${{ needs.discover-ansible-versions.outputs.versions }}
ansible-test-integration:
uses: ./.github/workflows/ansible-test-integration.yml
needs:
- discover-ansible-tests
- discover-ansible-versions
if: needs.discover-ansible-tests.outputs.integration-tests != '[]'
with:
targets: ${{ needs.discover-ansible-tests.outputs.integration-tests }}
ansible-core-versions: ${{ needs.discover-ansible-versions.outputs.versions }}