DEV Community

Cover image for Archiving CPAN logs in GitHub Actions

Archiving CPAN logs in GitHub Actions

davorg profile image Dave Cross ・2 min read

As more and more people have started to use GitHub Actions to test their CPAN modules, a pretty standard version of a basic configuration file has emerged. It looks something like this:

name: CI

    branches: [ master ]
    branches: [ master ]

    runs-on: ${{ matrix.os }}
        os: ['ubuntu-latest', 'macos-latest', 'windows-
        perl: [ 'latest' ]
    name: Perl ${{ matrix.perl }} on ${{ matrix.os }}
      - uses: actions/checkout@v2
      - name: Set up perl
        uses: shogo82148/actions-setup-perl@v1
          perl-version: ${{ matrix.perl }}
      - name: Perl version
        run: perl -V
      - name: Install modules
        run: cpanm --installdeps .
      - name: Run tests
        run: prove -lv t
Enter fullscreen mode Exit fullscreen mode

I've been slowly adding something similar to this to all of the GitHub repos that contain my CPAN modules. And it mostly works pretty well. There are just a few problems that I'm ironing out.

One of them is a problem where some of the required CPAN modules don't install cleanly, so the run is aborted. But I think I've found a tool that is going to help me fix this problem.

You'll see that I use cpanm to install the modules that are required to run the tests. And cpanm writes a detailed log of what it is doing which is invaluable when something goes wrong - as you can get the error messages from the log file. Unfortunately, this doesn't work well in a CI environment like GitHub Actions. All I see in the log of the run is something like this:

Building and testing Inline-C-0.81 ... FAIL
! Installing Inline::C failed. See /home/runner/.cpanm/work/1609767557.4781/build.log for details. 
Retry with --force to force install it.
! Installing the dependencies failed: Module 'Inline::C' is not installed
Enter fullscreen mode Exit fullscreen mode

That build.log file is the one we need to see. But it's on the container that has been used to run your tests, and by the time you're looking at that error, the container has vanished into the ether taking your build log with it.

But we can stop it being removed. GitHub Actions has a feature called "artifacts" where you can store items that are created in a job run so that you can examine them in more detail later on. We can use that to archive our build logs.

I've started adding this step to my GitHub Action config files:

- name: Archive CPAN logs
  if: ${{ failure() }}
  uses: actions/upload-artifact@v2
    name: cpan_log
    path: .cpanm/work/*/build.log
Enter fullscreen mode Exit fullscreen mode

This adds another step into my process. It only runs if another step fails in some way. It uses the standard action actions/upload-artifact@v2 to archive my build logs. Now, when something goes wrong in my tests the job page will have a link labelled "cpan_log" which I can click on to download a copy of the cpanm build log which I can then examine at my leisure to work out what the problem is.

Now I just need to add this to all of my existing CI workflows so that I can start to fix some of the issues I can see on my CPAN Dashboard.

Discussion (2)

Editor guide
thibaultduponchelle profile image
Tib • Edited

Your solution is elegant and I learnt something, thank you 👍

There is also another (elegant) solution, the --show-build-log-on-failure option of cpm handles this use case :

cpm install Your:Module --show-build-log-on-failure
Enter fullscreen mode Exit fullscreen mode

Along with speed, this is one of the two killer features of cpm for me !

szabgab profile image
Gabor Szabo

Nice. I am not sure if it is important, but you might also want to set the retention policy to something short so these log will be removed after a short period of time.

retention-days: 5