GitHub Action
Template Render Action
v1.0.2
Latest version
A github action to render ejs/mustache template files using github context.
This action is inspired by kikyous/template-action, with some additional features. Thanks to kikyous!
template-file
: Input template file path.template
: Input template string.- You must specify
template-file
ortemplate
- You must specify
vars
: [optional] Input variables. A dictionary of variables in JSON format to be used in the template. Or specify a.yml/.yaml/.json
file path.engine
: [optional] Choose template engine. Default isejs
.- Currently, you can choose
ejs
ormustache
- Currently, you can choose
options
: [optional] A JSON format string of options to be passed to the template engine.- For example,
{pretty: true}
- For example,
output-file
: [optional] Output file path.- If not specified, you can get rendered result from the action output with
${{ steps.<step-id>.outputs.content }}
.
- If not specified, you can get rendered result from the action output with
glob
: [optional] Glob mode. Default isfalse
. Iftrue
, glob mode is enabled:template-file
will be considered as a glob pattern (see@actions/glob
).template
/output-file
will be ignored.content
field in action output will not be set.- The output file name will be the same as the input file name, without the file extension. e.g.,
'data.json.template'
will be rendered to'data.json'
content
: template render result. (Only when glob mode is disabled)
name: Example for basic usage
on:
push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: recih/template-render-action@v1
id: template
with:
template: |
<% context.payload.commits.forEach(function(c){ %>
[✅ <%= c.message %>](<%= c.url %>)\n
<% }); %>
commiter: <%= context.payload.head_commit.author.name %>
vars: |
{ "name": "${{ steps.stepId.outputs.name }}" }
- name: Get the render output
run: echo "${{ steps.template.outputs.content }}"
name: Example for glob mode
on:
push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: recih/template-render-action@v1
with:
template-file: "**/*.template"
glob: true
EJS
: https://github.com/mde/ejsmustache
: https://github.com/janl/mustache.js
Following objects are exposed, and can be used in template file:
context
: TheContext
object in@actions/github
env
: Theprocess.env
object. You can access the environment variables withenv.<key>
you can explore context
use below action
name: Test
on:
push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: recih/template-render-action@v1
id: template
with:
template: "<%- JSON.stringify(context, undefined, 2) %>"
- name: Get the render output
run: echo "${{ steps.template.outputs.content }}"
- Support more template engines