Skip to content

Commit

Permalink
Converts the action to a composite action (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-carey authored Apr 20, 2023
1 parent 3b82aed commit 1e8050d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 31 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.8
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ Renders Jinja2 Templates via the [J2 cli](https://github.com/kolypto/j2cli).
# The name of the output file to write rendered contents to
# Default: output
output: ''

# If true, sets -x in the shell command
# Default: false
debug: ''
```
<!-- end usage -->
58 changes: 46 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

name: 'Render J2 Template'
description: 'Renders a J2 Template'

inputs:
template:
description: 'The path to the template file to render'
Expand Down Expand Up @@ -43,19 +46,50 @@ inputs:
description: 'The name of the output file to write rendered contents to'
required: false
default: output
debug:
description: 'If true, sets -x in the shell command'
required: false
default: false

outputs:
file:
description: 'The file the rendered content was written to'
value: ${{ steps.render.outputs.file }}
content:
description: 'The rendered content'
value: ${{ steps.render.outputs.content }}

runs:
using: 'docker'
image: 'Dockerfile'
env:
TEMPLATE: ${{ inputs.template }}
DATA: ${{ inputs.data }}
FORMAT: ${{ inputs.format }}
ENV_VARS: ${{ inputs.env_vars }}
FILTERS: ${{ inputs.filters }}
TESTS: ${{ inputs.tests }}
CUSTOMIZE: ${{ inputs.customize }}
UNDEFINED: ${{ inputs.undefined }}
OUTPUT: ${{ inputs.output }}
using: 'composite'
steps:
- name: 'Setup python'
uses: actions/setup-python@v4
with:
python-version-file: ${{ github.action_path }}/.python-version

- name: 'Cache python dependencies'
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles(join(fromJSON('["${{ github.action_path }}", "requirements.txt"]'), '/')) }}
restore-keys: ${{ runner.os }}-pip-

- name: 'Install dependencies'
shell: bash
run: pip install -r "${{ github.action_path }}/requirements.txt"

- name: 'Render'
id: render
shell: bash
run: "${{ github.action_path }}/src/render.sh"
env:
TEMPLATE: ${{ inputs.template }}
DATA: ${{ inputs.data }}
FORMAT: ${{ inputs.format }}
ENV_VARS: ${{ inputs.env_vars }}
FILTERS: ${{ inputs.filters }}
TESTS: ${{ inputs.tests }}
CUSTOMIZE: ${{ inputs.customize }}
UNDEFINED: ${{ inputs.undefined }}
OUTPUT: ${{ inputs.output }}
DEBUG: ${{ inputs.debug }}
13 changes: 9 additions & 4 deletions src/render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function set-output() {
function render() {
set -eo pipefail

if [ "${DEBUG:-false}" = 'true' ]; then
set -x
fi

# Validation

[ -n "$TEMPLATE" ] || {
Expand All @@ -29,10 +33,13 @@ function render() {
for var in Template Data Filters Tests Customize; do
VAR="${var^^}"
val="${!VAR}"
[ -z "$val" ] || [ -f "$val" ] || {
if [ -n "$val" ] && ! [ -f "$val" ]; then
whoami
ls -al "$(dirname "$val")"
ls -al "$val"
echo "[ERROR] $var file not found: $val" >&2
return 2
}
fi
done

[ -z "$UNDEFINED" ] || [ "$UNDEFINED" = true ] || [ "$UNDEFINED" = false ] || {
Expand Down Expand Up @@ -70,8 +77,6 @@ function render() {
COMMAND+=("$TEMPLATE")
[ -z "$DATA" ] || COMMAND+=("$DATA")

set -x

which j2
echo "[DEBUG] ${COMMAND[*]}" >&2
"${COMMAND[@]}"
Expand Down

0 comments on commit 1e8050d

Please sign in to comment.