Extend config/version.rb with more informations (#5061)

This gives installations not using git checkouts
to provide all the informations needed for the
internal version checks and version display in
the dashboard.

The build:stamp rake task was extended to also
add the new informations.
This commit is contained in:
darix
2017-08-28 18:24:56 +02:00
committed by Sam
parent d70ecf1c53
commit 4b5724ec02
3 changed files with 42 additions and 18 deletions

View File

@ -311,25 +311,44 @@ module Discourse
def self.git_version def self.git_version
return $git_version if $git_version return $git_version if $git_version
# load the version stamped by the "build:stamp" task git_cmd='git rev-parse HEAD'
f = Rails.root.to_s + "/config/version" self.load_version_or_git(git_cmd, Discourse::VERSION::STRING) { $git_version }
require f if File.exists?("#{f}.rb")
begin
$git_version ||= `git rev-parse HEAD`.strip
rescue
$git_version = Discourse::VERSION::STRING
end
end end
def self.git_branch def self.git_branch
return $git_branch if $git_branch return $git_branch if $git_branch
git_cmd='git rev-parse --abbrev-ref HEAD'
begin self.load_version_or_git(git_cmd, 'unknown') { $git_branch }
$git_branch ||= `git rev-parse --abbrev-ref HEAD`.strip
rescue
$git_branch = "unknown"
end end
def self.full_version
return $full_version if $full_version
git_cmd='git describe --dirty --match "v[0-9]*"'
self.load_version_or_git(git_cmd, 'unknown') { $full_version }
end
def self.load_version_or_git(git_cmd, default_value)
version_file = "#{Rails.root}/config/version.rb"
version_value = false
if File.exists?(version_file)
require version_file
version_value = yield
end
# file does not exist or does not define the expected global variable
unless version_value
begin
version_value = `#{git_cmd}`.strip
rescue # sollte noch ausspezifiziert werden…
version_value = default_value
end
end
if version_value.empty?
version_value = default_value
end
version_value
end end
# Either returns the site_contact_username user or the first admin. # Either returns the site_contact_username user or the first admin.

View File

@ -7,7 +7,7 @@ module DiscourseUpdates
DiscourseVersionCheck.new( DiscourseVersionCheck.new(
installed_version: Discourse::VERSION::STRING, installed_version: Discourse::VERSION::STRING,
installed_sha: (Discourse.git_version == 'unknown' ? nil : Discourse.git_version), installed_sha: (Discourse.git_version == 'unknown' ? nil : Discourse.git_version),
installed_describe: `git describe --dirty --match "v[0-9]*"`, installed_describe: Discourse.full_version,
git_branch: Discourse.git_branch, git_branch: Discourse.git_branch,
updated_at: nil updated_at: nil
) )
@ -17,7 +17,7 @@ module DiscourseUpdates
critical_updates: critical_updates_available?, critical_updates: critical_updates_available?,
installed_version: Discourse::VERSION::STRING, installed_version: Discourse::VERSION::STRING,
installed_sha: (Discourse.git_version == 'unknown' ? nil : Discourse.git_version), installed_sha: (Discourse.git_version == 'unknown' ? nil : Discourse.git_version),
installed_describe: `git describe --dirty --match "v[0-9]*"`, installed_describe: Discourse.full_version,
missing_versions_count: missing_versions_count, missing_versions_count: missing_versions_count,
git_branch: Discourse.git_branch, git_branch: Discourse.git_branch,
updated_at: updated_at updated_at: updated_at

View File

@ -1,8 +1,13 @@
desc "stamp the current build with the git hash placed in version.rb" desc "stamp the current build with the git hash placed in version.rb"
task "build:stamp" => :environment do task "build:stamp" => :environment do
git_version = `git rev-parse HEAD`.strip git_version = `git rev-parse HEAD`.strip
git_branch = `git rev-parse --abbrev-ref HEAD`
full_version = `git describe --dirty --match "v[0-9]*"`
File.open(Rails.root.to_s + '/config/version.rb', 'w') do |f| File.open(Rails.root.to_s + '/config/version.rb', 'w') do |f|
f.write("$git_version = #{git_version.inspect}\n") f.write("$git_version = #{git_version.inspect}\n")
f.write("$git_branch = #{git_branch.inspect}\n")
f.write("$full_version = #{full_version.inspect}\n")
end end
puts "Stamped current build with #{git_version}" puts "Stamped current build with #{git_version} #{git_branch} #{full_version}"
end end