Skip to content

Commit c7ae51b

Browse files
committed
Make ActionState available and add test
1 parent 1f9caf0 commit c7ae51b

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/init-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ async function run(
256256
const repositoryProperties = repositoryPropertiesResult.orElse({});
257257

258258
// Create a unique identifier for this run.
259-
getJobUUID(logger);
259+
getJobUUID(actionState);
260260

261261
core.exportVariable(EnvVar.INIT_ACTION_HAS_RUN, "true");
262262

src/setup-codeql-action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async function sendCompletedStatusReport(
9595

9696
/** The main behaviour of this action. */
9797
async function run(
98-
actionState: ActionState<["Base", "Logger", "Actions"]>,
98+
actionState: ActionState<["Base", "Logger", "Env", "Actions"]>,
9999
): Promise<void> {
100100
// To capture errors appropriately, keep as much code within the try-catch as
101101
// possible, and only use safe functions outside.
@@ -141,7 +141,7 @@ async function run(
141141
const actionStateWithFeatures = { ...actionState, features };
142142

143143
// Create a unique identifier for this run.
144-
getJobUUID(logger);
144+
getJobUUID(actionState);
145145

146146
const statusReportBase = await createStatusReportBase(
147147
ActionName.SetupCodeQL,

src/status-report.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from "ava";
22
import * as sinon from "sinon";
3+
import * as uuid from "uuid";
34

45
import * as actionsUtil from "./actions-util";
56
import { Config } from "./config-utils";
@@ -12,6 +13,7 @@ import {
1213
createInitWithConfigStatusReport,
1314
createStatusReportBase,
1415
getActionsStatus,
16+
getJobUUID,
1517
InitStatusReport,
1618
InitWithConfigStatusReport,
1719
} from "./status-report";
@@ -20,11 +22,18 @@ import {
2022
setupActionsVars,
2123
createTestConfig,
2224
makeMacro,
25+
callee,
2326
} from "./testing-utils";
2427
import { BuildMode, ConfigurationError, withTmpDir, wrapError } from "./util";
2528

2629
setupTests(test);
2730

31+
test("getJobUUID - generates valid UUIDs", async (t) => {
32+
await callee(getJobUUID)
33+
.withArgs()
34+
.passes((val) => t.true(uuid.validate(val)));
35+
});
36+
2837
function setupEnvironmentAndStub(tmpDir: string) {
2938
setupActionsVars(tmpDir, tmpDir, {
3039
GITHUB_EVENT_NAME: "dynamic",

src/status-report.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as os from "os";
33
import * as core from "@actions/core";
44
import { v4 as uuidV4 } from "uuid";
55

6+
import type { ActionState } from "./action-common";
67
import {
78
getWorkflowEventName,
89
getOptionalInput,
@@ -64,9 +65,9 @@ export function getDisplayActionName(actionName: ActionName): string {
6465
* Creates a UUIDv4 for the analysis and returns it.
6566
* The generated UUID is also exported as an environment variable.
6667
*/
67-
export function getJobUUID(logger: Logger) {
68+
export function getJobUUID(action: ActionState<["Logger", "ReadOnlyEnv"]>) {
6869
const jobRunUuid = uuidV4();
69-
logger.info(`Job run UUID is ${jobRunUuid}.`);
70+
action.logger.info(`Job run UUID is ${jobRunUuid}.`);
7071

7172
core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid);
7273
return jobRunUuid;

0 commit comments

Comments
 (0)