---
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:edge
                    - alpine:busybox-edge
                    - arch:latest
                    - debian:latest
                    - fedora:latest
                    - gentoo:latest
                    - opensuse:latest
                    - ubuntu:devel
                    - void:latest
                test:
                    - "10"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v6
            - 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
        container:
            image: ubuntu:devel
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v6
            - name: Install dependencies
              run: apt-get update && apt-get -y install make shellcheck shfmt
            - run: 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:devel
                    - void:latest
                test:
                    - "11"
                    - "12"
                    - "13"
                    - "14"
                    - "20"
                    - "21"
                    - "26"
                    - "30"
                    - "50"
                    - "80"
                    - "81"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v6
            - 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:devel
                test:
                    - "40"
                    - "41"
                    - "42"
                    - "43"
                    - "44"
                    - "45"
                exclude:
                    # https://github.com/dracut-ng/dracut-ng/issues/1677
                    - container: arch:latest
                      test: "41"
                    # TEST-45-SYSTEMD-IMPORT requires systemd >= v258
                    - container: opensuse:latest
                      test: "45"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm --privileged'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v6
            - 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 }}
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v6
            - 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
                    - fedora:latest
                    - opensuse:latest
                    - ubuntu:devel
                test:
                    - "31"
                    - "60"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v6
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: >
                USE_NETWORK=${{ matrix.network }}
                ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    network-iscsi:
        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:
                network:
                    - network-manager
                container:
                    - debian:latest
                    - ubuntu:devel
                test:
                    - "70"
                    - "71"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v6
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: >
                USE_NETWORK=${{ matrix.network }}
                ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    network-nbd:
        needs: basic
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-24.04
        timeout-minutes: 20
        concurrency:
            group: >
                network-nbd-${{ github.workflow }}-${{ github.ref }}
                -${{ matrix.container }}-${{ matrix.test }}-${{ matrix.network }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container:
                    - arch:latest
                    - debian:latest
                    - opensuse:latest
                test:
                    - "72"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v6
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: >
                USE_NETWORK=${{ matrix.network }}
                ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    arm64:
        needs: basic
        name: ${{ matrix.test }} on ${{ matrix.container }} on arm64
        runs-on: ubuntu-24.04-arm
        timeout-minutes: 20
        concurrency:
            group: >
                arm64-${{ github.workflow }}-${{ github.ref }}
                -${{ matrix.container }}-${{ matrix.test }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container:
                    - debian:latest
                    - opensuse:latest
                    - ubuntu:rolling
                    - void:latest
                test:
                    - "10"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm --privileged'
        steps:
            - name: "Checkout Repository"
              uses: actions/checkout@v6
            - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
              run: ./test/test-container.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
