name: zfs-linux

on:
  push:
  pull_request:

jobs:

  build:
    name: Build
    strategy:
      fail-fast: false
      matrix:
        os: [20.04, 22.04]
    runs-on: ubuntu-${{ matrix.os }}
    steps:
    - uses: actions/checkout@v4
      with:
        ref: ${{ github.event.pull_request.head.sha }}
    - name: Build modules
      run: .github/workflows/scripts/setup-dependencies.sh build
    - name: Prepare modules upload
      run: tar czf modules-${{ matrix.os }}.tgz *.deb .github tests/test-runner tests/ImageOS.txt
    - uses: actions/upload-artifact@v4
      with:
        name: modules-${{ matrix.os }}
        path: modules-${{ matrix.os }}.tgz
        retention-days: 14

  testings:
    name: Testing
    strategy:
      fail-fast: false
      matrix:
        os: [20.04, 22.04]
    needs: build
    uses: ./.github/workflows/zfs-linux-tests.yml
    with:
      os: ${{ matrix.os }}

  cleanup:
    if: always()
    name: Cleanup
    runs-on: ubuntu-22.04
    needs: testings
    steps:
    - uses: actions/download-artifact@v4
    - name: Generating summary
      run: |
        tar xzf modules-22.04/modules-22.04.tgz .github tests
        .github/workflows/scripts/generate-summary.sh
    # up to 4 steps, each can have 1 MiB output (for debugging log files)
    - name: Summary for errors #1
      run: .github/workflows/scripts/generate-summary.sh 1
    - name: Summary for errors #2
      run: .github/workflows/scripts/generate-summary.sh 2
    - name: Summary for errors #3
      run: .github/workflows/scripts/generate-summary.sh 3
    - name: Summary for errors #4
      run: .github/workflows/scripts/generate-summary.sh 4
    - uses: actions/upload-artifact@v4
      with:
        name: Summary Files
        path: Summary/
