2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
module Discourse
|
2019-01-25 22:19:01 +08:00
|
|
|
VERSION_REGEXP = /\A\d+\.\d+\.\d+(\.beta\d+)?\z/ unless defined? ::Discourse::VERSION_REGEXP
|
|
|
|
|
2020-07-07 05:48:00 +08:00
|
|
|
VERSION_COMPATIBILITY_FILENAME = ".discourse-compatibility"
|
|
|
|
|
2013-08-08 06:47:04 +08:00
|
|
|
# work around reloader
|
|
|
|
unless defined? ::Discourse::VERSION
|
2013-03-13 11:06:58 +08:00
|
|
|
module VERSION #:nodoc:
|
2018-01-04 05:54:55 +08:00
|
|
|
MAJOR = 2
|
2020-06-25 02:00:19 +08:00
|
|
|
MINOR = 6
|
2014-08-27 03:24:07 +08:00
|
|
|
TINY = 0
|
2020-06-25 02:00:19 +08:00
|
|
|
PRE = 'beta1'
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2013-03-13 11:06:58 +08:00
|
|
|
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2015-04-28 01:06:53 +08:00
|
|
|
|
|
|
|
def self.has_needed_version?(current, needed)
|
2020-06-29 15:52:33 +08:00
|
|
|
Gem::Version.new(current) >= Gem::Version.new(needed)
|
2015-04-28 01:06:53 +08:00
|
|
|
end
|
2020-07-07 05:48:00 +08:00
|
|
|
|
|
|
|
# lookup an external resource (theme/plugin)'s best compatible version
|
|
|
|
# compatible resource files are YAML, in the format:
|
|
|
|
# `discourse_version: plugin/theme git reference.` For example:
|
|
|
|
# 2.5.0.beta6: c4a6c17
|
|
|
|
# 2.5.0.beta4: d1d2d3f
|
|
|
|
# 2.5.0.beta2: bbffee
|
|
|
|
# 2.4.4.beta6: some-other-branch-ref
|
|
|
|
# 2.4.2.beta1: v1-tag
|
|
|
|
def self.find_compatible_resource(version_list)
|
|
|
|
|
|
|
|
return unless version_list
|
|
|
|
|
|
|
|
version_list = YAML.load(version_list).sort_by { |version, pin| Gem::Version.new(version) }.reverse
|
|
|
|
|
|
|
|
# If plugin compat version is listed as less than current Discourse version, take the version/hash listed before.
|
|
|
|
checkout_version = nil
|
|
|
|
version_list.each do |core_compat, target|
|
|
|
|
if Gem::Version.new(core_compat) == Gem::Version.new(::Discourse::VERSION::STRING) # Exact version match - return it
|
|
|
|
checkout_version = target
|
|
|
|
break
|
|
|
|
elsif Gem::Version.new(core_compat) < Gem::Version.new(::Discourse::VERSION::STRING) # Core is on a higher version than listed, use a later version
|
|
|
|
break
|
|
|
|
end
|
|
|
|
checkout_version = target
|
|
|
|
end
|
|
|
|
|
|
|
|
checkout_version
|
|
|
|
end
|
|
|
|
|
|
|
|
# Find a compatible resource from a git repo
|
|
|
|
def self.find_compatible_git_resource(path)
|
|
|
|
return unless File.directory?("#{path}/.git")
|
|
|
|
compat_resource, std_error, s = Open3.capture3("git -C '#{path}' show HEAD@{upstream}:#{Discourse::VERSION_COMPATIBILITY_FILENAME}")
|
|
|
|
Discourse.find_compatible_resource(compat_resource) if s.success?
|
|
|
|
end
|
2013-03-13 11:06:58 +08:00
|
|
|
end
|