Last active
May 29, 2021 21:26
-
-
Save hubgit/2eea657c3fc6e09ee24b62b64ec45654 to your computer and use it in GitHub Desktop.
Custom formatters/reporters for GitHub Actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 '' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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