Skip to content

Commit

Permalink
gh-actions/yaml/tojson: Add compact flag/fun (#955)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <[email protected]>
  • Loading branch information
phlax authored Nov 6, 2023
1 parent 03fe42b commit 53a6664
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions gh-actions/yaml/tojson/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inputs:
type: string
description: >
Yaml string to convert.
compact:
type: boolean
description: >
Compact JSON output.
runs:
using: 'node16'
Expand Down
2 changes: 1 addition & 1 deletion gh-actions/yaml/tojson/dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion gh-actions/yaml/tojson/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const run = async (): Promise<void> => {
try {
const yamlString = core.getInput('yaml')
if (!yamlString || yamlString === '') return
const compact = core.getBooleanInput('compact')
const yamlObject = yaml.load(yamlString)
const jsonString = JSON.stringify(yamlObject)
const jsonString = compact ? JSON.stringify(yamlObject) : JSON.stringify(yamlObject, null, 2)
core.setOutput('json', jsonString)
} catch (error) {
if (error instanceof Error) {
Expand Down

0 comments on commit 53a6664

Please sign in to comment.