@@ -7,6 +7,7 @@ import { createGetModuleFromFilename } from '../utils/module';
7
7
/**
8
8
* Returns a release dynamically from environment variables.
9
9
*/
10
+ // eslint-disable-next-line complexity
10
11
export function getSentryRelease ( fallback ?: string ) : string | undefined {
11
12
// Always read first as Sentry takes this as precedence
12
13
if ( process . env . SENTRY_RELEASE ) {
@@ -18,22 +19,91 @@ export function getSentryRelease(fallback?: string): string | undefined {
18
19
return GLOBAL_OBJ . SENTRY_RELEASE . id ;
19
20
}
20
21
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 =
22
28
// 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' ] ||
26
77
// 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' ] ||
31
82
// 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 ||
37
107
fallback
38
108
) ;
39
109
}
0 commit comments