Skip to content

Commit dde5e36

Browse files
authored
fix(node-core,vercel-edge): Use HEROKU_BUILD_COMMIT env var for default release (#19617)
Add `HEROKU_BUILD_COMMIT` as the primary env var for detecting the release on Heroku, keeping `HEROKU_SLUG_COMMIT` as a fallback since it is deprecated by Heroku. Closes: #19615
1 parent d975bcd commit dde5e36

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

packages/node-core/src/sdk/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export function getSentryRelease(fallback?: string): string | undefined {
6666
process.env['FC_GIT_COMMIT_SHA'] ||
6767
// Heroku #1 https://devcenter.heroku.com/articles/heroku-ci
6868
process.env['HEROKU_TEST_RUN_COMMIT_VERSION'] ||
69-
// Heroku #2 https://docs.sentry.io/product/integrations/deployment/heroku/#configure-releases
69+
// Heroku #2 https://devcenter.heroku.com/articles/dyno-metadata#dyno-metadata
70+
process.env['HEROKU_BUILD_COMMIT'] ||
71+
// Heroku #3 (deprecated by Heroku, kept for backward compatibility)
7072
process.env['HEROKU_SLUG_COMMIT'] ||
7173
// Railway - https://docs.railway.app/reference/variables#git-variables
7274
process.env['RAILWAY_GIT_COMMIT_SHA'] ||
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { getSentryRelease } from '../../src/sdk/api';
3+
4+
// Higher-priority env vars that may be set on CI (e.g. GITHUB_SHA on GitHub Actions)
5+
// and would take precedence over the Heroku vars we're testing.
6+
const HIGHER_PRIORITY_ENV_VARS = [
7+
'SENTRY_RELEASE',
8+
'GITHUB_SHA',
9+
'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA',
10+
'CI_BUILD_REF',
11+
'CI_COMMIT_SHA',
12+
'BITBUCKET_COMMIT',
13+
];
14+
15+
beforeEach(() => {
16+
for (const key of HIGHER_PRIORITY_ENV_VARS) {
17+
vi.stubEnv(key, '');
18+
}
19+
});
20+
21+
afterEach(() => {
22+
vi.unstubAllEnvs();
23+
});
24+
25+
describe('getSentryRelease', () => {
26+
it('uses HEROKU_BUILD_COMMIT env var', () => {
27+
vi.stubEnv('HEROKU_BUILD_COMMIT', 'heroku-build-commit-sha');
28+
29+
expect(getSentryRelease()).toBe('heroku-build-commit-sha');
30+
});
31+
32+
it('falls back to HEROKU_SLUG_COMMIT if HEROKU_BUILD_COMMIT is not set', () => {
33+
vi.stubEnv('HEROKU_SLUG_COMMIT', 'heroku-slug-commit-sha');
34+
35+
expect(getSentryRelease()).toBe('heroku-slug-commit-sha');
36+
});
37+
38+
it('prefers HEROKU_BUILD_COMMIT over HEROKU_SLUG_COMMIT', () => {
39+
vi.stubEnv('HEROKU_BUILD_COMMIT', 'heroku-build-commit-sha');
40+
vi.stubEnv('HEROKU_SLUG_COMMIT', 'heroku-slug-commit-sha');
41+
42+
expect(getSentryRelease()).toBe('heroku-build-commit-sha');
43+
});
44+
});

packages/vercel-edge/src/sdk.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ export function getSentryRelease(fallback?: string): string | undefined {
265265
process.env['FC_GIT_COMMIT_SHA'] ||
266266
// Heroku #1 https://devcenter.heroku.com/articles/heroku-ci
267267
process.env['HEROKU_TEST_RUN_COMMIT_VERSION'] ||
268-
// Heroku #2 https://docs.sentry.io/product/integrations/deployment/heroku/#configure-releases
268+
// Heroku #2 https://devcenter.heroku.com/articles/dyno-metadata#dyno-metadata
269+
process.env['HEROKU_BUILD_COMMIT'] ||
270+
// Heroku #3 (deprecated by Heroku, kept for backward compatibility)
269271
process.env['HEROKU_SLUG_COMMIT'] ||
270272
// Railway - https://docs.railway.app/reference/variables#git-variables
271273
process.env['RAILWAY_GIT_COMMIT_SHA'] ||

0 commit comments

Comments
 (0)