DEV Community

Cover image for A tour of Perl Github actions
Tib
Tib

Posted on

A tour of Perl Github actions

I am using A LOT github actions.

I like them well and nothing hurts me too much (except the scheduled jobs auto disabling, but I now accepted to live with it 😒).

Crowd Surfing

I use them for instance for doing strange things like CI poor-man dashboards like the picture below:

Dashboard

Or I simply use them to test my modules.

I even produced this showcase (not limited to github) or posted a long writing about a crypto-mining attack that targeted my github actions recently.

"Github actions" actually designates both the CI system in general and the ready-to-use modules made for it (what you could find on Circle CI under the name "Orbs" or "pipeline libraries" in Jenkins).

Now I will talk about "Github action" modules πŸ˜„

You can almost live without Github actions (I would at least use checkout action), but they bring so much convenience that you should really give them a try πŸ˜€

The status of github actions for Perl

There are already some github actions to satisfy most needs like installing CPAN deps, testing a distribution or linting (validating with perlcritic).

You have the excellent Setup Perl to install the perl version of your choice + install CPAN modules (cpanm and cpm inside!)

steps:
    - uses: actions/checkout@v1
    - name: Setup Perl
      uses: shogo82148/actions-setup-perl@v1
      with:
        perl-version: '5.30'
    - name: perl -V
      run: perl -V
    - run: cpanm --installdeps .
    - run: prove -lv t
Enter fullscreen mode Exit fullscreen mode

Note: The "Setup X" is common for actions and we find that for lot of technologies ("Setup Python", "Setup Ruby", "Setup Jira"...)

"Setup perl" installs perl but if you want, there is also the possibility to use a docker image having already the version you want:

 jobs:
  perl:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        perl-version:
          - '5.10'
          - '5.16'
          - 'latest'
          - 'threaded'

    container:
      image: perl:${{ matrix.perl-version }}

    steps:
      - uses: actions/checkout@v2
      - name: perl -V
        run: perl -V
Enter fullscreen mode Exit fullscreen mode

This will connect to a ubuntu-latest VM having docker, launch 4 containers perl:5.10, perl:5.16, perl:latest and perl:threaded and run your perl -V inside.

Docker

You can even come with your own customized image (that you can create and push from another github repo with its own github action).
Another example is ci-perl-helpers-ubuntu from houseabsolute/ci-perl-helpers that seems to target transparent multi ci providers tooling.

With containers, the actual perl setup has been done during the docker packaging.

There are the also excellent install-with-cpanm or install-with-cpm that give you convenient and unified actions to install CPAN modules:

install-with-cpanm

- name: install cpanm and multiple modules
  uses: perl-actions/install-with-cpanm@v1
  with:
    install: |
      Simple::Accessor
      Test::Parallel
Enter fullscreen mode Exit fullscreen mode

The | is for introducing multiline.

install-with-cpm

- name: install cpm and multiple modules
  uses: perl-actions/install-with-cpm@stable
  with:
    install: |
      Simple::Accessor
      Test::Parallel
Enter fullscreen mode Exit fullscreen mode

Do you know that cpm is fast?

... Or their poor man versions

I'm decidedly a poor man!

You can also simulate install-with-cpanm with:

steps:
      - name: Install alien
        run: curl -L https://cpanmin.us | perl - --configure-timeout=1920 Alien::FFI
Enter fullscreen mode Exit fullscreen mode

Or for cpm:

    steps:
      - name: Install alien
        run: curl -sL https://git.io/cpm | perl - install --show-build-log-on-failure --test --configure-timeout=1920 Alien::FFI
Enter fullscreen mode Exit fullscreen mode

Please note the --configure-timeout option to increase the configure time (Alien modules can take long time)

The cpm --show-build-log-on-failure is a candy ❀️

The --test is to run tests (cpm by default disables them, for speed!)

You probably noticed that these versions use the pre-installed perl that comes with the VM but it is generally OK.

More and more with ci-perl-tester-helpers

There is even more in ci-actions-perl-helpers since it configures with dzil or minil, installs deps and builds your code.

(I haven't tested this one)

Perlcritic actions

I haven't tested any, but there is multiple perlcritic github actions. See gugod-perlcritic or gugod-perlcritic-with-reviewdog or perl-critic-action or perl-critic or action-perlcritic.

So much choices...

Choices

Your first action?

It appears a bit late in this post πŸ˜€ but if you never jumped into github actions, here is my quickstart:

  1. Create a file in .github/workflows/ (need to create the directory) named for install check.yml
  2. Put this yml code inside:
name: check-syntax

on: [push]

jobs:
  perl:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Check syntax 
      run: for f in `find . -name "*.pm" -o -name "*.pl" -o -name "*.t"`; do perl -c $f; done
Enter fullscreen mode Exit fullscreen mode

Push then wait and see πŸ˜„
Check

Conclusion

This is the end of my tour of Github actions for Perl.

I have still plenty of things to say but won't fall into too much details πŸ˜„ maybe in another blog post πŸ˜„

I hope you learned something or that I gave you the motivation to setup a github action on your repository!

Top comments (1)

Collapse
 
manchicken profile image
Mike Stemle

I really wish CodeQL worked for Perl. I have a Perl-XS module that I maintain, and I can’t find many good paths forward for SAST.

Have you found anything that worked for that just yet?