Håkon Hægland
Håkon Hægland

Reputation: 40718

How to install cpanm with github action workflow with linux runner?

I am not able to install cpanm with this simple workflow:

name: linux-cpanm-test
on: [push, pull_request]
jobs:
  build-dist:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - name: perl info
        run: |
          perl --version
      - name: install cpanm
        run: cpan App::cpanminus
      - name: test cpanm
        run: cpanm -v Path::Tiny

Here is a link to the test repository. As can be seen, cpan App::cpanminus fails with:

Use of uninitialized value $_[0] in substitution (s///) at /usr/share/perl/5.30/File/Basename.pm line 341.
fileparse(): need a valid pathname at /usr/share/perl/5.30/CPAN/FirstTime.pm line 1413.
Error: Process completed with exit code 255.

Any ideas what can be the problem?

Upvotes: 0

Views: 369

Answers (3)

Håkon Hægland
Håkon Hægland

Reputation: 40718

It seems that cpan App::cpanminus tries to install local::lib into /home/runner/perl5/. I tried to bootstrap local::lib manually to $GITHUB_WORKSPACE/perl5 instead. This seems to fix the problem (I am not sure why, but I guess it has to do with permissions):

name: linux-cpanm-test
on: [push, pull_request]
jobs:
  build-dist:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - name: perl info
        run: |
          perl --version
      - name: setup locallib
        run: |
          tempdir=$(mktemp -d)
          cd $tempdir
          wget https://cpan.metacpan.org/authors/id/H/HA/HAARG/local-lib-2.000024.tar.gz
          tar zxvf local-lib-2.000024.tar.gz
          cd local-lib-2.000024
          PERL_LOCAL_LIB_ROOT=$GITHUB_WORKSPACE/perl5
          perl Makefile.PL --bootstrap=$PERL_LOCAL_LIB_ROOT
          make
          make test
          echo "PERL_LOCAL_LIB_ROOT=$PERL_LOCAL_LIB_ROOT" >> $GITHUB_ENV
          echo "PERL5LIB=$PERL_LOCAL_LIB_ROOT/lib/perl5" >> $GITHUB_ENV
          echo "PERL_MB_OPT=--install_base \"$PERL_LOCAL_LIB_ROOT/\"" >> $GITHUB_ENV
          echo "PERL_MM_OPT=INSTALL_BASE=$PERL_LOCAL_LIB_ROOT" >> $GITHUB_ENV
          echo "PATH=$PERL_LOCAL_LIB_ROOT/bin:$PATH" >> $GITHUB_ENV
      - name: install cpanm
        run: cpan App::cpanminus
      - name: test cpanm
        run: cpanm -v Path::Tiny

Here is a link to the new build log, showing that it now works.

Edit:

Here is a simplified workflow file as suggested by @ikegami. This also works:

name: linux-cpanm-test
on: [push, pull_request]
jobs:
  build-dist:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - name: perl info
        run: |
          perl --version
      - name: setup locallib
        run: |
          PERL_LOCAL_LIB_ROOT="$HOME/perl5"
          >>"$GITHUB_ENV" echo "PERL_LOCAL_LIB_ROOT=$PERL_LOCAL_LIB_ROOT"
          >>"$GITHUB_ENV" echo "PERL5LIB=$PERL_LOCAL_LIB_ROOT/lib/perl5"
          >>"$GITHUB_ENV" echo "PERL_MB_OPT=--install_base \"$PERL_LOCAL_LIB_ROOT/\""
          >>"$GITHUB_ENV" echo "PERL_MM_OPT=INSTALL_BASE=$PERL_LOCAL_LIB_ROOT"
          >>"$GITHUB_ENV" echo "PATH=$PERL_LOCAL_LIB_ROOT/bin:$PATH"
      - name: install cpanm
        run: cpan App::cpanminus
      - name: test cpanm
        run: cpanm -v Path::Tiny

Here is the log.

Upvotes: 0

brian d foy
brian d foy

Reputation: 132720

In my Github workflows, I don't use cpan to install cpanminus. I've run into issues with openssl on the ubuntu hosts.

        - name: Install cpanm and multiple modules
          run: |
            curl -L https://cpanmin.us | perl - App::cpanminus
            cpanm --notest ...

But, I also break my workflows for different platforms into separate files. See PerlPowerTools/.github/workflows for instance. That one is not very complicated.

I don't spend the time to try to make them all act like each other—that's too much complexity. I don't want to debug someone's action when it's not doing exactly what I want. Also, when one platform has a problem, I can create a branch and trigger just that platform on that branch. You might be able to do that with a single file runner too, but that's too much complexity for me to want to manage.

Also, I've had lots of spurious failures with CPAN mirrors with a bare call to cpan. I've updated all of my actions to point to the CDN version of CPAN and haven't seen that problem since:

cpan -M https://www.cpan.org ...

And, lately I've been careful to install dependencies first using the "no test" features of either client. This mostly saves a lot of time. After that, I then run the tests for my module:

cpanm --notest ...
cpan -T ...

Upvotes: 2

Dave Cross
Dave Cross

Reputation: 69224

I've been using shogu82148/actions-setup-perl. That installs cpanm for me and I've never had any problems.

The jobs section of my workflow files look like this:

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
        perl: [ 'latest' ]
    name: Perl ${{ matrix.perl }} on ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - name: Set up perl
        uses: shogo82148/actions-setup-perl@v1
        with:
          perl-version: ${{ matrix.perl }}
      - run: perl -V
      - run: cpanm --installdeps .
      - run: prove -lv t

Upvotes: 2

Related Questions