perl-actions / install-with-cpanm

GitHub action to install Perl Modules using App::cpanm
14 stars 3 forks source link

Make caching of installed modules easier #2

Closed rra closed 7 months ago

rra commented 4 years ago

I spent some time this evening adding caching of modules installed with this action to one of my projects (rra/rra-c-util). The cache action doesn't support running with sudo, so this required disabling sudo and installing into the local::lib path, which isn't ideal, but it seems to work.

I had to add some inobvious configuration to the action that would be easier if it were encapsulated in a configuration option. Specifically, I needed:

      - uses: perl-actions/install-with-cpanm@v1.1
        env:
          PERL5LIB: ${{ env.HOME }}/perl5
        with:
          args: "--local-lib=~/perl5"
          path: /usr/bin/cpanm
          sudo: false

to make everything work. Setting PERL5LIB was inobvious (cpanm --local-lib=~/perl5 does not set that variable and thus installation of modules that have dependencies that also have to be installed fails), as was needing to pre-install cpanminus with apt-get and then set path. I think the latter is because the default path cannot be written to without using sudo, and maybe there's an easier approach.

Would you be willing to add something like:

with:
  local-lib: ~/perl5

that sets both args and the environment variable (after tilde expansion)? Or even a boolean that always uses ~/perl5, since that's what local::lib wants. An option to use the pre-installed cpanm or maybe just switch to a different path when sudo: false would also be useful.

For the record, here's the full working workflow with caching:

jobs:
  build:
    runs-on: ubuntu-latest

    env:
      AUTHOR_TESTING: 1
      C_TAP_VERBOSE: 1

    steps:
      - uses: actions/checkout@v2
      - name: install
        run: sudo -E ci/install
      - name: Get Perl version
        id: get-perl
        run: |
          perl -e 'print "::set-output name=version::", $^V, "\n"'
      - name: Cache Perl modules
        uses: actions/cache@v2
        with:
          path: ~/perl5
          key: ${{ runner.os }}-perl-${{ steps.get-perl.outputs.version }}-${{ hashFiles('ci/cpanfile') }}
          restore-keys: |
            ${{ runner.os }}-perl-${{ steps.get-perl.outputs.version }}-
      - uses: perl-actions/install-with-cpanm@v1.1
        env:
          PERL5LIB: ${{ env.HOME }}/perl5
        with:
          args: "--local-lib=~/perl5"
          cpanfile: ci/cpanfile
          path: /usr/bin/cpanm
          sudo: false
      - name: test
        run: ci/test
oalders commented 2 years ago

@rra did you want to send a pull request for this?

oalders commented 7 months ago

@atoomic do we need a new release for this?

atoomic commented 7 months ago

@oalders Yeap we need a new release, was considering performing some cleanup and release during PTS but can probably find some time earlier if needed

oalders commented 7 months ago

No hurry. PTS seems like a good place for this.