-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(GH-808) Implement pdk release prep and publish subcommands #813
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use a negative expectation rather than a negative matcher for consistency (here and in the other specs in this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops. Good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an extra commit as I found a bunch of other tests that should be changed as well.