Skip to content

Commit

Permalink
Add initial action metadata with code
Browse files Browse the repository at this point in the history
  • Loading branch information
oceantume committed Jan 12, 2022
1 parent 3ef9b99 commit 7fdabe0
Show file tree
Hide file tree
Showing 5 changed files with 462 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'JSON Format'
author: 'Gabriel Bourgeois'
description: 'Formats a JSON file'
inputs:
file:
description: 'The path of the file to format'
required: true
space:
description: 'The spacing to use when formatting the JSON'
required: false
default: 2
runs:
using: 'node16'
main: 'index.js'
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const core = require('@actions/core')
const github = require('@actions/github')
const fs = require('fs')

try {
const file = core.getInput('file')
const space = Number(core.getInput('space'))

const original = fs.readFileSync(file, { encoding: 'utf8' })
const formatted = JSON.stringify(JSON.parse(original), null, space)

fs.writeFileSync(file, formatted)
} catch (error) {
core.setFailed(error)
}
Loading

0 comments on commit 7fdabe0

Please sign in to comment.