lib/pdk/module/update.rb in pdk-akerl-1.9.1.1 vs lib/pdk/module/update.rb in pdk-akerl-1.14.0.1
- old
+ new
@@ -4,10 +4,12 @@
module Module
class Update < Convert
GIT_DESCRIBE_PATTERN = %r{\A(?<base>.+?)-(?<additional_commits>\d+)-g(?<sha>.+)\Z}
def run
+ template_uri.git_ref = new_template_version
+
stage_changes!
if current_version == new_version
PDK.logger.debug _('This module is already up to date with version %{version} of the template.') % {
version: new_version,
@@ -37,33 +39,47 @@
update_manager.unlink_file(File.join('.bundle', 'config'))
end
update_manager.sync_changes!
- PDK::Util::Bundler.ensure_bundle! if needs_bundle_update?
+ if needs_bundle_update?
+ require 'pdk/util/bundler'
+ PDK::Util::Bundler.ensure_bundle!
+ end
+
print_result 'Update completed'
end
def module_metadata
@module_metadata ||= PDK::Module::Metadata.from_file('metadata.json')
rescue ArgumentError => e
raise PDK::CLI::ExitWithError, e.message
end
- def template_url
- @template_url ||= module_metadata.data['template-url']
+ def template_uri
+ @template_uri ||= PDK::Util::TemplateURI.new(module_metadata.data['template-url'])
end
def current_version
@current_version ||= describe_ref_to_s(current_template_version)
end
def new_version
@new_version ||= fetch_remote_version(new_template_version)
end
+ def new_template_version
+ return options[:'template-ref'] if options[:'template-ref']
+
+ if template_uri.default? && template_uri.ref_is_tag? && PDK::Util.package_install?
+ PDK::Util::TemplateURI.default_template_ref
+ else
+ template_uri.git_ref
+ end
+ end
+
private
def current_template_version
@current_template_version ||= module_metadata.data['template-ref']
end
@@ -71,38 +87,34 @@
def describe_ref_to_s(describe_ref)
data = GIT_DESCRIBE_PATTERN.match(describe_ref)
return data if data.nil?
- if data[:base].start_with?('heads/')
- "#{data[:base].gsub(%r{^heads/}, '')}@#{data[:sha]}"
+ if data[:base] =~ %r{^(?:heads|remotes)/}
+ "#{data[:base].gsub(%r{^(heads/|remotes/\w+?/)}, '')}@#{data[:sha]}"
else
data[:base]
end
end
- def new_template_version
- PDK::Util.default_template_ref
- end
+ def fetch_remote_version(template_ref)
+ return template_ref unless current_template_version.is_a?(String)
+ return template_ref if template_ref == PDK::TEMPLATE_REF
- def fetch_remote_version(version)
- return version unless version.include?('/')
-
- branch = version.partition('/').last
sha_length = GIT_DESCRIBE_PATTERN.match(current_template_version)[:sha].length - 1
- "#{branch}@#{PDK::Util::Git.ls_remote(template_url, "refs/heads/#{branch}")[0..sha_length]}"
+ "#{template_ref}@#{PDK::Util::Git.ls_remote(template_uri.git_remote, template_ref)[0..sha_length]}"
end
def update_message
- format_string = if template_url == PDK::Util.puppetlabs_template_url
+ format_string = if template_uri.default?
_('Updating %{module_name} using the default template, from %{current_version} to %{new_version}')
else
_('Updating %{module_name} using the template at %{template_url}, from %{current_version} to %{new_version}')
end
format_string % {
module_name: module_metadata.data['name'],
- template_url: template_url,
+ template_url: template_uri.git_remote,
current_version: current_version,
new_version: new_version,
}
end
end