diff --git a/config/application.rb b/config/application.rb index bb13b4dd50..3f01f13856 100644 --- a/config/application.rb +++ b/config/application.rb @@ -24,6 +24,7 @@ require_relative "../lib/open_food_network/i18n_config" require_relative '../lib/spree/core/environment' require_relative '../lib/spree/core/mail_interceptor' require_relative "../lib/i18n_digests" +require_relative "../lib/git_utils" if defined?(Bundler) # If you precompile assets before deploying to production, use this line @@ -34,8 +35,8 @@ end module Openfoodnetwork class Application < Rails::Application - # Store a description of the current version, with linebreak trimmed - config.x.git_version = `git describe --tags --dirty=-modified`.strip + # Store a description of the current version + config.x.git_version = GitUtils::git_version config.after_initialize do # We need this here because the test env file loads before the Spree engine is loaded diff --git a/lib/git_utils.rb b/lib/git_utils.rb new file mode 100644 index 0000000000..d7a8d1bad9 --- /dev/null +++ b/lib/git_utils.rb @@ -0,0 +1,15 @@ +class GitUtils + # Generate a description of the git version based on latest tag. + # Eg: "v4.4.4-156-g8afcd82-modified" + # - tag name + # - number of commits since tag + # - commit ID + # - "modified" if uncommitted changes + # + def self.git_version + # Capture stderr so that confusing errors aren't shown in comand output + stdout, _stderr, _status = Open3.capture3("git describe --tags --dirty=-modified") + # Strip trailing linebreak + stdout.strip + end +end