Skip to content

Commit

Permalink
set outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Mar 25, 2023
1 parent 7b897a1 commit adce8c2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as jsonValidator from '../src/functions/json-validator'

const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation(() => {})
const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation(() => {})

beforeEach(() => {
jest.clearAllMocks()
Expand All @@ -15,6 +16,7 @@ beforeEach(() => {
test('successfully runs the action', async () => {
expect(await run()).toBe(true)
expect(infoMock).toHaveBeenCalledWith('✅ all JSON files are valid')
expect(setOutputMock).toHaveBeenCalledWith('success', 'true')
})

test('fails the action due to json errors', async () => {
Expand All @@ -28,4 +30,5 @@ test('fails the action due to json errors', async () => {
expect(setFailedMock).toHaveBeenCalledWith(
'❌ 3 JSON files failed validation'
)
expect(setOutputMock).toHaveBeenCalledWith('success', 'false')
})
2 changes: 2 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export async function run() {

if (jsonResult.success === true) {
core.info('✅ all JSON files are valid')
core.setOutput('success', 'true')
return true
} else {
core.info(
`JSON Validation Results:\n - Passed: ${jsonResult.passed}\n - Failed: ${jsonResult.failed}`
)
core.setOutput('success', 'false')
core.setFailed(`❌ ${jsonResult.failed} JSON files failed validation`)
return false
}
Expand Down

0 comments on commit adce8c2

Please sign in to comment.