GitHub Actions for Perl Development
Tags: githubactions, cd, ci, github
Published: 2024-01-20 14:18:50

---
title: GitHub Actions for Perl Development
published: true
date: 2024-01-20 14:14:42 UTC
tags: githubactions,cd,ci,github
canonical_url: https://perlhacks.com/2024/01/github-actions-for-perl-development/
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ljt0kw6q4to14xnplhe.png
---

You might remember that I’ve been taking an interest in [GitHub Actions](https://github.com/features/actions) for the last year or so (I even [wrote a book on the subject](https://actions.davecross.co.uk/)). And at the Perl Conference in Toronto last summer I gave a talk called “GitHub Actions for Perl Development” (here are [the slides](https://docs.google.com/presentation/d/e/2PACX-1vT_vwCseMJ_csjJjE79d09ADAE_fuAs59VSlSVY5Fwb-aDfEOpB4hi3-mS3vVX5kjbZzqTGJ4C-DSz7/pub?start=false&loop=false&delayms=3000) and [the video](https://www.youtube.com/watch?v=ol_Qk31v17g)).

During that talk, I mentioned a project I was working on to produce a set of reusable workflows that would make it easier for anyone to start using GitHub Actions in their Perl development. Although (as I said in the talk) things were moving pretty quickly on the project at the time, once I got back to London, several other things became more important and work on this project pretty much stalled. But over the last couple of weeks, I’ve returned to this project and I’ve finally got some of the workflows into a state where I’ve been using them successfully in my GitHub repos and I think they’re now ready for you to start using them in yours. There are three workflows that I’d like you to try:

- [**cpan\_test:**](https://github.com/PerlToolsTeam/github_workflows/blob/main/.github/workflows/cpan-test.yml) This runs your test suite and reports on the results
- **[cpan\_coverage:](https://github.com/PerlToolsTeam/github_workflows/blob/main/.github/workflows/cpan-coverage.yml)** This calculates the coverage of your test suite and reports the results. It also uploads the results to [coveralls.io](https://coveralls.io/)
- [**cpan\_perlcritic:**](https://github.com/PerlToolsTeam/github_workflows/blob/main/.github/workflows/cpan-perlcritic.yml) This runs perlcritic over your code and reports on the results

And using these workflows in your GitHub repos is as simple as creating a new file in the <tt>.github/workflows</tt> directory which contains something like this:

```
name: CI

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]
  workflow_dispatch:

jobs:
  build:
    uses: PerlToolsTeam/github_workflows/.github/workflows/cpan-test.yml@main

  coverage:
    uses: PerlToolsTeam/github_workflows/.github/workflows/cpan-coverage.yml@main

  perlcritic:
    uses: PerlToolsTeam/github_workflows/.github/workflows/cpan-perlcritic.yml@main
```

There are a couple of parameters you can use to change the behaviour of these workflows. In the Toronto talk, I introduced the idea of a matrix of tests, where you can test against three operating systems (Linux, MacOS and Windows) and a list of Perl versions. By default, the cpan-test workflow uses all three operating systems and all production versions of Perl from 5.24 to 5.38. But you can change that by using the <tt>perl_version</tt> and <tt>os</tt> parameters. For example, if you only wanted to test on Ubuntu, using the most recent two versions of Perl, you could use this:

```
build:
  uses: PerlToolsTeam/github_workflows/.github/workflows/cpan-test.yml@main
  with:
    perl_version: "['5.36', '5.38']"
    os: "['ubuntu']"
```

Annoyingly, the parameters to a reusable workflow can only be a single scalar value. That’s why we have to use a JSON-encoded string representing an array of values. Maybe this will get better in the future.

The cpan-perlcritic workflow also has a parameter. You can use level to change the level that perlcritic runs at. The default is 5 (the gentlest level) but if you were feeling particularly masochistic, you could do this:

```
perlcritic:
    uses: PerlToolsTeam/github_workflows/.github/workflows/cpan-perlcritic.yml@main
    with:
      level: 1
```

The workflows are, of course, [available on GitHub](https://github.com/PerlToolsTeam/github_workflows). It would be great to have some people trying them out and reporting back on their experiences. [Raising issues](https://github.com/PerlToolsTeam/github_workflows/issues) and [sending pull requests](https://github.com/PerlToolsTeam/github_workflows/pulls) is very much encouraged.

Please let me know how you get on with them.

The post [GitHub Actions for Perl Development](https://perlhacks.com/2024/01/github-actions-for-perl-development/) appeared first on [Perl Hacks](https://perlhacks.com).