---
name: Ansible Test
on:  # yamllint disable-line rule:truthy
  pull_request:
  merge_group:
    branches:
      - main
    types:
      - checks_requested
  push:
    branches:
      - main
  workflow_dispatch:
env:
  LSR_ROLE2COLL_NAMESPACE: fedora
  LSR_ROLE2COLL_NAME: linux_system_roles
permissions:
  contents: read
jobs:
  ansible_test:
    runs-on: ubuntu-latest
    steps:
      - name: Update pip, git
        run: |
          set -euxo pipefail
          python3 -m pip install --upgrade pip
          sudo apt update
          sudo apt install -y git

      - name: Checkout repo
        uses: actions/checkout@v6

      - name: Install tox, tox-lsr
        run: |
          set -euxo pipefail
          pip3 install "git+https://github.com/linux-system-roles/tox-lsr@3.14.0"

      - name: Convert role to collection format
        run: |
          set -euxo pipefail
          TOXENV=collection lsr_ci_runtox

      - name: Run ansible-test
        uses: ansible-community/ansible-test-gh-action@release/v1
        with:
          testing-type: sanity  # wokeignore:rule=sanity
          ansible-core-version: stable-2.17
          collection-src-directory: ${{ github.workspace }}/.tox/ansible_collections/${{ env.LSR_ROLE2COLL_NAMESPACE }}/${{ env.LSR_ROLE2COLL_NAME }}
