mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
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:
parent
d70ecf1c53
commit
4b5724ec02
|
@ -311,25 +311,44 @@ module Discourse
|
|||
def self.git_version
|
||||
return $git_version if $git_version
|
||||
|
||||
# load the version stamped by the "build:stamp" task
|
||||
f = Rails.root.to_s + "/config/version"
|
||||
require f if File.exists?("#{f}.rb")
|
||||
|
||||
begin
|
||||
$git_version ||= `git rev-parse HEAD`.strip
|
||||
rescue
|
||||
$git_version = Discourse::VERSION::STRING
|
||||
end
|
||||
git_cmd='git rev-parse HEAD'
|
||||
self.load_version_or_git(git_cmd, Discourse::VERSION::STRING) { $git_version }
|
||||
end
|
||||
|
||||
def self.git_branch
|
||||
return $git_branch if $git_branch
|
||||
|
||||
begin
|
||||
$git_branch ||= `git rev-parse --abbrev-ref HEAD`.strip
|
||||
rescue
|
||||
$git_branch = "unknown"
|
||||
git_cmd='git rev-parse --abbrev-ref HEAD'
|
||||
self.load_version_or_git(git_cmd, 'unknown') { $git_branch }
|
||||
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
|
||||
|
||||
# Either returns the site_contact_username user or the first admin.
|
||||
|
|
|
@ -7,7 +7,7 @@ module DiscourseUpdates
|
|||
DiscourseVersionCheck.new(
|
||||
installed_version: Discourse::VERSION::STRING,
|
||||
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,
|
||||
updated_at: nil
|
||||
)
|
||||
|
@ -17,7 +17,7 @@ module DiscourseUpdates
|
|||
critical_updates: critical_updates_available?,
|
||||
installed_version: Discourse::VERSION::STRING,
|
||||
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,
|
||||
git_branch: Discourse.git_branch,
|
||||
updated_at: updated_at
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
desc "stamp the current build with the git hash placed in version.rb"
|
||||
task "build:stamp" => :environment do
|
||||
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|
|
||||
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
|
||||
puts "Stamped current build with #{git_version}"
|
||||
puts "Stamped current build with #{git_version} #{git_branch} #{full_version}"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user