on:
  push:
    branches:
      - '*'
    tags-ignore:
      - '*'
  pull_request:

env:
  PERL_USE_UNSAFE_INC: 0
  AUTHOR_TESTING: 1
  AUTOMATED_TESTING: 1
  RELEASE_TESTING: 1
  PERL_CARTON_PATH: $GITHUB_WORKSPACE/local

jobs:
  linux-redhat:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        os:
          - image: fedora
            rpms: ''
          - image: almalinux:9
            rpms: gmp-devel

    container:
      image: ${{ matrix.os.image }}

    steps:
      - uses: actions/checkout@main

      # Omit GMP so we test pure-Perl:
      - run: dnf -y install perl-App-cpanminus openssl ${{ matrix.os.rpms }}

      - name: perl -V
        run: perl -V
      - name: Install Dependencies
        run: cpanm --verbose --notest --installdeps --with-configure --with-recommends .
      - name: perl Makefile.PL
        run: perl Makefile.PL
      - name: make
        run: make
      - name: Run Tests
        run: prove -wlvmb t

  linux-ubuntu:

    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        perl-version:
          - '5.36'
          - '5.34'
          - '5.32'
          - '5.30'
          - '5.28'
          - '5.26'
          - '5.24'
          - '5.22'
          - '5.20'
          - '5.18'
          - '5.16'
          - '5.14'
          - '5.12'
          - '5.10'
          - '5.8'

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

    steps:
      - uses: actions/checkout@v2
      - run: apt install -y libgmp3-dev openssl
      - name: perl -V
        run: perl -V
      - name: Install Dependencies
        run: cpanm --notest --installdeps --with-configure --with-recommends .
      - name: perl Makefile.PL
        run: perl Makefile.PL
      - name: make
        run: make
      - name: Run Tests
        run: prove -wlvmb t

#----------------------------------------------------------------------
  mac:

    runs-on: macOS-latest

    steps:
      - uses: actions/checkout@main
      - name: Set up Perl
        run: brew install perl cpanminus
      - name: perl -V
        run: perl -V
      - name: Install dependencies
        run: cpanm --notest --installdeps --with-configure --with-recommends .
      - name: perl Makefile.PL
        run: perl Makefile.PL
      - name: make
        run: make
      - name: Run tests (with coverage)
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          curl -L https://cpanmin.us | perl - --notest Devel::Cover::Report::Coveralls
          `perl -MConfig -E'print $Config::Config{"sitebin"}'`/cover -test -report Coveralls

#----------------------------------------------------------------------
  windows:

    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up Perl
        run: |
          choco install strawberryperl
          echo "C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin" >> $GITHUB_PATH
      - name: perl -V
        run: perl -V
      - name: Install Dependencies
        run: curl -L https://cpanmin.us | perl - --notest --with-recommends --with-configure --installdeps .
      - name: perl Makefile.PL
        run: perl Makefile.PL
      - name: make
        run: make
      - name: Run Tests
        run: make test

#----------------------------------------------------------------------
  cygwin:
    runs-on: windows-latest

    steps:
      - name: Set up Cygwin
        uses: egor-tensin/setup-cygwin@master
        with:
            platform: x64
            packages: perl_base perl-ExtUtils-MakeMaker make gcc-g++ libcrypt-devel libgmp-devel bash
      - uses: actions/checkout@v2
      - run: perl -V
        shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}'
      - run: cpan App::cpanminus
        shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}'
      - name: Install Dependencies
        run: cd $GITHUB_WORKSPACE; cpanm --verbose --notest --installdeps --with-configure --with-recommends .
        shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}'
      - name: perl Makefile.PL
        run: cd $GITHUB_WORKSPACE; perl Makefile.PL
        shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}'
      - name: make test
        run: cd $GITHUB_WORKSPACE; make test
        shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}'