---
name: Run Tests

# yamllint disable-line rule:truthy
on:
  push:
    branches:
      - "**"
  pull_request:
  workflow_dispatch:

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ macos-latest, windows-latest ]
        perl: [ "5" ]
        include:
          - { os: "ubuntu-latest", perl: "5.26" }
          - { os: "ubuntu-latest", perl: "5.28" }
          - { os: "ubuntu-latest", perl: "5.30" }
          - { os: "ubuntu-latest", perl: "5.32" }
          - { os: "ubuntu-latest", perl: "5.34" }
          - { os: "ubuntu-latest", perl: "5.36" }
          - { os: "ubuntu-latest", perl: "5.38" }
          - { os: "ubuntu-latest", perl: "5.40" }
          - { os: "ubuntu-latest", perl: "5.42" }
          - { os: "ubuntu-latest", perl: "5.42", perl-threaded: true }

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up perl
        uses: shogo82148/actions-setup-perl@v1
        if: matrix.os != 'windows-latest'
        with:
          perl-version: ${{ matrix.perl }}
          multi-thread: ${{ matrix.perl-threaded }}
      - name: Set up perl (Strawberry)
        uses: shogo82148/actions-setup-perl@v1
        if: matrix.os == 'windows-latest'
        with:
          distribution: "strawberry"

      - run: perl -V

      - name: Install Dist::Zilla
        run: cpanm --notest Dist::Zilla

      - name: Install author dependencies
        run: dzil authordeps --missing | cpanm --notest

      - name: Build distribution
        run: dzil build --in build-dir

      - name: Install dependencies and test
        run: |
          cd build-dir
          cpanm --notest --installdeps .
          cpanm --verbose --test-only .
