Skip to content

Commit 688bd62

Browse files
authored
Add release detection from Kamal deployment (#2895)
Kamal provides a KAMAL_VERSION environment variable in the containers it builds and deploys. It's the SHA of the commit the release is based on. - Added a path to use the environment variable in ReleaseDetector if set. It's done after looking for SENTRY_RELEASE, but before looking for a git repo. - Added spec for coverage.
1 parent e3ec142 commit 688bd62

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

sentry-ruby/lib/sentry/release_detector.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ReleaseDetector
66
class << self
77
def detect_release(project_root:, running_on_heroku:)
88
detect_release_from_env ||
9+
detect_release_from_kamal ||
910
detect_release_from_git ||
1011
detect_release_from_capistrano(project_root) ||
1112
detect_release_from_heroku(running_on_heroku)
@@ -31,6 +32,10 @@ def detect_release_from_git
3132
Sentry.sys_command("git rev-parse HEAD") if File.directory?(".git")
3233
end
3334

35+
def detect_release_from_kamal
36+
ENV["KAMAL_VERSION"]
37+
end
38+
3439
def detect_release_from_env
3540
ENV["SENTRY_RELEASE"]
3641
end

sentry-ruby/spec/sentry_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,15 @@
12351235
end
12361236
end
12371237

1238+
it 'uses `KAMAL_VERSION` env variable' do
1239+
ENV['KAMAL_VERSION'] = 'GIT_SHA'
1240+
1241+
described_class.init
1242+
expect(described_class.configuration.release).to eq('GIT_SHA')
1243+
1244+
ENV.delete('KAMAL_VERSION')
1245+
end
1246+
12381247
context "when git is available" do
12391248
before do
12401249
allow(File).to receive(:directory?).and_return(false)

0 commit comments

Comments
 (0)