Skip to content

Commit

Permalink
improve version information
Browse files Browse the repository at this point in the history
  • Loading branch information
meltheadorable committed Jul 10, 2024
1 parent 27c1a4b commit 7d8191f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/controllers/ping_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def show
@tests = {}
@tests[:dj_running] = Utils::DelayedJobChecker.instance.ok?
@ok = @tests.values.all?
@version = Cnfg.system_version
@version = Cnfg.system_version(detailed: true)
render(layout: nil, formats: :text, status: @ok ? :ok : :service_unavailable)
end
end
49 changes: 37 additions & 12 deletions lib/config_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,33 @@ def offline_mode?
end

# read system version from file
def system_version
@system_version ||= File.read(Rails.root.join("VERSION")).strip
def system_version(detailed: false)
return @system_version if @system_version.present? && !detailed
return @detailed_system_version if @detailed_system_version.present?

case Rails.env
when "development!"
git_describe_tags = `git describe --tags`
git_branch = `git rev-parse --abbrev-ref HEAD`
@system_version = "#{git_describe_tags.strip} (#{git_branch.strip})"
@detailed_system_version = @system_version
else
version_file = File.read(Rails.root.join("VERSION")).strip if File.exist?(Rails.root.join("VERSION"))
version = version_file

@system_version = version
return @system_version unless detailed

revision_file = File.read(Rails.root.join("REVISION")) if File.exist?(Rails.root.join("REVISION"))
branch_file = File.read(Rails.root.join("BRANCH")) if File.exist?(Rails.root.join("BRANCH"))

revision = revision_file&.strip&.slice(0..8)&.then { |rev| "(#{rev})" }.presence
branch = branch_file&.strip&.then { |br| "[#{br}]" }.presence

@detailed_system_version = [version, revision, branch].compact.join(" ")
end

detailed ? @detailed_system_version : @system_version
end

# Locales we support that are displayed right-to-left.
Expand Down Expand Up @@ -59,7 +84,7 @@ def url_port
# Returns a hash of url options (port, protocol, host). Omits port if it's default for protocol.
def url_options
options = {protocol: url_protocol, host: url_host}
return options if url_protocol == "http" && url_port == 80 || url_protocol == "https" && url_port == 443
return options if (url_protocol == "http" && url_port == 80) || (url_protocol == "https" && url_port == 443)
options[:port] = url_port
options
end
Expand All @@ -73,19 +98,19 @@ def smtp_port
end

def smtp_domain
ENV["NEMO_SMTP_DOMAIN"]
ENV.fetch("NEMO_SMTP_DOMAIN", nil)
end

def smtp_authentication
ENV["NEMO_SMTP_AUTHENTICATION"]&.to_sym
end

def smtp_user_name
ENV["NEMO_SMTP_USER_NAME"]
ENV.fetch("NEMO_SMTP_USER_NAME", nil)
end

def smtp_password
ENV["NEMO_SMTP_PASSWORD"]
ENV.fetch("NEMO_SMTP_PASSWORD", nil)
end

# Returns a hash of SMTP options, omitting anything that's blank
Expand All @@ -102,31 +127,31 @@ def smtp_options
end

def google_maps_key
ENV["NEMO_GOOGLE_MAPS_API_KEY"]
ENV.fetch("NEMO_GOOGLE_MAPS_API_KEY", nil)
end

def scout_key
ENV["NEMO_SCOUT_KEY"]
ENV.fetch("NEMO_SCOUT_KEY", nil)
end

def sentry_dsn
ENV["NEMO_SENTRY_DSN"]
ENV.fetch("NEMO_SENTRY_DSN", nil)
end

def allow_missionless_sms?
ENV["NEMO_ALLOW_MISSIONLESS_SMS"] == "true"
end

def universal_sms_token
allow_missionless_sms? ? ENV["NEMO_UNIVERSAL_SMS_TOKEN"] : nil
allow_missionless_sms? ? ENV.fetch("NEMO_UNIVERSAL_SMS_TOKEN", nil) : nil
end

def recaptcha_public_key
ENV["NEMO_RECAPTCHA_PUBLIC_KEY"]
ENV.fetch("NEMO_RECAPTCHA_PUBLIC_KEY", nil)
end

def recaptcha_private_key
ENV["NEMO_RECAPTCHA_PRIVATE_KEY"]
ENV.fetch("NEMO_RECAPTCHA_PRIVATE_KEY", nil)
end

def storage_service
Expand Down

0 comments on commit 7d8191f

Please sign in to comment.