I'm Mészáros Róbert – a full-stack developer who enjoys working in cross-functional teams the most.

Currently, together with a WordPress VIP agency, we support enterprise clients.

At Codeable, I have mainly vetted experts lately.

implenton is the name of this development-related space.

Recent posts

In GitHub Actions there are many places where we can use arrays.

For example, when using the matrix strategy:

jobs:
example_matrix:
strategy:
matrix:
version: [10, 12, 14]

Or when we want to filter whats triggers the workflow:

on:
push:
branches:
- main
- 'releases/**'

But, we are limited to using only strings, numbers, and booleans for input values.

The following are not valid options according to the spec:

- uses: 'example-action@v1'
with:
keys: ['foo', 'bar']
- uses: 'example-action@v1'
with:
keys:
- foo
- bar

We can use multiline strings if we want something close to multiline values.

- uses: 'example-action@v1'
with:
keys: |-
foo
bar

But the value of keys is still a string; it only contains new lines.

We have to turn it intro a proper array.

If we use JavaScript actions, it will look something similar:

import core from "@actions/core";
 
const keys = core.getInput("keys")
.split(/[\r\n]/)
.map(input => input.trim())
.filter(input => input !== '');

It's an important but small detail that we used |- in the YAML and not |.

We can control how we treat the final line break in multiline strings.

Chomping controls how final line breaks and trailing empty lines are interpreted.

For comparison, here's the YAML converted into JSON:

strip: |-
foo
clip: |
bar
{
"strip": "foo",
"clip": "bar\n"
}

If we exaggerate a little, there's always something new to learn when reading someone else's code, even for seasoned veterans like Freek Van der Herten.

In his article, Discovering PHP's first-class callable syntax, Freek shares how he came across a PHP feature while examining the Laravel codebase.

This is the first example I've come across where this particular feature is employed in such an appealing way.

Featured Publications