name: testsuite

on: [push, pull_request]

jobs:
  ubuntu:
    env:
      PERL_USE_UNSAFE_INC: 0
      AUTHOR_TESTING: 1
      AUTOMATED_TESTING: 1
      RELEASE_TESTING: 1

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - run: perl -V
      - name: install cpan deps
        uses: perl-actions/install-with-cpm@v1
        with:
          install: |
            Crypt::OpenSSL::Guess
            Test::More
            Time::HiRes
            Test::CPAN::Meta
            Test::Pod
            Test::Pod::Coverage
            Test::CPAN::Changes
            Test::CheckChanges
            Class::XSAccessor
            Text::CSV_XS
            List::MoreUtils
            Test::Kwalitee
      - run: perl Makefile.PL
      - run: make test

  perl-versions:
    runs-on: ubuntu-latest
    name: List Perl versions
    outputs:
      perl-versions: ${{ steps.action.outputs.perl-versions }}
    steps:
      - id: action
        uses: perl-actions/perl-versions@v1
        with:
          since-perl: v5.8
          with-devel: true

  linux:
    name: "perl ${{ matrix.perl-version }}"
    needs:
      - ubuntu
      - perl-versions
    env:
      PERL_USE_UNSAFE_INC: 0
      AUTOMATED_TESTING: 1
      AUTHOR_TESTING: 0
      RELEASE_TESTING: 0

    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        perl-version: ${{ fromJson (needs.perl-versions.outputs.perl-versions) }}

    container:
      image: perldocker/perl-tester:${{ matrix.perl-version }}

    steps:
      - uses: actions/checkout@v4
      - run: perl -V
      - name: install cpan deps
        uses: perl-actions/install-with-cpm@v1
        with:
          sudo: false
          install: |
            Crypt::OpenSSL::Guess
            Test::More
            Time::HiRes
      - run: perl Makefile.PL
      - run: make test

  macOS:
    needs: [ubuntu]
    env:
      PERL_USE_UNSAFE_INC: 0
      AUTOMATED_TESTING: 1
      AUTHOR_TESTING: 0
      RELEASE_TESTING: 0

    runs-on: macOS-latest

    strategy:
      fail-fast: false
      matrix:
        perl-version: [latest]

    steps:
      - uses: actions/checkout@v4
      - run: perl -V
      - name: install cpan deps
        uses: perl-actions/install-with-cpm@v1
        with:
          sudo: false
          install: |
            Crypt::OpenSSL::Guess
      - run: perl Makefile.PL
      - run: make test

  windows:
    needs: [ubuntu]
    env:
      PERL_USE_UNSAFE_INC: 0
      AUTOMATED_TESTING: 1
      AUTHOR_TESTING: 0
      RELEASE_TESTING: 0
      VCPKG_DEFAULT_TRIPLET: x64-windows

    runs-on: windows-latest

    strategy:
      fail-fast: false
      matrix:
        perl-version: [latest]

    steps:
      - uses: actions/checkout@v4
      - run: perl -V
      - run: perl Makefile.PL
      - run: echo $PATH
        shell: bash
      #- run: prove -vb t/*.t
      # https://github.com/actions/runner-images/issues/5459
      - run: PATH="/c/Strawberry/c/bin:/c/Strawberry/perl/site/bin:/c/Strawberry/perl/bin:/c/ProgramData/Chocolatey/bin:/c/Windows/system32:/c/Windows:/usr/bin:/c/mingw64/bin" make test
        shell: bash
        #continue-on-error: true