refactor: extract ApplicationVersion version from sentry

This commit is contained in:
Colin Darie 2024-04-22 16:45:06 +02:00
parent 21507cf524
commit 0581c67d6c
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
3 changed files with 21 additions and 14 deletions

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class ApplicationVersion
@@current = nil
# Detect the current release version, which helps Sentry identifying the current release
# or can be used as cache key when for some contents susceptible to change between releases.
#
# The deploy process can write a "version" file at root
# containing a string identifying the release, like the sha256 commit used by its release.
# It defaults to a random string if the file is not found (so each restart will behave like a new version)
def self.current
@@current ||= begin
version = Rails.root.join('version')
version.readable? ? version.read.strip : SecureRandom.hex
end
@@current.presence
end
end