-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1161 from DataDog/andrea.moscatelli/support-custo…
…m-tags-for-github-jobs Support custom tags and metrics for GH jobs
- Loading branch information
Showing
7 changed files
with
37 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,10 @@ export const PROVIDER_TO_DISPLAY_NAME = { | |
buddy: 'Buddy', | ||
} | ||
|
||
// DD_GITHUB_JOB_NAME is an override that is required for adding custom tags and metrics | ||
// to GHA jobs if the 'name' property is used. It's ok for it to be missing in case the name property is not used. | ||
const envAllowedToBeMissing = ['DD_GITHUB_JOB_NAME'] | ||
|
||
// Receives a string with the form 'John Doe <[email protected]>' | ||
// and returns { name: 'John Doe', email: 'john.doe@gmail.com' } | ||
const parseEmailAndName = (emailAndName: string | undefined) => { | ||
|
@@ -713,7 +717,14 @@ export const getCIEnv = (): {ciEnv: Record<string, string>; provider: string} => | |
|
||
if (process.env.GITHUB_ACTIONS || process.env.GITHUB_ACTION) { | ||
return { | ||
ciEnv: filterEnv(['GITHUB_SERVER_URL', 'GITHUB_REPOSITORY', 'GITHUB_RUN_ID', 'GITHUB_RUN_ATTEMPT']), | ||
ciEnv: filterEnv([ | ||
'GITHUB_SERVER_URL', | ||
'GITHUB_REPOSITORY', | ||
'GITHUB_RUN_ID', | ||
'GITHUB_RUN_ATTEMPT', | ||
'GITHUB_JOB', | ||
'DD_GITHUB_JOB_NAME', | ||
]), | ||
provider: 'github', | ||
} | ||
} | ||
|
@@ -760,20 +771,20 @@ export const getCIEnv = (): {ciEnv: Record<string, string>; provider: string} => | |
|
||
const filterEnv = (values: string[]): Record<string, string> => { | ||
const ciEnvs: Record<string, string> = {} | ||
const missing: string[] = [] | ||
const requiredMissing: string[] = [] | ||
|
||
values.forEach((envKey) => { | ||
const envValue = process.env[envKey] | ||
if (envValue) { | ||
ciEnvs[envKey] = envValue | ||
} else { | ||
missing.push(envKey) | ||
} else if (!envAllowedToBeMissing.includes(envKey)) { | ||
requiredMissing.push(envKey) | ||
} | ||
}) | ||
|
||
if (missing.length > 0) { | ||
if (requiredMissing.length > 0) { | ||
// Get the missing values for better error | ||
throw new Error(`Missing environment variables [${missing.toString()}]`) | ||
throw new Error(`Missing environment variables [${requiredMissing.toString()}]`) | ||
} | ||
|
||
return ciEnvs | ||
|