Skip to content

Commit

Permalink
Showing 21 changed files with 96 additions and 34 deletions.
16 changes: 14 additions & 2 deletions lib/actions-util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions lib/analyze-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze-action.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions lib/autobuild-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/autobuild-action.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js.map
8 changes: 6 additions & 2 deletions lib/init.js
2 changes: 1 addition & 1 deletion lib/init.js.map
2 changes: 1 addition & 1 deletion lib/upload-sarif-action.js
2 changes: 1 addition & 1 deletion lib/upload-sarif-action.js.map
12 changes: 11 additions & 1 deletion lib/util.js
2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

32 changes: 29 additions & 3 deletions src/actions-util.ts
@@ -8,7 +8,12 @@ import * as yaml from "js-yaml";

import * as api from "./api-client";
import * as sharedEnv from "./shared-environment";
import { getRequiredEnvParam, GITHUB_DOTCOM_URL, isHTTPError } from "./util";
import {
getRequiredEnvParam,
GITHUB_DOTCOM_URL,
isHTTPError,
UserError,
} from "./util";

/**
* The utils in this module are meant to be run inside of the action only.
@@ -545,7 +550,12 @@ export async function getRef(): Promise<string> {
}

type ActionName = "init" | "autobuild" | "finish" | "upload-sarif";
type ActionStatus = "starting" | "aborted" | "success" | "failure";
type ActionStatus =
| "starting"
| "aborted"
| "success"
| "failure"
| "user-error";

export interface StatusReportBase {
/** ID of the workflow run containing the action run. */
@@ -588,6 +598,17 @@ export interface StatusReportBase {
exception?: string;
}

export function getActionsStatus(
error?: unknown,
otherFailureCause?: string
): ActionStatus {
if (error || otherFailureCause) {
return error instanceof UserError ? "user-error" : "failure";
} else {
return "success";
}
}

/**
* Compose a StatusReport.
*
@@ -650,7 +671,12 @@ export async function createStatusReportBase(
if (exception) {
statusReport.exception = exception;
}
if (status === "success" || status === "failure" || status === "aborted") {
if (
status === "success" ||
status === "failure" ||
status === "aborted" ||
status === "user-error"
) {
statusReport.completed_at = new Date().toISOString();
}
const matrix = getRequiredInput("matrix");
8 changes: 4 additions & 4 deletions src/analyze-action.ts
@@ -39,10 +39,10 @@ export async function sendStatusReport(
stats: AnalysisStatusReport | undefined,
error?: Error
) {
const status =
stats?.analyze_failure_language !== undefined || error !== undefined
? "failure"
: "success";
const status = actionsUtil.getActionsStatus(
error,
stats?.analyze_failure_language
);
const statusReportBase = await actionsUtil.createStatusReportBase(
"finish",
status,
6 changes: 2 additions & 4 deletions src/autobuild-action.ts
@@ -2,6 +2,7 @@ import * as core from "@actions/core";

import {
createStatusReportBase,
getActionsStatus,
getTemporaryDirectory,
sendStatusReport,
StatusReportBase,
@@ -30,10 +31,7 @@ async function sendCompletedStatusReport(
) {
initializeEnvironment(Mode.actions, pkg.version);

const status =
failingLanguage !== undefined || cause !== undefined
? "failure"
: "success";
const status = getActionsStatus(cause, failingLanguage);
const statusReportBase = await createStatusReportBase(
"autobuild",
status,
3 changes: 2 additions & 1 deletion src/init-action.ts
@@ -4,6 +4,7 @@ import * as core from "@actions/core";

import {
createStatusReportBase,
getActionsStatus,
getOptionalInput,
getRequiredInput,
getTemporaryDirectory,
@@ -289,7 +290,7 @@ async function run() {
await sendStatusReport(
await createStatusReportBase(
"init",
"failure",
getActionsStatus(error),
startedAt,
String(error),
error instanceof Error ? error.stack : undefined
7 changes: 6 additions & 1 deletion src/init.ts
@@ -119,9 +119,14 @@ export async function runInit(
e.message?.includes("Refusing to create databases") &&
e.message.includes("exists and is not an empty directory.")
) {
throw new Error(
throw new util.UserError(
`Is the "init" action called twice in the same job? ${e.message}`
);
} else if (
e instanceof Error &&
e.message?.includes("is not compatible with this CodeQL CLI")
) {
throw new util.UserError(e.message);
} else {
throw e;
}
2 changes: 1 addition & 1 deletion src/upload-sarif-action.ts
@@ -81,7 +81,7 @@ async function run() {
await actionsUtil.sendStatusReport(
await actionsUtil.createStatusReportBase(
"upload-sarif",
"failure",
actionsUtil.getActionsStatus(error),
startedAt,
message,
stack
10 changes: 10 additions & 0 deletions src/util.ts
@@ -580,6 +580,16 @@ export class HTTPError extends Error {
}
}

/**
* An Error class that indicates an error that occurred due to
* a misconfiguration of the action or the CodeQL CLI.
*/
export class UserError extends Error {
constructor(message: string) {
super(message);
}
}

export function isHTTPError(arg: any): arg is HTTPError {
return arg?.status !== undefined && Number.isInteger(arg.status);
}

0 comments on commit 3d93bb2

Please sign in to comment.