name: Perl Tests

on:
  push:
    branches-ignore:
      - 'exp-**'
      - 'exp/**'
  pull_request:
    branches-ignore:
      - 'exp-**'
      - 'exp/**'

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        os: [[% FOREACH o IN github.use_ci.runners %] [% o %], [% END %]]
        perl: [ '[% short_min_perl_version %]', '5.38' ]
        exclude:
          # MacOS runners are very expensive, so let’s run only on the latest Perl
          - os: macos
            perl: '[% short_min_perl_version %]'

        # From time to time, Strawberry Perl does not have the latest Perl
        # version. So these lines can be uncommented to remove it (and replace
        # it with another version in the include section below).
        # Currently Strawberry Perl has 5.38
        #   - os: windows
        #     perl: '5.38'
        # include:
        #   - os: windows
        #     perl: '5.32'

    runs-on: ${{matrix.os}}-latest
    name: Perl ${{matrix.perl}} ${{matrix.os}}

    steps:
    - uses: actions/checkout@v4

    - name: Set up perl
      uses: shogo82148/actions-setup-perl@v1
      with:
          perl-version: ${{ matrix.perl }}
          distribution: ${{ ( matrix.os == 'windows'  && 'strawberry' ) || 'default' }}

    - name: Show Perl Version
      run: |
        perl -v

    - name: Install aspell
      if:  ${{ matrix.os == 'ubuntu' }}
      run: |
        sudo apt-get install aspell

    - name: Install Modules
      if:  ${{ matrix.os != 'macos' }}
      run: |
        cpanm -V
        cpanm -v --installdeps --notest --with-configure --with-recommends --with-suggests --with-all-features [% FOREACH f IN github.use_ci.excluded_features %]--without-feature [% f %] [% END %].

    # MacOS runners are very costly, so let’s install the minimum amount of
    # dependency.
    - name: Install Modules on MacOS
      if:  ${{ matrix.os == 'macos' }}
      run: |
        cpanm -V
        cpanm -v --installdeps --notest --with-configure --without-recommends --without-suggests .

    - name: Run tests on Linux
      if:  ${{ matrix.os == 'ubuntu' }}
      env:
        AUTOMATED_TESTING: 1
        NONINTERACTIVE_TESTING: 1
        EXTENDED_TESTING: 1
        RELEASE_TESTING: 1
      run: |
        perl Makefile.PL
        make
        make test

    # MacOS runners are very costly, so let’s not run the EXTENDED_TESTING
    # tests, to save some cost.
    - name: Run tests on MacOS
      if:  ${{ matrix.os == 'macos' }}
      env:
        AUTOMATED_TESTING: 1
        NONINTERACTIVE_TESTING: 1
        RELEASE_TESTING: 1
      run: |
        perl Makefile.PL
        make
        make test  

    # On Windows there is no 'make' command. It seems that Makefile.PL defaults
    # to using 'dmake' which is maybe installed on the GitHub VMs. However we
    # know that there is a 'gmake' included with Strawberry Perl, so let’s use
    # that one.
    - name: Run tests on Windows
      if:  ${{ matrix.os == 'windows' }}
      env:
        AUTOMATED_TESTING: 1
        NONINTERACTIVE_TESTING: 1
        RELEASE_TESTING: 1
      run: |
        perl Makefile.PL MAKE=gmake
        gmake
        gmake test

    - name: Show Errors on Linux
      if:  ${{ failure() && matrix.os == 'ubuntu' }}
      run: |
         cat /home/runner/.cpanm/work/*/build.log

    - name: Show Errors on Windows
      if:  ${{ failure() && matrix.os == 'windows' }}
      run: |
         ls -l C:/Users/
         ls -l C:/Users/RUNNER~1/
         cat C:/Users/runneradmin/.cpanm/work/*/build.log

    - name: Show Errors on MacOS
      if:  ${{ failure() && matrix.os == 'macos' }}
      run: |
         cat  /Users/runner/.cpanm/work/*/build.log