name: Integration Test

on:
    pull_request:
        branches: [ main ]

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-latest
        timeout-minutes: 30
        concurrency:
            group: basic-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container: [
                        "alpine",
                        "arch",
                        "debian",
                        "fedora",
                        "gentoo",
                        "opensuse",
                        "ubuntu",
                        "void",
                ]
                test: [
                        "01",
                ]
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm'
        steps:
            -   name: "Checkout Repository"
                uses: actions/checkout@v4
            -   name: "${{ matrix.container }} TEST-${{ matrix.test }}"
                run: ./test/test-github.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    extended:
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-latest
        timeout-minutes: 30
        concurrency:
            group: extended-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container: [
                        "alpine",
                        "arch",
                        "debian",
                        "fedora",
                        "gentoo",
                        "opensuse",
                        "ubuntu",
                        "void",
                ]
                test: [
                        "02",
                        "03",
                        "04",
                        "05",
                        "10",
                        "11",
                        "12",
                        "13",
                        "14",
                        "15",
                        "16",
                        "17",
                        "18",
                        "62",
                        "98",
                ]
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm'
        steps:
            -   name: "Checkout Repository"
                uses: actions/checkout@v4
            -   name: "${{ matrix.container }} TEST-${{ matrix.test }}"
                run: ./test/test-github.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    dracut-cpio:
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-latest
        timeout-minutes: 30
        concurrency:
            group: dracut-cpio-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container: [
                        "opensuse",
                ]
                test: [
                        "63",
                ]
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            options: '--device=/dev/kvm'
        steps:
            -   name: "Checkout Repository"
                uses: actions/checkout@v4
            -   name: "${{ matrix.container }} TEST-${{ matrix.test }}"
                run: ./test/test-github.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    arm64:
        name: ${{ matrix.test }} on ${{ matrix.container }} on arm64
        runs-on: ubuntu-latest
        timeout-minutes: 30
        concurrency:
            group: arm64-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container: [
                        "debian",
                        "fedora",
                ]
                test: [
                        "98",
                ]
        steps:
            -   name: Set up QEMU
                uses: docker/setup-qemu-action@v3
                with:
                    platforms: 'linux/arm64'
            -   name: "Checkout Repository"
                uses: actions/checkout@v4
            -   name: "${{ matrix.container }} TEST-${{ matrix.test }}"
                run: docker run --platform linux/arm64 '--device=/dev/kvm' -v $PWD:/w ghcr.io/dracut-ng/${{ matrix.container }} /w/test/test-github.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    network:
        # all nfs based on default networking
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-latest
        timeout-minutes: 45
        concurrency:
            group: network-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}-${{ matrix.network }}
            cancel-in-progress: true
        strategy:
            fail-fast: false
            matrix:
                container: [
                        "arch",
                        "debian",
                        "fedora",
                        "gentoo",
                        "opensuse",
                        "ubuntu",
                ]
                test: [
                        "20",
                        "50",
                        "60",
                ]
                include:
                  - network: ""
                  - # on debian run tests with systemd-networkd
                    container: "debian"
                    network: "systemd-networkd"
                  - # on openSUSE run tests with network-legacy
                    container: "opensuse"
                    network: "network-legacy"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            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-github.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    network-iscsi:
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-latest
        timeout-minutes: 45
        concurrency:
            group: network-iscsi-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}-${{ matrix.network }}
            cancel-in-progress: true
        strategy:
            # run tests sequentially
            max-parallel: 1
            fail-fast: false
            matrix:
                container: [
                        "arch",
                        "debian",
                        "fedora",
                        "gentoo",
                        "opensuse",
                        "ubuntu",
                ]
                test: [ "30","35" ]
                include:
                  - network: ""
                  - # on debian run tests with systemd-networkd
                    container: "debian"
                    network: "systemd-networkd"
                  - # on openSUSE run tests with network-legacy
                    container: "opensuse"
                    network: "network-legacy"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            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-github.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
    network-nbd:
        name: ${{ matrix.test }} on ${{ matrix.container }}
        runs-on: ubuntu-latest
        timeout-minutes: 45
        concurrency:
            group: network-nbd-${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}-${{ matrix.network }}
            cancel-in-progress: true
        strategy:
            # run tests sequentially
            max-parallel: 1
            fail-fast: false
            matrix:
                container: [
                        "arch",
                        "debian",
                        "fedora",
                        "opensuse",
                ]
                test: [ "40" ]
                include:
                  - network: ""
                  - # on openSUSE run tests with network-legacy
                    container: "opensuse"
                    network: "network-legacy"
                  - # on debian run this test on network-legacy to be able to pass it
                    container: "debian"
                    network: "network-legacy"
        container:
            image: ghcr.io/dracut-ng/${{ matrix.container }}
            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-github.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
