-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add summary to action job #62
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as core from '@actions/core' | ||
import { readFileSync } from 'fs' | ||
import type { LinterResponse } from './types' | ||
import type { LinterResponse, ErrorDetail } from './types' | ||
import fetch from 'node-fetch' | ||
import { pluralize } from './utils' | ||
|
||
|
@@ -11,6 +11,7 @@ export async function lintFiles( | |
linterConfig: Record<string, unknown> | ||
): Promise<number> { | ||
let totalErrors = 0 | ||
const fileErrors: Record<string, ErrorDetail[]> = {} | ||
|
||
for (const file of files) { | ||
const fileContents = readFileSync(file, 'utf8') | ||
|
@@ -52,22 +53,56 @@ export async function lintFiles( | |
|
||
const errors = result.report.errors | ||
totalErrors += errors.length | ||
if (errors.length > 0) { | ||
fileErrors[file] = errors.map((error) => ({ | ||
line: error.lineNumber, | ||
column: error.column, | ||
endColumn: error.endColumn, | ||
message: `${error.ruleId} - ${error.description}`, | ||
ruleId: error.ruleId, | ||
description: error.description | ||
})) | ||
} | ||
} | ||
|
||
// Create summary of all errors | ||
core.summary.addHeading('Accessibility Linting Results').addBreak() | ||
|
||
// Report errors using GitHub annotations | ||
for (const error of errors) { | ||
core.error( | ||
`${file}:${error.lineNumber} - ${error.ruleId} - ${error.description}`, | ||
{ | ||
file, | ||
startLine: error.lineNumber, | ||
startColumn: error.column, | ||
endColumn: error.endColumn, | ||
title: 'Axe Linter' | ||
} | ||
) | ||
for (const [file, errors] of Object.entries(fileErrors)) { | ||
if (errors.length > 0) { | ||
// Add file heading | ||
core.summary | ||
.addHeading(`❌ Error${pluralize(errors.length)} in ${file}:`, 2) | ||
.addList( | ||
errors.map( | ||
(error) => | ||
`🔴 Line ${error.line}: ${error.ruleId} - ${error.description}` | ||
) | ||
) | ||
.addBreak() | ||
|
||
// Create GitHub annotations | ||
for (const error of errors) { | ||
core.error( | ||
`${file}:${error.line} - ${error.ruleId} - ${error.description}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is defined in both GH annotations but also in the workflow itself. Without the file and line number the error is not too helpful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you output errors in eslint stylish format, you don't need to manually create annotations, you can rely on GH Problem Matchers: =>
|
||
{ | ||
file, | ||
startLine: error.line, | ||
startColumn: error.column, | ||
endColumn: error.endColumn, | ||
title: 'Axe Linter' | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
// Add summary footer | ||
await core.summary | ||
.addBreak() | ||
.addRaw(`Found ${totalErrors} accessibility issue${pluralize(totalErrors)}`) | ||
.write() | ||
|
||
core.debug(`Found ${totalErrors} error${pluralize(totalErrors)}`) | ||
return totalErrors | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you could consider eslint stylish formatter style here? I guess this format will be more familiar to the community.
If it's not very late, I'd also use the the same format in action logs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can ask the team and see what their thoughts were on this. I don't see why this would be an issue