Skip to content

Commit a34ac47

Browse files
committed
feat: add outputs generation again
As mentioned on actions/toolkit#702 (comment), we are safe to execute commands on our side. This reverts commit 58072cd, reversing changes made to 1788ebd.
1 parent 771ad9d commit a34ac47

4 files changed

Lines changed: 165 additions & 41 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ You can see more info about GitHub's default token [here](https://docs.github.co
6262

6363
default: `${{ github.token }}`
6464

65+
## Outputs
66+
67+
### `results`
68+
69+
The error and warning messages for each one of the analyzed commits. This is useful if you want to use the commitlint results in a JSON format in other jobs. See [the documentation](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#fromjson) on how to read JSON information from outputs.
70+
71+
Below you can see an example text output together with its corresponding JSON output:
72+
6573
```
6674
You have commit messages with errors
6775

src/action.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const lint = require('@commitlint/lint').default
77
const { format } = require('@commitlint/format')
88
const load = require('@commitlint/load').default
99
const gitCommits = require('./gitCommits')
10+
const generateOutputs = require('./generateOutputs')
1011

1112
const pullRequestEvent = 'pull_request'
1213

@@ -108,9 +109,7 @@ const hasOnlyWarnings = lintedCommits =>
108109
lintedCommits.some(({ lintResult }) => lintResult.warnings.length)
109110

110111
const setFailed = formattedResults => {
111-
process.exitCode = 1
112-
113-
console.error(`You have commit messages with errors\n\n${formattedResults}`)
112+
core.setFailed(`You have commit messages with errors\n\n${formattedResults}`)
114113
}
115114

116115
const handleOnlyWarnings = formattedResults => {
@@ -135,9 +134,7 @@ const showLintResults = async ([from, to]) => {
135134
)
136135
const formattedResults = formatErrors(lintedCommits)
137136

138-
// disable workflow commands
139-
const token = uuidv4()
140-
console.log(`::stop-commands::${token}`)
137+
generateOutputs(lintedCommits)
141138

142139
if (hasOnlyWarnings(lintedCommits)) {
143140
handleOnlyWarnings(formattedResults)
@@ -146,15 +143,10 @@ const showLintResults = async ([from, to]) => {
146143
} else {
147144
console.log('Lint free! 🎉')
148145
}
149-
150-
// enable workflow commands
151-
console.log(`::${token}::`)
152146
}
153147

154148
const exitWithMessage = message => error => {
155-
process.exitCode = 1
156-
157-
console.error(`${message}\n${error.message}\n${error.stack}`)
149+
core.setFailed(`${message}\n${error.message}\n${error.stack}`)
158150
}
159151

160152
const commitLinterAction = () =>

0 commit comments

Comments
 (0)