Skip to content

Commit

Permalink
Merge pull request #8 from marocchino/exit-code
Browse files Browse the repository at this point in the history
Exit code
  • Loading branch information
marocchino authored Feb 19, 2021
2 parents d3f8ac0 + 956e2b8 commit 5833f08
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ jobs:
- uses: ./
id: validate
- uses: marocchino/sticky-pull-request-comment@v2
if: always()
with:
header: validate-dependabot
message: ${{ steps.validate.outputs.markdown }}
message: |
${{ steps.validate.outputs.markdown }}
${{ steps.validate.outputs.raw }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- uses: marocchino/validate-dependabot@v1
id: validate
- uses: marocchino/sticky-pull-request-comment@v2
if: always()
with:
header: validate-dependabot
message: ${{ steps.validate.outputs.markdown }}
Expand Down
11 changes: 11 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ describe('validate', () => {
source: {
pointer: '#/updates/8/commit-message/prefix'
}
},
{
title: 'Unparseable',
detail:
"(): could not find expected ':' while scanning a simple key at line 10 column 1"
}
]
})
Expand All @@ -47,6 +52,7 @@ describe('validate', () => {
| title | detail | source |
| ----- | ------ | ------ |
| Invalid | The property '#/updates/8/commit-message/prefix' was not of a maximum string length of 15 | #/updates/8/commit-message/prefix |
| Unparseable | (): could not find expected ':' while scanning a simple key at line 10 column 1 | undefined |
`,
raw: {
errors: [
Expand All @@ -57,6 +63,11 @@ describe('validate', () => {
pointer: '#/updates/8/commit-message/prefix'
},
title: 'Invalid'
},
{
title: 'Unparseable',
detail:
"(): could not find expected ':' while scanning a simple key at line 10 column 1"
}
]
}
Expand Down
6 changes: 5 additions & 1 deletion 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.

12 changes: 8 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ async function run(): Promise<void> {
const {raw, message} = await validate(path)
core.setOutput('raw', raw)
core.setOutput('markdown', message)
if (raw.errors.length !== 0) {
core.setFailed('exists errors')
}
} catch (error) {
core.setFailed(error.message)
}
Expand All @@ -17,7 +20,7 @@ export async function validate(
path: string
): Promise<{
raw: {
errors: {title: string; detail: string; source: {pointer: string}}[]
errors: {title: string; detail: string; source?: {pointer: string}}[]
}
message: string
}> {
Expand All @@ -38,19 +41,20 @@ export async function validate(
}
)
const raw = await result.json()
core.debug(`response: ${JSON.stringify(raw)}`)
let message
if (raw?.errors.length > 0) {
const lines = raw.errors
.map(
({
title,
detail,
source: {pointer}
source
}: {
title: string
detail: string
source: {pointer: string}
}) => `| ${title} | ${detail} | ${pointer} |`
source?: {pointer: string}
}) => `| ${title} | ${detail} | ${source?.pointer} |`
)
.join('\n')
message = `
Expand Down

0 comments on commit 5833f08

Please sign in to comment.