11import * as actionsCore from "@actions/core" ;
2- import { createHash } from "node:crypto" ;
2+ import { createHash , randomUUID } from "node:crypto" ;
33
44const OPTIONAL_VARIABLES = [ "INVOCATION_ID" ] ;
55
@@ -8,36 +8,56 @@ const OPTIONAL_VARIABLES = ["INVOCATION_ID"];
88 * JSON sent to server.
99 */
1010export type AnonymizedCorrelationHashes = {
11+ $anon_distinct_id : string ;
12+ $groups : Record < string , string | undefined > ;
13+ $session_id ?: string ;
1114 correlation_source : string ;
12- repository ?: string ;
13- run ?: string ;
14- run_differentiator ?: string ;
15- workflow ?: string ;
16- job ?: string ;
17- groups : Record < string , string | undefined > ;
15+ github_repository_hash ?: string ;
16+ github_workflow_hash ?: string ;
17+ github_workflow_job_hash ?: string ;
18+ github_workflow_run_differentiator_hash ?: string ;
19+ github_workflow_run_hash ?: string ;
1820 is_ci : boolean ;
1921} ;
2022
21- export function identify ( projectName : string ) : AnonymizedCorrelationHashes {
23+ export function identify ( ) : AnonymizedCorrelationHashes {
24+ const repository = hashEnvironmentVariables ( "GHR" , [
25+ "GITHUB_SERVER_URL" ,
26+ "GITHUB_REPOSITORY_OWNER" ,
27+ "GITHUB_REPOSITORY_OWNER_ID" ,
28+ "GITHUB_REPOSITORY" ,
29+ "GITHUB_REPOSITORY_ID" ,
30+ ] ) ;
31+
32+ const run_differentiator = hashEnvironmentVariables ( "GHWJA" , [
33+ "GITHUB_SERVER_URL" ,
34+ "GITHUB_REPOSITORY_OWNER" ,
35+ "GITHUB_REPOSITORY_OWNER_ID" ,
36+ "GITHUB_REPOSITORY" ,
37+ "GITHUB_REPOSITORY_ID" ,
38+ "GITHUB_WORKFLOW" ,
39+ "GITHUB_JOB" ,
40+ "GITHUB_RUN_ID" ,
41+ "GITHUB_RUN_NUMBER" ,
42+ "GITHUB_RUN_ATTEMPT" ,
43+ "INVOCATION_ID" ,
44+ ] ) ;
45+
2246 const ident : AnonymizedCorrelationHashes = {
47+ $anon_distinct_id : process . env [ "RUNNER_TRACKING_ID" ] || randomUUID ( ) ,
48+
2349 correlation_source : "github-actions" ,
2450
25- repository : hashEnvironmentVariables ( "GHR" , [
26- "GITHUB_SERVER_URL" ,
27- "GITHUB_REPOSITORY_OWNER" ,
28- "GITHUB_REPOSITORY_OWNER_ID" ,
29- "GITHUB_REPOSITORY" ,
30- "GITHUB_REPOSITORY_ID" ,
31- ] ) ,
32- workflow : hashEnvironmentVariables ( "GHW" , [
51+ github_repository_hash : repository ,
52+ github_workflow_hash : hashEnvironmentVariables ( "GHW" , [
3353 "GITHUB_SERVER_URL" ,
3454 "GITHUB_REPOSITORY_OWNER" ,
3555 "GITHUB_REPOSITORY_OWNER_ID" ,
3656 "GITHUB_REPOSITORY" ,
3757 "GITHUB_REPOSITORY_ID" ,
3858 "GITHUB_WORKFLOW" ,
3959 ] ) ,
40- job : hashEnvironmentVariables ( "GHWJ" , [
60+ github_workflow_job_hash : hashEnvironmentVariables ( "GHWJ" , [
4161 "GITHUB_SERVER_URL" ,
4262 "GITHUB_REPOSITORY_OWNER" ,
4363 "GITHUB_REPOSITORY_OWNER_ID" ,
@@ -46,17 +66,7 @@ export function identify(projectName: string): AnonymizedCorrelationHashes {
4666 "GITHUB_WORKFLOW" ,
4767 "GITHUB_JOB" ,
4868 ] ) ,
49- run : hashEnvironmentVariables ( "GHWJR" , [
50- "GITHUB_SERVER_URL" ,
51- "GITHUB_REPOSITORY_OWNER" ,
52- "GITHUB_REPOSITORY_OWNER_ID" ,
53- "GITHUB_REPOSITORY" ,
54- "GITHUB_REPOSITORY_ID" ,
55- "GITHUB_WORKFLOW" ,
56- "GITHUB_JOB" ,
57- "GITHUB_RUN_ID" ,
58- ] ) ,
59- run_differentiator : hashEnvironmentVariables ( "GHWJA" , [
69+ github_workflow_run_hash : hashEnvironmentVariables ( "GHWJR" , [
6070 "GITHUB_SERVER_URL" ,
6171 "GITHUB_REPOSITORY_OWNER" ,
6272 "GITHUB_REPOSITORY_OWNER_ID" ,
@@ -65,13 +75,11 @@ export function identify(projectName: string): AnonymizedCorrelationHashes {
6575 "GITHUB_WORKFLOW" ,
6676 "GITHUB_JOB" ,
6777 "GITHUB_RUN_ID" ,
68- "GITHUB_RUN_NUMBER" ,
69- "GITHUB_RUN_ATTEMPT" ,
70- "INVOCATION_ID" ,
7178 ] ) ,
72- groups : {
73- ci : "github-actions" ,
74- project : projectName ,
79+ github_workflow_run_differentiator_hash : run_differentiator ,
80+ $session_id : run_differentiator ,
81+ $groups : {
82+ github_repository : repository ,
7583 github_organization : hashEnvironmentVariables ( "GHO" , [
7684 "GITHUB_SERVER_URL" ,
7785 "GITHUB_REPOSITORY_OWNER" ,
0 commit comments