Skip to content

Commit fc165e5

Browse files
authored
feat(node): Detect release from more providers (#12529)
ref #12513 This PR upgrades release detection for Node and Vercel Edge SDKs. This change adds release name detection for: - GitLab CI - AppVeyor - AWS Amplify - Azure Pipelines - Bitrise - Buddy CI - Cirrus CI - Codefresh - Codemagic - Semaphore CI - Travis CI - CloudBees CodeShip - Coolify - Jenkins - TeamCity - Woodpecker CI Based on getsentry/sentry-javascript-bundler-plugins#549 Supercedes #12507
1 parent 6f953ab commit fc165e5

File tree

2 files changed

+166
-22
lines changed

2 files changed

+166
-22
lines changed

packages/node/src/sdk/api.ts

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { createGetModuleFromFilename } from '../utils/module';
77
/**
88
* Returns a release dynamically from environment variables.
99
*/
10+
// eslint-disable-next-line complexity
1011
export function getSentryRelease(fallback?: string): string | undefined {
1112
// Always read first as Sentry takes this as precedence
1213
if (process.env.SENTRY_RELEASE) {
@@ -18,22 +19,91 @@ export function getSentryRelease(fallback?: string): string | undefined {
1819
return GLOBAL_OBJ.SENTRY_RELEASE.id;
1920
}
2021

21-
return (
22+
// This list is in approximate alpha order, separated into 3 categories:
23+
// 1. Git providers
24+
// 2. CI providers with specific environment variables (has the provider name in the variable name)
25+
// 3. CI providers with generic environment variables (checked for last to prevent possible false positives)
26+
27+
const possibleReleaseNameOfGitProvider =
2228
// GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
23-
process.env.GITHUB_SHA ||
24-
// Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
25-
process.env.COMMIT_REF ||
29+
process.env['GITHUB_SHA'] ||
30+
// GitLab CI - https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
31+
process.env['CI_MERGE_REQUEST_SOURCE_BRANCH_SHA'] ||
32+
process.env['CI_BUILD_REF'] ||
33+
process.env['CI_COMMIT_SHA'] ||
34+
// Bitbucket - https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
35+
process.env['BITBUCKET_COMMIT'];
36+
37+
const possibleReleaseNameOfCiProvidersWithSpecificEnvVar =
38+
// AppVeyor - https://www.appveyor.com/docs/environment-variables/
39+
process.env['APPVEYOR_PULL_REQUEST_HEAD_COMMIT'] ||
40+
process.env['APPVEYOR_REPO_COMMIT'] ||
41+
// AWS CodeBuild - https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
42+
process.env['CODEBUILD_RESOLVED_SOURCE_VERSION'] ||
43+
// AWS Amplify - https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html
44+
process.env['AWS_COMMIT_ID'] ||
45+
// Azure Pipelines - https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
46+
process.env['BUILD_SOURCEVERSION'] ||
47+
// Bitrise - https://devcenter.bitrise.io/builds/available-environment-variables/
48+
process.env['GIT_CLONE_COMMIT_HASH'] ||
49+
// Buddy CI - https://buddy.works/docs/pipelines/environment-variables#default-environment-variables
50+
process.env['BUDDY_EXECUTION_REVISION'] ||
51+
// Builtkite - https://buildkite.com/docs/pipelines/environment-variables
52+
process.env['BUILDKITE_COMMIT'] ||
53+
// CircleCI - https://circleci.com/docs/variables/
54+
process.env['CIRCLE_SHA1'] ||
55+
// Cirrus CI - https://cirrus-ci.org/guide/writing-tasks/#environment-variables
56+
process.env['CIRRUS_CHANGE_IN_REPO'] ||
57+
// Codefresh - https://codefresh.io/docs/docs/codefresh-yaml/variables/
58+
process.env['CF_REVISION'] ||
59+
// Codemagic - https://docs.codemagic.io/yaml-basic-configuration/environment-variables/
60+
process.env['CM_COMMIT'] ||
61+
// Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
62+
process.env['CF_PAGES_COMMIT_SHA'] ||
63+
// Drone - https://docs.drone.io/pipeline/environment/reference/
64+
process.env['DRONE_COMMIT_SHA'] ||
65+
// Flightcontrol - https://www.flightcontrol.dev/docs/guides/flightcontrol/environment-variables#built-in-environment-variables
66+
process.env['FC_GIT_COMMIT_SHA'] ||
67+
// Heroku #1 https://devcenter.heroku.com/articles/heroku-ci
68+
process.env['HEROKU_TEST_RUN_COMMIT_VERSION'] ||
69+
// Heroku #2 https://docs.sentry.io/product/integrations/deployment/heroku/#configure-releases
70+
process.env['HEROKU_SLUG_COMMIT'] ||
71+
// Render - https://render.com/docs/environment-variables
72+
process.env['RENDER_GIT_COMMIT'] ||
73+
// Semaphore CI - https://docs.semaphoreci.com/ci-cd-environment/environment-variables
74+
process.env['SEMAPHORE_GIT_SHA'] ||
75+
// TravisCI - https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
76+
process.env['TRAVIS_PULL_REQUEST_SHA'] ||
2677
// Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
27-
process.env.VERCEL_GIT_COMMIT_SHA ||
28-
process.env.VERCEL_GITHUB_COMMIT_SHA ||
29-
process.env.VERCEL_GITLAB_COMMIT_SHA ||
30-
process.env.VERCEL_BITBUCKET_COMMIT_SHA ||
78+
process.env['VERCEL_GIT_COMMIT_SHA'] ||
79+
process.env['VERCEL_GITHUB_COMMIT_SHA'] ||
80+
process.env['VERCEL_GITLAB_COMMIT_SHA'] ||
81+
process.env['VERCEL_BITBUCKET_COMMIT_SHA'] ||
3182
// Zeit (now known as Vercel)
32-
process.env.ZEIT_GITHUB_COMMIT_SHA ||
33-
process.env.ZEIT_GITLAB_COMMIT_SHA ||
34-
process.env.ZEIT_BITBUCKET_COMMIT_SHA ||
35-
// Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
36-
process.env.CF_PAGES_COMMIT_SHA ||
83+
process.env['ZEIT_GITHUB_COMMIT_SHA'] ||
84+
process.env['ZEIT_GITLAB_COMMIT_SHA'] ||
85+
process.env['ZEIT_BITBUCKET_COMMIT_SHA'];
86+
87+
const possibleReleaseNameOfCiProvidersWithGenericEnvVar =
88+
// CloudBees CodeShip - https://docs.cloudbees.com/docs/cloudbees-codeship/latest/pro-builds-and-configuration/environment-variables
89+
process.env['CI_COMMIT_ID'] ||
90+
// Coolify - https://coolify.io/docs/knowledge-base/environment-variables
91+
process.env['SOURCE_COMMIT'] ||
92+
// Heroku #3 https://devcenter.heroku.com/changelog-items/630
93+
process.env['SOURCE_VERSION'] ||
94+
// Jenkins - https://plugins.jenkins.io/git/#environment-variables
95+
process.env['GIT_COMMIT'] ||
96+
// Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
97+
process.env['COMMIT_REF'] ||
98+
// TeamCity - https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html
99+
process.env['BUILD_VCS_NUMBER'] ||
100+
// Woodpecker CI - https://woodpecker-ci.org/docs/usage/environment
101+
process.env['CI_COMMIT_SHA'];
102+
103+
return (
104+
possibleReleaseNameOfGitProvider ||
105+
possibleReleaseNameOfCiProvidersWithSpecificEnvVar ||
106+
possibleReleaseNameOfCiProvidersWithGenericEnvVar ||
37107
fallback
38108
);
39109
}

packages/vercel-edge/src/sdk.ts

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export function init(options: VercelEdgeOptions = {}): void {
8282
/**
8383
* Returns a release dynamically from environment variables.
8484
*/
85+
// eslint-disable-next-line complexity
8586
export function getSentryRelease(fallback?: string): string | undefined {
8687
// Always read first as Sentry takes this as precedence
8788
if (process.env.SENTRY_RELEASE) {
@@ -93,18 +94,91 @@ export function getSentryRelease(fallback?: string): string | undefined {
9394
return GLOBAL_OBJ.SENTRY_RELEASE.id;
9495
}
9596

96-
return (
97+
// This list is in approximate alpha order, separated into 3 categories:
98+
// 1. Git providers
99+
// 2. CI providers with specific environment variables (has the provider name in the variable name)
100+
// 3. CI providers with generic environment variables (checked for last to prevent possible false positives)
101+
102+
const possibleReleaseNameOfGitProvider =
97103
// GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
98-
process.env.GITHUB_SHA ||
104+
process.env['GITHUB_SHA'] ||
105+
// GitLab CI - https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
106+
process.env['CI_MERGE_REQUEST_SOURCE_BRANCH_SHA'] ||
107+
process.env['CI_BUILD_REF'] ||
108+
process.env['CI_COMMIT_SHA'] ||
109+
// Bitbucket - https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
110+
process.env['BITBUCKET_COMMIT'];
111+
112+
const possibleReleaseNameOfCiProvidersWithSpecificEnvVar =
113+
// AppVeyor - https://www.appveyor.com/docs/environment-variables/
114+
process.env['APPVEYOR_PULL_REQUEST_HEAD_COMMIT'] ||
115+
process.env['APPVEYOR_REPO_COMMIT'] ||
116+
// AWS CodeBuild - https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
117+
process.env['CODEBUILD_RESOLVED_SOURCE_VERSION'] ||
118+
// AWS Amplify - https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html
119+
process.env['AWS_COMMIT_ID'] ||
120+
// Azure Pipelines - https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
121+
process.env['BUILD_SOURCEVERSION'] ||
122+
// Bitrise - https://devcenter.bitrise.io/builds/available-environment-variables/
123+
process.env['GIT_CLONE_COMMIT_HASH'] ||
124+
// Buddy CI - https://buddy.works/docs/pipelines/environment-variables#default-environment-variables
125+
process.env['BUDDY_EXECUTION_REVISION'] ||
126+
// Builtkite - https://buildkite.com/docs/pipelines/environment-variables
127+
process.env['BUILDKITE_COMMIT'] ||
128+
// CircleCI - https://circleci.com/docs/variables/
129+
process.env['CIRCLE_SHA1'] ||
130+
// Cirrus CI - https://cirrus-ci.org/guide/writing-tasks/#environment-variables
131+
process.env['CIRRUS_CHANGE_IN_REPO'] ||
132+
// Codefresh - https://codefresh.io/docs/docs/codefresh-yaml/variables/
133+
process.env['CF_REVISION'] ||
134+
// Codemagic - https://docs.codemagic.io/yaml-basic-configuration/environment-variables/
135+
process.env['CM_COMMIT'] ||
136+
// Cloudflare Pages - https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
137+
process.env['CF_PAGES_COMMIT_SHA'] ||
138+
// Drone - https://docs.drone.io/pipeline/environment/reference/
139+
process.env['DRONE_COMMIT_SHA'] ||
140+
// Flightcontrol - https://www.flightcontrol.dev/docs/guides/flightcontrol/environment-variables#built-in-environment-variables
141+
process.env['FC_GIT_COMMIT_SHA'] ||
142+
// Heroku #1 https://devcenter.heroku.com/articles/heroku-ci
143+
process.env['HEROKU_TEST_RUN_COMMIT_VERSION'] ||
144+
// Heroku #2 https://docs.sentry.io/product/integrations/deployment/heroku/#configure-releases
145+
process.env['HEROKU_SLUG_COMMIT'] ||
146+
// Render - https://render.com/docs/environment-variables
147+
process.env['RENDER_GIT_COMMIT'] ||
148+
// Semaphore CI - https://docs.semaphoreci.com/ci-cd-environment/environment-variables
149+
process.env['SEMAPHORE_GIT_SHA'] ||
150+
// TravisCI - https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
151+
process.env['TRAVIS_PULL_REQUEST_SHA'] ||
99152
// Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
100-
process.env.VERCEL_GIT_COMMIT_SHA ||
101-
process.env.VERCEL_GITHUB_COMMIT_SHA ||
102-
process.env.VERCEL_GITLAB_COMMIT_SHA ||
103-
process.env.VERCEL_BITBUCKET_COMMIT_SHA ||
153+
process.env['VERCEL_GIT_COMMIT_SHA'] ||
154+
process.env['VERCEL_GITHUB_COMMIT_SHA'] ||
155+
process.env['VERCEL_GITLAB_COMMIT_SHA'] ||
156+
process.env['VERCEL_BITBUCKET_COMMIT_SHA'] ||
104157
// Zeit (now known as Vercel)
105-
process.env.ZEIT_GITHUB_COMMIT_SHA ||
106-
process.env.ZEIT_GITLAB_COMMIT_SHA ||
107-
process.env.ZEIT_BITBUCKET_COMMIT_SHA ||
158+
process.env['ZEIT_GITHUB_COMMIT_SHA'] ||
159+
process.env['ZEIT_GITLAB_COMMIT_SHA'] ||
160+
process.env['ZEIT_BITBUCKET_COMMIT_SHA'];
161+
162+
const possibleReleaseNameOfCiProvidersWithGenericEnvVar =
163+
// CloudBees CodeShip - https://docs.cloudbees.com/docs/cloudbees-codeship/latest/pro-builds-and-configuration/environment-variables
164+
process.env['CI_COMMIT_ID'] ||
165+
// Coolify - https://coolify.io/docs/knowledge-base/environment-variables
166+
process.env['SOURCE_COMMIT'] ||
167+
// Heroku #3 https://devcenter.heroku.com/changelog-items/630
168+
process.env['SOURCE_VERSION'] ||
169+
// Jenkins - https://plugins.jenkins.io/git/#environment-variables
170+
process.env['GIT_COMMIT'] ||
171+
// Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
172+
process.env['COMMIT_REF'] ||
173+
// TeamCity - https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html
174+
process.env['BUILD_VCS_NUMBER'] ||
175+
// Woodpecker CI - https://woodpecker-ci.org/docs/usage/environment
176+
process.env['CI_COMMIT_SHA'];
177+
178+
return (
179+
possibleReleaseNameOfGitProvider ||
180+
possibleReleaseNameOfCiProvidersWithSpecificEnvVar ||
181+
possibleReleaseNameOfCiProvidersWithGenericEnvVar ||
108182
fallback
109183
);
110184
}

0 commit comments

Comments
 (0)