Skip to content

Commit

Permalink
(PDK-715) Use correct module template branch/ref
Browse files Browse the repository at this point in the history
For gem installs, we need to make sure they use a compatible
module-template version, similar to what we do for package installs
in our build process. For development, we still want to use the
default git branch.
  • Loading branch information
bmjen committed Dec 4, 2017
1 parent 2fe6884 commit 19a2488
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lib/pdk/module/templatedir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ def initialize(path_or_url, module_metadata = {}, init = false)
# use.
temp_dir = PDK::Util.make_tmpdir_name('pdk-module-template')

clone_result = PDK::Util::Git.git('clone', path_or_url, '--branch', 'convert', temp_dir)
clone_result = if PDK::Util.package_install?
PDK::Util::Git.git('clone', path_or_url, temp_dir)
elsif PDK::Util.gem_install?
PDK::Util::Git.git('clone', path_or_url, '--branch', PDK::TEMPLATE_VERSION, temp_dir)
else # TODO: Once we decide on a branching strategy for the pdk-module-template, this needs to be updated.
PDK::Util::Git.git('clone', path_or_url, '--branch', 'convert', temp_dir)
end

unless clone_result[:exit_code].zero?
PDK.logger.error clone_result[:stdout]
PDK.logger.error clone_result[:stderr]
Expand Down Expand Up @@ -187,10 +194,7 @@ def validate_module_template!

unless File.directory?(@moduleroot_init) # rubocop:disable Style/GuardClause
# rubocop:disable Metrics/LineLength
raise ArgumentError, _("The template at '%{path}' does not contain a 'moduleroot_init/' directory, which indicates you are using an older style of template. Before continuing please use the --template_url flag when running the pdk new or convert commands to pass a new style template.") % { path: @path } unless @init

PDK.logger.warn(_("The template at '%{path}' doesn't seem to have a 'moduleroot_init' directory, this could indicate that you are using an older style of template.")) % { path: @path } # rubocop:disable Lint/Void
PDK.logger.warn(_('To pass in a new template you can use the --template_url flag when running the pdk new or convert commands.'))
raise ArgumentError, _("The template at '%{path}' does not contain a 'moduleroot_init/' directory, which indicates you are using an older style of template. Before continuing please use the --template-url flag when running the pdk new commands to pass a new style template.") % { path: @path }
# rubocop:enable Metrics/LineLength
end
end
Expand Down
7 changes: 6 additions & 1 deletion lib/pdk/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ def package_install?
end
module_function :package_install?

def development_mode?
PDK::VERSION.end_with? 'pre'
end
module_function :development_mode?

def gem_install?
!package_install?
!(package_install? || development_mode?)
end
module_function :gem_install?

Expand Down
1 change: 1 addition & 0 deletions lib/pdk/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module PDK
VERSION = '1.3.0.pre'.freeze
TEMPLATE_VERSION = '0.x'.freeze
end
32 changes: 32 additions & 0 deletions spec/unit/pdk/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,48 @@
end
end

describe '.development_mode?' do
subject { described_class.development_mode? }

context 'when version ends with pre' do
before(:each) do
stub_const('PDK::VERSION', '1.0.0.pre')
end

it { is_expected.to be true }
end

context 'when version does not end with pre' do
before(:each) do
stub_const('PDK::VERSION', '1.0.0')
end

it { is_expected.to be false }
end
end

describe '.gem_install?' do
subject { described_class.gem_install? }

before(:each) do
allow(described_class).to receive(:development_mode?).and_return(false)
end

context 'when there is no version file', version_file: false do
it { is_expected.to be true }
end

context 'when a version file is present', version_file: true do
it { is_expected.to be false }
end

context 'when a version file is present and in development mode is true', version_file: false do
before(:each) do
allow(described_class).to receive(:development_mode?).and_return(true)
end

it { is_expected.to be false }
end
end

describe '.pdk_package_basedir' do
Expand Down

0 comments on commit 19a2488

Please sign in to comment.