Skip to content

Commit

Permalink
fix: Make check runs work again
Browse files Browse the repository at this point in the history
  • Loading branch information
kewisch committed Sep 10, 2024
1 parent 2b52642 commit 9ee8b22
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
build:
name: "Build"
runs-on: ubuntu-latest
permissions:
checks: write
outputs:
name: ${{ steps.web-ext-build.outputs.name }}
steps:
Expand Down Expand Up @@ -61,7 +63,8 @@ jobs:
runs-on: ubuntu-latest
needs: build
env:
HAS_SIGN_KEY: ${{ secrets.AMO_SIGN_KEY != '' && secrets.AMO_SIGN_SECRET != '' }}
#HAS_SIGN_KEY: ${{ secrets.AMO_SIGN_KEY != '' && secrets.AMO_SIGN_SECRET != '' }}

Check warning on line 66 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build

66:8 [comments] missing starting space in comment
HAS_SIGN_KEY:
steps:
- name: "Checkout"
if: env.HAS_SIGN_KEY
Expand Down Expand Up @@ -115,8 +118,8 @@ jobs:
name: "Self-test: ATN release"
runs-on: ubuntu-latest
needs: build
env:
HAS_SIGN_KEY: ${{ secrets.ATN_SIGN_KEY != '' && secrets.ATN_SIGN_SECRET != '' }}
#env:

Check warning on line 121 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build

121:6 [comments] missing starting space in comment
#HAS_SIGN_KEY: ${{ secrets.ATN_SIGN_KEY != '' && secrets.ATN_SIGN_SECRET != '' }}

Check warning on line 122 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build

122:6 [comments] missing starting space in comment
steps:
- name: "Checkout"
if: env.HAS_SIGN_KEY
Expand Down
41 changes: 19 additions & 22 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,20 @@ export default class WebExtAction {
}

async cmd_lint() {
function linterToAnnotation(message) {
let level = message._type == "error" ? "failure" : message._type;
function linterToAnnotationProperty(data) {
return {
path: message.file || "none",
start_line: message.line || 1,
end_line: message.line || 1,
start_column: message.column,
end_column: message.column,
annotation_level: level,
message: message.description,
title: message.message
title: data.message,
file: data.file,
startLine: data.line || 1,
startColumn: data.column
};
}

function linterToString(message) {
let prefix = message._type[0].toUpperCase() + message._type.substr(1);
return `${prefix}: ${message.file}${":" + (message.line || "")} - ${message.message}`;
}

let check = new CheckRun("web-ext lint", github.context, this.options.token);
await check.create();

let results = await webExt.cmd.lint({
sourceDir: this.options.sourceDir,
artifactsDir: this.options.artifactsDir,
Expand All @@ -83,20 +76,24 @@ export default class WebExtAction {
shouldExitProgram: false
});

let nonfatal = results.notices.concat(results.warnings).map(linterToAnnotation);
let fatal = results.errors.map(linterToAnnotation);
let summary = results.summary;
let summaryLine = `${summary.errors} Errors, ${summary.warnings} Warnings, ${summary.notices} Notices`;
let annotations = results.errors.concat(results.warnings).concat(results.notices);

await check.complete(summaryLine, nonfatal, fatal);
if (annotations.length > 10) {
core[annotations[9]._type]("Only the first 9 linting messages are shown, please fix them first");
console.log(annotations.map(linterToString).join("\n") + "\n");
annotations.splice(9);
}

if (!check.ready) {
console.log(results.notices.concat(results.warnings).concat(results.errors).map(linterToString).join("\n") + "\n");
for (let message of annotations) {
core[message._type](message.description, linterToAnnotationProperty(message));
}
console.log(summaryLine);

if (fatal.length) {
let summary = results.summary;
let summaryLine = `${summary.errors} Errors, ${summary.warnings} Warnings, ${summary.notices} Notices`;
if (results.errors.length) {
throw new Error(summaryLine);
} else {
console.log(summaryLine);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/checkrun.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ export default class CheckRun {
}
}

async complete(errorCount, warningCount, annotations) {
async complete(errors, warnings, notices) {
if (!this.ready) {
return;
}

let conclusion = "success";
if (errorCount > 0) {
if (errors.length > 0) {
conclusion = "failure";
} else if (warningCount > 0) {
} else if (warnings.length > 0) {
conclusion = "neutral";
}

Expand All @@ -60,15 +60,15 @@ export default class CheckRun {
conclusion: conclusion,
output: {
title: this.name,
summary: `${errorCount} errors, ${warningCount} warnings`,
annotations: annotations,
summary: `${errors.length} errors, ${warnings.length} warnings, ${notices.length} notices`,
annotations: errors.concat(warnings).concat(notices)
},
};

try {
await this.octokit.rest.checks.update(data);
} catch (e) {
console.log(JSON.stringify(data, null, 2));
console.error(JSON.stringify(data, null, 2));
throw e;
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/extension/borderify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
Just draw a border round the document.body.
*/
document.body.style.border = "5px solid red";


var varia = "foo";

document.innerHTML = varia;

0 comments on commit 9ee8b22

Please sign in to comment.