DEV Community

Cover image for Creating new Perl composite actions from a repository template
Juan Julián Merelo Guervós
Juan Julián Merelo Guervós

Posted on

Creating new Perl composite actions from a repository template

So you want to create a quick-and-dirty GitHub actions that does only one thing and does it well, or glues together several actions, or simply to show off a bit at your next work interview. Here's how you can do it.
Let me introduce you to composite GitHub actions, one of the three types that are there (the other are JavaScript GHAs or container-based GHAs) and maybe one of the most widely unknown. However, they have several things going for them. First, they have low latency: no need to download a container or to set up some JS environment). Second, they are relatively easy to set up: they can be self-contained, with everything needed running directly on the description of the GitHub action. Third, you can leverage all the tools installed on the runner like bash, compilers, build tools... or Perl, which can be that and much more.
Even being easy, it is even easier if you have a bit of boilerplate you can use directly or adapt to your own purposes. This is what has guided the creation of the template for a composite GitHub action based on Perl. It is quite minimalistic. But let me walk you through what it has got so that you can use it easier

First, this action.yml describes what it does and how it does:

name: 'Hello Perl'
description: 'Perl Github Action Template'
inputs:
  template-input:  # Change this
    description: 'What it is about'
    required: false # or not
    default: 'World'
runs:
  using: "composite"
  steps:
    - uses: actions/checkout@v4
    - run: print %ENV;
      shell: perl {0}
    - run: ${GITHUB_ACTION_PATH}/action.pl
      shell: bash
Enter fullscreen mode Exit fullscreen mode

You will have to customize inputs as well as outputs here (and, of course, name and description), but the steps are already baked in. It even includes the correct path to the (downloaded) Github action: when you're acting on a repository, the place where a GHA is is contained in an environment variable, GITHUB_ACTION_PATH. You can access it that way.

In general, that script might need external libraries, even your own, which you might have moved out of the script for testing purposes (everything must be tested). That is why the action also contains App::FatPacker as a dependency; that's a bundler that will put the source (action.src.pl), your library (lib/Action.pm) and every other module you might have used into a single file, the action.pl referenced above.

A Makefile is also provided, so that, after installing fatpack, typing make will process the source and generate the script.

And that's essentially it. Use the template and create your new (composite) action in just a few minutes!

Top comments (0)