Skip to content

Commit

Permalink
Continue after CLI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael B. Gale committed Jun 14, 2023
1 parent f239f49 commit 899b5a2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
17 changes: 14 additions & 3 deletions lib/resolve-environment-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/resolve-environment-action.js.map

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

41 changes: 28 additions & 13 deletions src/resolve-environment-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
sendStatusReport,
} from "./actions-util";
import { getGitHubVersion } from "./api-client";
import { CommandInvocationError } from "./codeql";
import * as configUtils from "./config-utils";
import { Language, resolveAlias } from "./languages";
import { getActionsLogger } from "./logging";
import { runResolveBuildEnvironment } from "./resolve-environment";
import { checkForTimeout, checkGitHubVersionInRange, wrapError } from "./util";

const ACTION_NAME = "resolve-environment";
const ENVIRONMENT_OUTPUT_NAME = "environment";

async function run() {
const startedAt = new Date();
Expand Down Expand Up @@ -48,21 +50,34 @@ async function run() {
workingDirectory,
language
);
core.setOutput("environment", result);
core.setOutput(ENVIRONMENT_OUTPUT_NAME, result);
} catch (unwrappedError) {
const error = wrapError(unwrappedError);
core.setFailed(
`Failed to resolve a build environment suitable for automatically building your code. ${error.message}`
);
await sendStatusReport(
await createStatusReportBase(
ACTION_NAME,
getActionsStatus(error),
startedAt,
error.message,
error.stack
)
);

if (error instanceof CommandInvocationError) {
// If the CLI failed to run successfully for whatever reason,
// we just return an empty JSON object and proceed with the workflow.
core.setOutput(ENVIRONMENT_OUTPUT_NAME, {});
logger.warning(
`Failed to resolve a build environment suitable for automatically building your code. ${error.message}`
);
} else {
// For any other error types, something has more seriously gone wrong and we fail.
core.setFailed(
`Failed to resolve a build environment suitable for automatically building your code. ${error.message}`
);

await sendStatusReport(
await createStatusReportBase(
ACTION_NAME,
getActionsStatus(error),
startedAt,
error.message,
error.stack
)
);
}

return;
}

Expand Down

0 comments on commit 899b5a2

Please sign in to comment.