|
1 | 1 | import * as os from "os"; |
2 | 2 |
|
3 | 3 | import * as core from "@actions/core"; |
4 | | -import { v4 as uuidV4 } from "uuid"; |
| 4 | +import * as uuid from "uuid"; |
5 | 5 |
|
6 | 6 | import type { ActionState } from "./action-common"; |
7 | 7 | import { |
@@ -62,11 +62,21 @@ export function getDisplayActionName(actionName: ActionName): string { |
62 | 62 | } |
63 | 63 |
|
64 | 64 | /** |
65 | | - * Creates a UUIDv4 for the analysis and returns it. |
66 | | - * The generated UUID is also exported as an environment variable. |
| 65 | + * Either creates a UUIDv4 for the analysis or retrieves an existing one from the |
| 66 | + * environment and returns it. |
| 67 | + * If a new UUID is generated, it is also exported as an environment variable. |
67 | 68 | */ |
68 | 69 | export function getJobUUID(action: ActionState<["Logger", "ReadOnlyEnv"]>) { |
69 | | - const jobRunUuid = uuidV4(); |
| 70 | + // Check if we already have a UUID for the analysis and return it if so. |
| 71 | + const existingJobRunUuid = action.env.getOptional(EnvVar.JOB_RUN_UUID); |
| 72 | + |
| 73 | + if (existingJobRunUuid !== undefined && uuid.validate(existingJobRunUuid)) { |
| 74 | + action.logger.info(`Existing job run UUID is ${existingJobRunUuid}.`); |
| 75 | + return existingJobRunUuid; |
| 76 | + } |
| 77 | + |
| 78 | + // Otherwise generate a new UUID. |
| 79 | + const jobRunUuid = uuid.v4(); |
70 | 80 | action.logger.info(`Job run UUID is ${jobRunUuid}.`); |
71 | 81 |
|
72 | 82 | core.exportVariable(EnvVar.JOB_RUN_UUID, jobRunUuid); |
|
0 commit comments