Github Actions + EJS = Template file generation

Gonzalo Mendoza
2 min readMar 14, 2022

It is common in organizations the need to communicate either internally or to external customers

The need for a tool capable of covering the use cases of the Marketing, development and operations departments arises intuitively.

Template flow

EJS Lint

It is essential to have a tool that allows us to validate if the input template has the correct syntax. That is, to guarantee that the base file can be processed

For this we will use EJS lint, the Action of it follows the following syntax

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check if templates are correct using EJS Lint
uses: yogonza524/ejs-lint-action@v1.3
with:
folder: path/to/templateFolder

The code can be found on the Github Marketplace via https://github.com/marketplace/actions/ejs-lint

EJS tool

Once we have validated the base template we will need to use the inputs in JSON format. I recommend minifying the input JSON

Now you must use the Action EJS found in the Github Marketplace https://github.com/marketplace/actions/ejs-action

jobs:
ejsAction:
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Show template file
run: cat templates/some.ejs
- name: EJS Action
uses: yogonza524/ejs-action@v1.3
with:
fileTemplate: 'templates/some.ejs'
variables: '{"name" : "Pepe"}'
fileOutput: 'templates/output.txt'
- name: Show output file
run: cat templates/output.txt

Using this in a pipeline from another repo, we can see the following

External pipeline using EJS

Benefits

  • Generation speed
  • Little configuration

Cons

  • Creating input variables can be complex

--

--

Gonzalo Mendoza

Software engineer dedicated to the creation, deployment and continuity of software solutions. With criticality and a broad analytical sense