Skip to content

Commit

Permalink
Merge pull request #14 from DeterminateSystems/graham/fh-271-detsys-t…
Browse files Browse the repository at this point in the history
…s-window-ids-arent-unique-across-a-matrix

Include the optional environment variable INVOCATION_ID in the differ…
  • Loading branch information
grahamc authored Apr 18, 2024
2 parents 57c3688 + 5ae4597 commit 1e6067d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
20 changes: 13 additions & 7 deletions dist/correlation.js

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

27 changes: 19 additions & 8 deletions src/correlation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as actionsCore from "@actions/core";
import { createHash } from "node:crypto";

const OPTIONAL_VARIABLES = ["INVOCATION_ID"];

export type AnonymizedCorrelationHashes = {
correlation_source: string;
repository?: string;
Expand Down Expand Up @@ -59,6 +61,7 @@ export function identify(projectName: string): AnonymizedCorrelationHashes {
"GITHUB_RUN_ID",
"GITHUB_RUN_NUMBER",
"GITHUB_RUN_ATTEMPT",
"INVOCATION_ID",
]),
groups: {
ci: "github-actions",
Expand All @@ -84,16 +87,24 @@ function hashEnvironmentVariables(
const hash = createHash("sha256");

for (const varName of variables) {
const value = process.env[varName];
let value = process.env[varName];

if (value === undefined) {
actionsCore.debug(
`Environment variable not set: ${varName} -- can't generate the requested identity`,
);
return undefined;
} else {
hash.update(value);
hash.update("\0");
if (OPTIONAL_VARIABLES.includes(varName)) {
actionsCore.debug(
`Optional environment variable not set: ${varName} -- substituting with the variable name`,
);
value = varName;
} else {
actionsCore.debug(
`Environment variable not set: ${varName} -- can't generate the requested identity`,
);
return undefined;
}
}

hash.update(value);
hash.update("\0");
}

return `${prefix}-${hash.digest("hex")}`;
Expand Down

0 comments on commit 1e6067d

Please sign in to comment.