Skip to content

Commit 1f9caf0

Browse files
committed
Refactor jobRunUuid init into a function
Use in `init` and `setup-codeql` actions
1 parent 18420e3 commit 1f9caf0

4 files changed

Lines changed: 70 additions & 58 deletions

File tree

lib/entry-points.js

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

src/init-action.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as path from "path";
44
import * as core from "@actions/core";
55
import * as io from "@actions/io";
66
import * as semver from "semver";
7-
import { v4 as uuidV4 } from "uuid";
87

98
import { Action, ActionState, runInActions } from "./action-common";
109
import {
@@ -69,6 +68,7 @@ import {
6968
createInitWithConfigStatusReport,
7069
createStatusReportBase,
7170
getActionsStatus,
71+
getJobUUID,
7272
sendStatusReport,
7373
} from "./status-report";
7474
import { ToolsDownloadStatusReport } from "./tools-download";
@@ -256,9 +256,7 @@ async function run(
256256
const repositoryProperties = repositoryPropertiesResult.orElse({});
257257

258258
// Create a unique identifier for this run.
259-
const jobRunUuid = uuidV4();
260-
logger.info(`Job run UUID is ${jobRunUuid}.`);
261-
core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid);
259+
getJobUUID(logger);
262260

263261
core.exportVariable(EnvVar.INIT_ACTION_HAS_RUN, "true");
264262

src/setup-codeql-action.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as core from "@actions/core";
2-
import { v4 as uuidV4 } from "uuid";
32

43
import { Action, ActionState, runInActions } from "./action-common";
54
import {
@@ -26,6 +25,7 @@ import {
2625
InitToolsDownloadFields,
2726
createStatusReportBase,
2827
getActionsStatus,
28+
getJobUUID,
2929
sendStatusReport,
3030
} from "./status-report";
3131
import { ToolsDownloadStatusReport } from "./tools-download";
@@ -140,9 +140,8 @@ async function run(
140140

141141
const actionStateWithFeatures = { ...actionState, features };
142142

143-
const jobRunUuid = uuidV4();
144-
logger.info(`Job run UUID is ${jobRunUuid}.`);
145-
core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid);
143+
// Create a unique identifier for this run.
144+
getJobUUID(logger);
146145

147146
const statusReportBase = await createStatusReportBase(
148147
ActionName.SetupCodeQL,

src/status-report.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as os from "os";
22

33
import * as core from "@actions/core";
4+
import { v4 as uuidV4 } from "uuid";
45

56
import {
67
getWorkflowEventName,
@@ -59,6 +60,18 @@ export function getDisplayActionName(actionName: ActionName): string {
5960
return actionName;
6061
}
6162

63+
/**
64+
* Creates a UUIDv4 for the analysis and returns it.
65+
* The generated UUID is also exported as an environment variable.
66+
*/
67+
export function getJobUUID(logger: Logger) {
68+
const jobRunUuid = uuidV4();
69+
logger.info(`Job run UUID is ${jobRunUuid}.`);
70+
71+
core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid);
72+
return jobRunUuid;
73+
}
74+
6275
/**
6376
* @returns a boolean indicating whether the analysis is considered to be first party.
6477
*

0 commit comments

Comments
 (0)