Generate file output from a JSON string.
```yaml ... - name: Set output id: set-output run: | echo "color=green" >> $GITHUB_OUTPUT
- name: Generate file output from json
uses: tj-actions/json2file@v1
with:
directory: 'output'
outputs: ${{ toJSON(steps.set-output.outputs) }}
keys: 'color'
extension: 'txt'
... ```
The above example will create a file named color.txt
in the output
directory with the contents green
.
bash
$ cat ./output/color.txt
green
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-------------------|--------|----------|---------------------|-------------------------------------------------------------|
| bin_path | string | false | | Path to the binary |
| directory | string | true | ".github/outputs"
| Directory to write to |
| extension | string | false | "txt"
| File extension to use |
| keys | string | true | | List of Keys to read from
the outputs
JSON string |
| outputs | string | true | | JSON string |
| skip_missing_keys | string | false | "false"
| Skip missing keys not found in
the outputs
JSON string |
Run json2file --help
for more information.
```bash $ json2file --help Generate file output from JSON
Usage: json2file [OPTIONS] --keys
Options:
-k, --keys
-h, --help Print help
-V, --version Print version
```
bash
$ json2file --keys="foo bar" --outputs="{\"foo\": \"value1\", \"bar\": \"value2\"}" --directory=/tmp --extension=txt
This creates two files with the following contents:
foo.txt
txt
value1
bar.txt
txt
value2
If you feel generous and want to show some extra appreciation:
This package was created with Cookiecutter using cookiecutter-action
Report bugs at https://github.com/tj-actions/json2file/issues.
If you are reporting a bug, please include: