Creating new Perl composite actions from a repository template
Tags: perl, githubactions, repositorytemplates, designpatterns
Published: 2024-05-22 12:06:18

---
title: Creating new Perl composite actions from a repository template
published: true
description: What's in a template for composite actions
tags: perl, githubactions, repositorytemplates, designpatterns
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b0iilqhx6w93x0bpvmae.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2024-05-22 10:26 +0000
---

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](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action), 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](https://github.com/actions/runner-images) 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](https://github.com/JJ/perl-composite-action-template). 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:

```yaml
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
```

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](https://github.com/new?template_name=perl-composite-action-template) and create your new (composite) action in just a few minutes!