name: windows-latest

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

jobs:
  perl:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - name: Perl version
        run: perl -V
      - name: Perl config
        run: perl -MConfig -MData::Dumper -e 'local $Data::Dumper::Sortkeys = 1;warn Dumper \%Config;'
      - name: Set PATH using GITHUB_PATH
        run: echo "C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
      - name: Show PATH
        run: echo $env:PATH
      - name: Set PERL5LIB
        run: echo "PERL5LIB=$HOME/mylib/lib/perl5;$HOME/mylib/lib/perl5/$(perl -MConfig -e 'print $Config{archname}')" >> $env:GITHUB_ENV
      - name: Show PERL5LIB
        run: echo $env:PERL5LIB
      - name: Download cpanm
        run: perl -0777 -Mstrict -Mwarnings -MIO::Socket::INET -e 'my $socket = IO::Socket::INET->new(  Proto => qq(tcp),  PeerAddr => qq(cpanmin.us),  PeerPort => 80,) or die $!;print $socket join qq(\r\n),  qq(GET / HTTP/1.1),  qq(Connection:close),  qq(Host:cpanmin.us),  qq(\r\n);my $res = <$socket>;$res =~ m(^HTTP/1\.1 200 OK\r\n) or die $res;$res =~ s/.*?\r\n\r\n//s;open my $out, qq(>), qq(cpanm) or die $!;print $out $res'
      - name: cpanm installs ExtUtils::MakeMaker
        run: perl cpanm -v -n -L ~/mylib ExtUtils::MakeMaker
      - name: cpanm installs dependent modules
        run: perl cpanm -v -n -L ~/mylib --installdeps . --configure-args="--meta"
      - name: Show MYMETA.json
        run: cat MYMETA.json
      - run: perl Makefile.PL
      - name: make disttest
        run: |
          $MAKE_JOBS = perl -MJSON::PP -e 'undef $/; $m=decode_json(<>); print $m->{x_parallel_make_jobs} || 1' MYMETA.json
          $TEST_JOBS = perl -MJSON::PP -e 'undef $/; $m=decode_json(<>); print $m->{x_parallel_test_jobs} || 1' MYMETA.json
          echo "MAKE_JOBS: $MAKE_JOBS"
          echo "TEST_JOBS: $TEST_JOBS"
          $env:MAKEFLAGS = "j$MAKE_JOBS"
          $env:HARNESS_OPTIONS = "j$TEST_JOBS"
          gmake disttest
