Skip to content

Commit

Permalink
feat: add failOnWarning on sql review
Browse files Browse the repository at this point in the history
  • Loading branch information
albertilagan committed Apr 25, 2024
1 parent fa01dfd commit 9123798
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .github/actions/sql-review/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ inputs:
database:
description: "The name of database. Example: instances/prod-instance/databases/example"
required: true
failOnWarnings:
description: "Fail job if sql review has warnings"
type: boolean
required: false
default: true
runs:
using: "node20"
main: "dist/index.js"
3 changes: 2 additions & 1 deletion .github/actions/sql-review/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function run() {
const token = core.getInput("token", { required: true });
const database = core.getInput("database", { required: true });
const extraHeaders = core.getInput('headers');
const failOnWarnings = core.getBooleanInput('failOnWarnings');
let headers = extraHeaders ? JSON.parse(extraHeaders) : {};
headers = Object.assign({ "Content-Type": "application/json", 'Authorization': `Bearer ${token}` }, headers);
const { owner, repo } = github.context.repo;
Expand Down Expand Up @@ -104,7 +105,7 @@ function run() {
const annotation = `::${advice.status} file=${file},line=${advice.line},col=${advice.column},title=${advice.title} (${advice.code})::${advice.content}. https://www.bytebase.com/docs/reference/error-code/advisor#${advice.code}`;
// Emit annotations for each advice
core.info(annotation);
if (advice.status === 'ERROR' || advice.status === 'WARNING') {
if (advice.status === 'ERROR' || (failOnWarnings && advice.status === 'WARNING')) {
hasErrorOrWarning = true;
}
});
Expand Down
3 changes: 2 additions & 1 deletion .github/actions/sql-review/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async function run(): Promise<void> {
const token = core.getInput("token", { required: true })
const database = core.getInput("database", { required: true })
const extraHeaders: string = core.getInput('headers');
const failOnWarnings: boolean = core.getBooleanInput('failOnWarnings');

let headers: HeadersInit = extraHeaders ? JSON.parse(extraHeaders) : {};
headers = {
Expand Down Expand Up @@ -83,7 +84,7 @@ async function run(): Promise<void> {
// Emit annotations for each advice
core.info(annotation);

if (advice.status === 'ERROR' || advice.status === 'WARNING') {
if (advice.status === 'ERROR' || (failOnWarnings && advice.status === 'WARNING')) {
hasErrorOrWarning = true;
}
});
Expand Down

0 comments on commit 9123798

Please sign in to comment.