A JavaScript action that renders a string template into an output variable using the ETA library.
| Name | Description | Type | Required | Default |
|---|---|---|---|---|
template |
Template string to render (supports ETA syntax) or a path to a file containing the template. |
string |
true |
"" |
varName |
Name of the variable that holds all data to be used in the template (variables). |
string |
false |
it |
variables |
Variables to substitute in the template. You can use YAML, JSON, or dotenv format. See examples |
string |
false |
"" |
| Name | Type | Description |
|---|---|---|
text |
string |
Rendered template string. |
You can use functions from the date-fns
library to format dates inside the template.
Use any function with the utils.dateFns prefix.
For example, to format a date,
you can use utils.dateFns.format(it.date, "MM/dd/yyyy HH:mm:ss").
In addition to the default functions,
you can use the UTCDateMini
class to work with UTC date objects.
You can use this class directly (without the utils prefix).
For example, to format a date, you can use UTCDateMini(it.date).
[!INFO] The heavier alternative
UTCDateclass is not available in this action for now.
Example formatting timestamp:
steps:
- name: Render template with formatted date
uses: roamingowl/template-output-with-eta@v1
with:
template: |
Formatted date is <%= utils.dateFns.format(new UTCDateMini(it.timestamp * 1000), "MM/dd/yyyy HH:mm:ss") %>
variables: |
timestamp: 1711187861will produce output like:
Formatted date is 03/23/2024 09:57:41Variables in YAML format:
steps:
- name: Render a simple template with variables in YAML format
uses: roamingowl/template-output-with-eta@v1
with:
template: |
<%= it.what %> this is <%= it.name %>
variables: |
name: 'John'
what: 'hi'Variables in JSON format:
steps:
- name: Render a simple template with variables in JSON format
uses: roamingowl/template-output-with-eta@v1
with:
template: |
<%= it.what %> this is <%= it.name %>
variables: |
{ "what": "hi", "name": "John" }Variables in dotenv format:
steps:
- name: Render a simple template with variables in dotenv format
uses: roamingowl/template-output-with-eta@v1
with:
template: |
<%= it.WHAT %> this is <%= it.NAME %>
variables: |
WHAT=hi
NAME=JohnLoad template from a file:
steps:
- name: Render a simple template from a file
uses: roamingowl/template-output-with-eta@v1
with:
template: ./template.txt
variables: |
what: hi
name: JohnPrint the date difference between two timestamps in minutes:
steps:
- name: Render the difference between two timestamps in minutes
uses: roamingowl/template-output-with-eta@v1
id: render
with:
template: |
The difference is <%= Math.abs(utils.dateFns.differenceInMinutes(new Date(it.t1 * 1000), new Date(it.t2 * 1000))) %> minutes
variables: |
t1: 1711187861
t2: 1711188041
- name: Print the difference
shell: bash
run: echo "Difference is ${{ steps.render.outputs.text }}"The scripts and documentation in this project are released under the MIT License.