-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(todo GH-808) Implement pdk release subcommands
- Loading branch information
1 parent
269b478
commit 82cdafb
Showing
4 changed files
with
189 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'pdk/cli/release' | ||
|
||
module PDK::CLI | ||
@release_prep_cmd = @release_cmd.define_command do | ||
name 'prep' | ||
usage _('prep [options]') | ||
summary _('Performs all the pre-release checks to ensure module is ready to be released') | ||
|
||
flag nil, :force, _('Release the module automatically, with no prompts.') | ||
flag nil, :'skip-validation', _('Skips the module validation check.') | ||
flag nil, :'skip-changelog', _('Skips the automatic changelog generation.') | ||
flag nil, :'skip-dependency', _('Skips the module dependency check.') | ||
flag nil, :'skip-documentation', _('Skips the documentation update.') | ||
|
||
option nil, :version, _('Update the module to the specified version prior to release. When not specified, the new version will be computed from the Changelog where possible.'), | ||
argument: :required | ||
|
||
run do |opts, _args, cmd| | ||
# Make sure build is being run in a valid module directory with a metadata.json | ||
PDK::CLI::Util.ensure_in_module!( | ||
message: _("`pdk release #{cmd.name}` can only be run from inside a valid module with a metadata.json."), | ||
log_level: :info, | ||
) | ||
|
||
opts[:'skip-build'] = true | ||
opts[:'skip-publish'] = true | ||
|
||
Release.prepare_interview(opts) unless opts[:force] | ||
|
||
Release.send_analytics("release #{cmd.name}", opts) | ||
|
||
release = PDK::Module::Release.new(nil, opts) | ||
|
||
Release.module_compatibility_checks!(release, opts) | ||
|
||
release.run | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'spec_helper' | ||
require 'pdk/cli' | ||
|
||
describe 'PDK::CLI release prep' do | ||
let(:help_text) { a_string_matching(%r{^USAGE\s+pdk release prep}m) } | ||
|
||
context 'when not run from inside a module' do | ||
include_context 'run outside module' | ||
|
||
it 'exits with an error' do | ||
expect(logger).to receive(:error).with(a_string_matching(%r{must be run from inside a valid module})) | ||
|
||
expect { PDK::CLI.run(%w[new class test_class]) }.to exit_nonzero | ||
end | ||
|
||
it 'does not submit the command to analytics' do | ||
expect(analytics).not_to receive(:screen_view) | ||
|
||
expect { PDK::CLI.run(%w[new class test_class]) }.to exit_nonzero | ||
end | ||
end | ||
|
||
context 'when run from inside a module' do | ||
let(:release_object) do | ||
instance_double( | ||
PDK::Module::Release, | ||
pdk_compatible?: true, | ||
module_metadata: mock_metadata_obj, | ||
run: nil, | ||
) | ||
end | ||
|
||
let(:mock_metadata_obj) do | ||
instance_double( | ||
PDK::Module::Metadata, | ||
forge_ready?: true, | ||
) | ||
end | ||
|
||
before(:each) do | ||
allow(PDK::CLI::Util).to receive(:ensure_in_module!).and_return(nil) | ||
allow(PDK::Module::Release).to receive(:new).and_return(release_object) | ||
allow(PDK::Util).to receive(:exit_process).and_raise('exit_process mock should not be called') | ||
end | ||
|
||
it 'calls PDK::Module::Release.run' do | ||
expect(release_object).to receive(:run) | ||
|
||
expect { PDK::CLI.run(%w[release prep --force]) }.not_to raise_error | ||
end | ||
|
||
it 'skips building and publishing' do | ||
expect(PDK::Module::Release).to receive(:new).with(Object, hash_including(:'skip-build' => true, :'skip-publish' => true)) | ||
|
||
expect { PDK::CLI.run(%w[release prep --force]) }.not_to raise_error | ||
end | ||
|
||
it 'does not start an interview when --force is used' do | ||
expect(PDK::CLI::Util::Interview).to receive(:new).never | ||
|
||
PDK::CLI.run(%w[release prep --force]) | ||
end | ||
|
||
it 'calls PDK::CLI::Release.module_compatibility_checks!' do | ||
expect(PDK::CLI::Release).to receive(:module_compatibility_checks!).and_return(nil) | ||
|
||
expect { PDK::CLI.run(%w[release prep --force]) }.not_to raise_error | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters