---
name: Integration Test

on:  # yamllint disable-line rule:truthy
    pull_request:
        branches: [main]
        paths-ignore:
            - antora-playbook.yaml
            - 'doc_site/**'
            - 'man/**'

    # Allows you to run this workflow manually from the Actions tab
    workflow_dispatch:

env:
    # set V to 2 when re-running jobs with debug logging enabled
    # see https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging
    V: "${{ secrets.ACTIONS_STEP_DEBUG && '2' }}"

jobs:
    basic:
        # run this test on all containers
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-24.04
        timeout-minutes: 20
        concurrency:
            group: basic-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container:
                    - alpine:latest
                    - arch:latest
                    - debian:latest
                    - fedora:latest
                    - gentoo:latest
                    - opensuse:latest
                    - ubuntu:rolling
                    - void:latest
                test:
                    - "10"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}-amd
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v4
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}

    # syncheck
    syncheck:
        needs: basic
        name: syncheck
        runs-on: ubuntu-24.04
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v4
            - run: |
                  sudo apt-get update
                  sudo apt-get -y install shellcheck shfmt
                  make syncheck

    extended:
        needs: basic
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-24.04
        timeout-minutes: 20
        concurrency:
            group: extended-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container:
                    - arch:latest
                    - fedora:latest
                    - gentoo:latest
                    - opensuse:latest
                    - ubuntu:rolling
                    - void:latest
                test:
                    - "11"
                    - "12"
                    - "20"
                    - "23"
                    - "26"
                    - "30"
                    - "80"
                    - "81"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}-amd
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v4
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}

    extended-systemd:
        needs: basic
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-24.04
        timeout-minutes: 20
        concurrency:
            group: extended-systemd-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container:
                    - arch:latest
                    - fedora:latest
                    - gentoo:latest
                    - opensuse:latest
                    - ubuntu:rolling
                test:
                    - "40"
                    - "41"
                    - "42"
                    - "43"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}-amd
            options: '--device=/dev/kvm --privileged'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v4
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}

    dracut-cpio:
        needs: basic
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-24.04
        timeout-minutes: 20
        concurrency:
            group: dracut-cpio-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container:
                    - opensuse:latest
                test:
                    - "82"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}-amd
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v4
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    network:
        needs: basic
        # all nfs based on default networking
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-24.04
        timeout-minutes: 20
        concurrency:
            group: network-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}-${{ matrix.network }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container:
                    - arch:latest
                    - debian:latest
                    - fedora:latest
                    - gentoo:latest
                    - opensuse:latest
                    - ubuntu:rolling
                test:
                    - "60"
                    - "61"
                    - "62"
                include:
                    - network: ""
                    # on debian run tests with systemd-networkd
                    - container: "debian:latest"
                      network: "systemd-networkd"
                    # on openSUSE run tests with network-legacy
                    - container: "opensuse:latest"
                      network: "network-legacy"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}-amd
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v4
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: USE_NETWORK=${{ matrix.network }} ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    network-advanced:
        needs: basic
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-24.04
        timeout-minutes: 20
        concurrency:
            group: network-iscsi-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}-${{ matrix.network }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container:
                    - opensuse:latest
                test:
                    - "70"
                include:
                    # on openSUSE run tests with network-legacy
                    - container: "opensuse:latest"
                      network: "network-legacy"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}-amd
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v4
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: USE_NETWORK=${{ matrix.network }} ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
