Use Jinja2 template engine on multipe files as a GitHub action.
This is a very simple version of the action, that is ok for my first need. Futur enhancement will come.
The actual "simple" version transform all local j2 files (recursively) ('*.j2') with the jinja2 library.
The new file name is the same filename without the j2 extension.
For exemple, README.md.j2
becomes README.md
.
It this version, it can only be used with environment variable, see my test template file.
Environement variable as used as with the jinja2 cli, with a kind of environ
method :
{{ environ('TEST') }}
- uses: fletort/jinja2-template-action@v1
env:
TEST: my_value
Environment variables are used as with jinja2 cli:
{{ environ('TEST') }}
Or as other contextual github information:
{{ env.TEST }}
- uses: fletort/jinja2-template-action@v1
with:
variables: |
TEST1=mytest
TEST2=isfunny
- uses: fletort/jinja2-template-action@v1
with:
data_file: my_data.json
data_format: json # can be detected automatically (see below)
Possible data type are: env, yaml, json, ini
EXEMPLE_SMART=yoyo
EXEMPLE_MY_VAR=True
[EXEMPLE]
SMART=yoyo
MY_VAR=True
---
EXEMPLE:
SMART=yoyo
MY_VAR=True
{
"EXEMPLE": {
"SMART": "yoyo",
"MY_VAR": True
}
}
For previous INI, YAML, JSON examples, jinja template will be:
{{ EXEMPLE.SMART }}
{{ EXEMPLE.MY_VAR }}
For previous ENV example, jinja template will be:
{{ EXEMPLE_SMART }}
{{ EXEMPLE_MY_VAR }}
Some of the contextual information about workflow runs are available inside your jinja Template:
- github
- job
- runner
- strategy
- matrix
As part of an expression, you can access context information using one of two syntaxes.
Index syntax: github['sha']
Property dereference syntax: github.sha
{{ github.repository }}
{{ job.status }}
{{ runner.os }}
{{ strategy.job_index }}
{{ matrix.your_matrix_variable_name }}
Note: All strategy information key contains dashes that must me marked as underscore in jinja expression: ${{ strategy.job-index }}
becomes {{ strategy.job_index }}
.
Name | Description | Default |
---|---|---|
variables |
Variable to substitute in the jinja templates. Must be Key, value pairs in .env file format (key=value). | "" |
keep_template |
Put to true to keep original template file. |
false |
data_file |
Source file contening inputs variable for the jinja template. | "" |
data_format |
Format of the data_file . Can be env , ini , yaml , json or automatic (for automatic detection). The automatic detction is based on the extension then on the content. |
automatic |
All unit test executed on each branch/PR are listed/described on testspace.
Coverage information and history is also avalailable on coveralls.
The scripts and documentation in this project are released under the MIT License