Skip to content

Commit

Permalink
feat: add outputs generation again
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wagoid committed Feb 7, 2021
1 parent 771ad9d commit a34ac47
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 41 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ You can see more info about GitHub's default token [here](https://docs.github.co

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

## Outputs

### `results`

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.

Below you can see an example text output together with its corresponding JSON output:

```
You have commit messages with errors
Expand Down
16 changes: 4 additions & 12 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const lint = require('@commitlint/lint').default
const { format } = require('@commitlint/format')
const load = require('@commitlint/load').default
const gitCommits = require('./gitCommits')
const generateOutputs = require('./generateOutputs')

const pullRequestEvent = 'pull_request'

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

const setFailed = formattedResults => {
process.exitCode = 1

console.error(`You have commit messages with errors\n\n${formattedResults}`)
core.setFailed(`You have commit messages with errors\n\n${formattedResults}`)
}

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

// disable workflow commands
const token = uuidv4()
console.log(`::stop-commands::${token}`)
generateOutputs(lintedCommits)

if (hasOnlyWarnings(lintedCommits)) {
handleOnlyWarnings(formattedResults)
Expand All @@ -146,15 +143,10 @@ const showLintResults = async ([from, to]) => {
} else {
console.log('Lint free! 🎉')
}

// enable workflow commands
console.log(`::${token}::`)
}

const exitWithMessage = message => error => {
process.exitCode = 1

console.error(`${message}\n${error.message}\n${error.stack}`)
core.setFailed(`${message}\n${error.message}\n${error.stack}`)
}

const commitLinterAction = () =>
Expand Down
Loading

0 comments on commit a34ac47

Please sign in to comment.