-
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.
(GH-808) Implement pdk release prep and publish subcommands
Previously the pdk release command was added. This commit adds the prep and publish subcommands as per PDK RFC 003. This commit also adds tests for new subcommands.
- Loading branch information
1 parent
269b478
commit c354423
Showing
6 changed files
with
312 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 _('(Experimental) Performs all the pre-release checks to ensure module is ready to be released') | ||
|
||
flag nil, :force, _('Prepare 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,40 @@ | ||
require 'pdk/cli/release' | ||
|
||
module PDK::CLI | ||
@release_publish_cmd = @release_cmd.define_command do | ||
name 'publish' | ||
usage _('publish [options] <tarball>') | ||
summary _('(Experimental) Publishes the module <tarball> to the Forge.') | ||
|
||
flag nil, :force, _('Publish the module automatically, with no prompts.') | ||
|
||
option nil, :'forge-upload-url', _('Set forge upload url path.'), | ||
argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases' | ||
|
||
option nil, :'forge-token', _('Set Forge API token.'), argument: :required, default: nil | ||
|
||
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-validation'] = true | ||
opts[:'skip-changelog'] = true | ||
opts[:'skip-dependency'] = true | ||
opts[:'skip-documentation'] = true | ||
opts[:'skip-build'] = true | ||
opts[:'skip-versionset'] = true | ||
opts[:force] = true unless PDK::CLI::Util.interactive? | ||
|
||
Release.prepare_publish_interview(TTY::Prompt.new(help_color: :cyan), opts) unless opts[:force] | ||
|
||
Release.send_analytics("release #{cmd.name}", opts) | ||
|
||
release = PDK::Module::Release.new(nil, 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,71 @@ | ||
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) } | ||
let(:cli_args) { %w[release prep] } | ||
|
||
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(cli_args) }.to exit_nonzero | ||
end | ||
|
||
it 'does not submit the command to analytics' do | ||
expect(analytics).not_to receive(:screen_view) | ||
|
||
expect { PDK::CLI.run(cli_args) }.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(cli_args.concat(%w[--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(cli_args.concat(%w[--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(cli_args.concat(%w[--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(cli_args.concat(%w[--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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require 'spec_helper' | ||
require 'pdk/cli' | ||
|
||
describe 'PDK::CLI release publish' do | ||
let(:help_text) { a_string_matching(%r{^USAGE\s+pdk release publish}m) } | ||
let(:cli_args) { %w[release publish] } | ||
|
||
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(cli_args) }.to exit_nonzero | ||
end | ||
|
||
it 'does not submit the command to analytics' do | ||
expect(analytics).not_to receive(:screen_view) | ||
|
||
expect { PDK::CLI.run(cli_args) }.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(cli_args.concat(%w[--force])) }.not_to raise_error | ||
end | ||
|
||
it 'skips all but publishing' do | ||
expect(PDK::Module::Release).to receive(:new).with( | ||
Object, | ||
hash_including( | ||
:'skip-validation' => true, | ||
:'skip-changelog' => true, | ||
:'skip-dependency' => true, | ||
:'skip-documentation' => true, | ||
:'skip-build' => true, | ||
), | ||
) | ||
|
||
expect { PDK::CLI.run(cli_args.concat(%w[--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(cli_args.concat(%w[--force])) | ||
end | ||
|
||
it 'implicitly uses --force in non-interactive environments' do | ||
allow(PDK::CLI::Util).to receive(:interactive?).and_return(false) | ||
expect(PDK::Module::Release).to receive(:new).with(Object, hash_including(force: true)) | ||
|
||
expect { PDK::CLI.run(cli_args) }.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