Skip to content

Instantly share code, notes, and snippets.

@hubgit
Last active May 29, 2021 21:26
Show Gist options
  • Select an option

  • Save hubgit/2eea657c3fc6e09ee24b62b64ec45654 to your computer and use it in GitHub Desktop.

Select an option

Save hubgit/2eea657c3fc6e09ee24b62b64ec45654 to your computer and use it in GitHub Desktop.
Custom formatters/reporters for GitHub Actions
const { issueCommand, issue } = require('@actions/core/lib/command')
const pathPrefixLength = process.cwd().length + 1
module.exports = results => {
issue('group', 'ESLint Annotations')
for (const result of results) {
for (const message of result.messages) {
const { fatal, severity, line, column: col } = message
const status = fatal || severity === 2 ? 'error' : 'warning'
const file = result.filePath.substr(pathPrefixLength)
const data = { file, line, col }
const description = `${message.message} (${message.ruleId})`
issueCommand(status, data, description)
}
}
issue('endgroup')
return ''
}
const { issueCommand, issue } = require('@actions/core/lib/command')
const Mocha = require('mocha')
const pathPrefixLength = process.cwd().length + 1
const stackRe = /^\s*at Context.* \(([^()]+):([0-9]+):([0-9]+)\)/gm
module.exports = class GitHubActionsReporter {
constructor(runner) {
runner
.once('start', () => {
issue('group', 'Mocha Annotations')
})
.on('fail', (test, err) => {
const [, _file, line, col] = stackRe.exec(err.stack) || []
const file = _file || test.file.substr(pathPrefixLength)
const data = { file, line, col }
const description = `${err.message} (${test.fullTitle()})`
issueCommand('error', data, description)
})
.once('end', () => {
issue('endgroup')
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment