Skip to content

Commit 7a6a2ca

Browse files
committed
Use runInActions for the resolve-environment action
1 parent 6c74506 commit 7a6a2ca

2 files changed

Lines changed: 46 additions & 69 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 20 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/resolve-environment-action.ts‎

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import * as core from "@actions/core";
22

3-
import {
4-
getActionVersion,
5-
getOptionalInput,
6-
getRequiredInput,
7-
getTemporaryDirectory,
8-
} from "./actions-util";
3+
import { runInActions, type Action, type ActionState } from "./action-common";
4+
import { getActionVersion, getTemporaryDirectory } from "./actions-util";
95
import { getGitHubVersion } from "./api-client";
106
import { CliError } from "./cli-errors";
117
import { Config, getConfig } from "./config-utils";
12-
import { getActionsLogger } from "./logging";
138
import { runResolveBuildEnvironment } from "./resolve-environment";
149
import {
1510
sendStatusReport,
16-
sendUnhandledErrorStatusReport,
1711
createStatusReportBase,
1812
getActionsStatus,
1913
ActionName,
@@ -24,25 +18,28 @@ import {
2418
checkForTimeout,
2519
checkGitHubVersionInRange,
2620
ConfigurationError,
27-
getErrorMessage,
2821
wrapError,
2922
} from "./util";
3023

3124
const ENVIRONMENT_OUTPUT_NAME = "environment";
3225

33-
async function run(startedAt: Date) {
26+
/**
27+
* The main functionality of the `resolve-environment` action is implemented by this function.
28+
* This is called once by {@link runInActions} after it is called in {@link runWrapper}.
29+
*/
30+
async function run(action: ActionState<["Base", "Logger", "Actions"]>) {
3431
// To capture errors appropriately, keep as much code within the try-catch as
3532
// possible, and only use safe functions outside.
3633

37-
const logger = getActionsLogger();
34+
const logger = action.logger;
3835

3936
let config: Config | undefined;
4037

4138
try {
4239
const statusReportBase = await createStatusReportBase(
43-
ActionName.ResolveEnvironment,
40+
action.name,
4441
"starting",
45-
startedAt,
42+
action.startedAt,
4643
config,
4744
await checkDiskUsage(logger),
4845
logger,
@@ -62,12 +59,13 @@ async function run(startedAt: Date) {
6259
);
6360
}
6461

65-
const workingDirectory = getOptionalInput("working-directory");
62+
const workingDirectory =
63+
action.actions.getOptionalInput("working-directory");
6664
const result = await runResolveBuildEnvironment(
6765
config.codeQLCmd,
6866
logger,
6967
workingDirectory,
70-
getRequiredInput("language"),
68+
action.actions.getRequiredInput("language"),
7169
);
7270
core.setOutput(ENVIRONMENT_OUTPUT_NAME, result);
7371
} catch (unwrappedError) {
@@ -82,14 +80,14 @@ async function run(startedAt: Date) {
8280
);
8381
} else {
8482
// For any other error types, something has more seriously gone wrong and we fail.
85-
core.setFailed(
83+
action.actions.setFailed(
8684
`Failed to resolve a build environment suitable for automatically building your code. ${error.message}`,
8785
);
8886

8987
const statusReportBase = await createStatusReportBase(
90-
ActionName.ResolveEnvironment,
88+
action.name,
9189
getActionsStatus(error),
92-
startedAt,
90+
action.startedAt,
9391
config,
9492
await checkDiskUsage(logger),
9593
logger,
@@ -105,9 +103,9 @@ async function run(startedAt: Date) {
105103
}
106104

107105
const statusReportBase = await createStatusReportBase(
108-
ActionName.ResolveEnvironment,
106+
action.name,
109107
"success",
110-
startedAt,
108+
action.startedAt,
111109
config,
112110
await checkDiskUsage(logger),
113111
logger,
@@ -117,23 +115,14 @@ async function run(startedAt: Date) {
117115
}
118116
}
119117

118+
/** Defines the `resolve-environment` action. */
119+
const resolveEnvironmentAction: Action = {
120+
name: ActionName.ResolveEnvironment,
121+
run,
122+
};
123+
124+
/** The main entry point for the `resolve-environment` action. */
120125
export async function runWrapper() {
121-
const startedAt = new Date();
122-
const logger = getActionsLogger();
123-
try {
124-
await run(startedAt);
125-
} catch (error) {
126-
core.setFailed(
127-
`${ActionName.ResolveEnvironment} action failed: ${getErrorMessage(
128-
error,
129-
)}`,
130-
);
131-
await sendUnhandledErrorStatusReport(
132-
ActionName.ResolveEnvironment,
133-
startedAt,
134-
error,
135-
logger,
136-
);
137-
}
126+
await runInActions(resolveEnvironmentAction);
138127
await checkForTimeout();
139128
}

0 commit comments

Comments
 (0)