Skip to content

Commit

Permalink
Added additional parameters to support --ext-str options in `jsonne…
Browse files Browse the repository at this point in the history
…t`. (#1)
  • Loading branch information
vicpara authored Sep 5, 2020
1 parent a10876f commit 42bf702
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
id: jsonnet
with:
file: 'test/example.jsonnet'
params: 'test=true,env=stag'
render_jsonnet_to_single_file:
runs-on: ubuntu-latest
name: Write rendered result to file
Expand All @@ -40,5 +41,6 @@ jobs:
with:
file: 'test/example.jsonnet'
output_dir: test/multi-file-output/
params: 'test=true dryrun=false;env=prod'
- name: Validation
run: diff test/multi-file-output/person1 test/person1
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and combine them with another GitHub action to:
* `output_file` - when set, writes the STDOUT from Jsonnet invocation to $output-file. OPTIONAL
* `output_dir` - when set, appends `-m $output_dir` to the Jsonnet invocation to render multiple output files to a single directory. OPTIONAL
* `plaintext` - when set to any value, Jsonnet is invoked with the `-S` flag to emit plaintext rather than JSON-encoded output.
* `params` - specify external `--ext-str` arguments. `dryrun=true env=prod` becomes `--ext-str dryrun=true --ext-str env=prod`. Use either of comma, space or semicolon as argument separator. OPTIONAL

## Output

Expand All @@ -40,6 +41,7 @@ steps:
with:
file: path/to/file.jsonnet
output_file: output/file.json
params: dryrun=true env=prod
```
### Render multiple files in a single directory
Expand All @@ -51,4 +53,5 @@ steps:
with:
file: path/to/file.jsonnet
output_dir: output/
params: dryrun=true;env=prod
```
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ inputs:
When set to `true`, invokes Jsonnet with the `-S` flag to print the output
verbatim rather than encoded as JSON
required: false
params:
description: |
Pass arguments to `jsonnet` that get mapped to `--ext-str` arguments.
`dryrun=true env=prod` becomes `--ext-str dryrun=true --ext-str env=prod`.
Use either of comma, space or semicolon as argument separator.
required: false
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -32,3 +38,4 @@ runs:
- ${{ inputs.output_dir }}
- ${{ inputs.output_file }}
- ${{ inputs.plaintext }}
- ${{ inputs.params }}
16 changes: 14 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@ else
PLAINTEXT_ARG="-S"
fi

if [ -z "$INPUT_PARAMS" ]
then
EXTERNAL_PARAMS_ARG=""
else
INPUT_PARAMS=$(echo $INPUT_PARAMS | sed 's/[,;]/ /g')
EXTERNAL_PARAMS_ARG=""
for PARAM in $INPUT_PARAMS
do
EXTERNAL_PARAMS_ARG="$EXTERNAL_PARAMS_ARG --ext-str $PARAM"
done
fi

if [ -z "$INPUT_OUTPUT_FILE" ]
then
echo "Running jsonnet $OUTPUT_DIR_ARG $PLAINTEXT_ARG $INPUT_FILE"
jsonnet $OUTPUT_DIR_ARG $PLAINTEXT_ARG $INPUT_FILE
jsonnet $EXTERNAL_PARAMS_ARG $OUTPUT_DIR_ARG $PLAINTEXT_ARG $INPUT_FILE
else
echo "Running jsonnet $OUTPUT_DIR_ARG $PLAINTEXT_ARG $INPUT_FILE > $INPUT_OUTPUT_FILE"
OUTPUT=$(jsonnet $OUTPUT_DIR_ARG $PLAINTEXT_ARG $INPUT_FILE)
OUTPUT=$(jsonnet $EXTERNAL_PARAMS_ARG $OUTPUT_DIR_ARG $PLAINTEXT_ARG $INPUT_FILE)
echo "$OUTPUT" > $INPUT_OUTPUT_FILE
fi

0 comments on commit 42bf702

Please sign in to comment.