зеркало из https://github.com/github/ruby.git
[rubygems/rubygems] Make test framework/CI configuration for bundle gem consistent
* Add hints for --ci option https://github.com/rubygems/rubygems/commit/5f779f45b0
This commit is contained in:
Родитель
a80a5706b1
Коммит
8e3136a03b
|
@ -574,8 +574,10 @@ module Bundler
|
||||||
method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set gem.mit true`."
|
method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set gem.mit true`."
|
||||||
method_option :rubocop, :type => :boolean, :desc => "Add rubocop to the generated Rakefile and gemspec. Set a default with `bundle config set gem.rubocop true`."
|
method_option :rubocop, :type => :boolean, :desc => "Add rubocop to the generated Rakefile and gemspec. Set a default with `bundle config set gem.rubocop true`."
|
||||||
method_option :test, :type => :string, :lazy_default => Bundler.settings["gem.test"] || "", :aliases => "-t", :banner => "Use the specified test framework for your library",
|
method_option :test, :type => :string, :lazy_default => Bundler.settings["gem.test"] || "", :aliases => "-t", :banner => "Use the specified test framework for your library",
|
||||||
:desc => "Generate a test directory for your library, either rspec, minitest or test-unit. Set a default with `bundle config set gem.test rspec`."
|
:desc => "Generate a test directory for your library, either rspec, minitest or test-unit. Set a default with `bundle config set gem.test (rspec|minitest|test-unit)`."
|
||||||
method_option :ci, :type => :string, :desc => "Generate CI configuration, either GitHub Actions, Travis CI, GitLab CI or CircleCI. Set a default with `bundle config set gem.ci (github|travis|gitlab|circle)`"
|
method_option :ci, :type => :string, :lazy_default => Bundler.settings["gem.ci"] || "",
|
||||||
|
:desc => "Generate CI configuration, either GitHub Actions, Travis CI, GitLab CI or CircleCI. Set a default with `bundle config set gem.ci (github|travis|gitlab|circle)`"
|
||||||
|
|
||||||
def gem(name)
|
def gem(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,12 @@ module Bundler
|
||||||
"so -t is not needed if you want to continue using it. " \
|
"so -t is not needed if you want to continue using it. " \
|
||||||
"This setting can be changed anytime with `bundle config gem.test`."
|
"This setting can be changed anytime with `bundle config gem.test`."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if options[:ci] == Bundler.settings["gem.ci"]
|
||||||
|
Bundler.ui.info "Bundler is configured to generate CI files for #{Bundler.settings["gem.ci"]}, "\
|
||||||
|
"so --ci is not needed if you want to continue using it. " \
|
||||||
|
"This setting can be changed anytime with `bundle config gem.ci`."
|
||||||
|
end
|
||||||
rescue Errno::EEXIST => e
|
rescue Errno::EEXIST => e
|
||||||
raise GenericSystemCallError.new(e, "There was a conflict while creating the new gem.")
|
raise GenericSystemCallError.new(e, "There was a conflict while creating the new gem.")
|
||||||
end
|
end
|
||||||
|
@ -231,8 +237,9 @@ module Bundler
|
||||||
|
|
||||||
if test_framework.to_s.empty?
|
if test_framework.to_s.empty?
|
||||||
Bundler.ui.confirm "Do you want to generate tests with your gem?"
|
Bundler.ui.confirm "Do you want to generate tests with your gem?"
|
||||||
Bundler.ui.info test_framework_hint
|
Bundler.ui.info hint_text("test")
|
||||||
result = Bundler.ui.ask "Type 'rspec', 'minitest' or 'test-unit' to generate those test files now. " \
|
|
||||||
|
result = Bundler.ui.ask "Enter a framework name to generate those test files now. " \
|
||||||
"rspec/minitest/test-unit/(none):"
|
"rspec/minitest/test-unit/(none):"
|
||||||
if result =~ /rspec|minitest|test-unit/
|
if result =~ /rspec|minitest|test-unit/
|
||||||
test_framework = result
|
test_framework = result
|
||||||
|
@ -248,30 +255,31 @@ module Bundler
|
||||||
test_framework
|
test_framework
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_framework_hint
|
def hint_text(setting)
|
||||||
if Bundler.settings["gem.test"] == false
|
if Bundler.settings["gem.#{setting}"] == false
|
||||||
"Your choice will only be applied to this gem."
|
"Your choice will only be applied to this gem."
|
||||||
else
|
else
|
||||||
"Future `bundle gem` calls will use your choice. " \
|
"Future `bundle gem` calls will use your choice. " \
|
||||||
"This setting can be changed anytime with `bundle config gem.test`."
|
"This setting can be changed anytime with `bundle config gem.#{setting}`."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ask_and_set_ci
|
def ask_and_set_ci
|
||||||
ci_template = options[:ci] || Bundler.settings["gem.ci"]
|
ci_template = options[:ci] || Bundler.settings["gem.ci"]
|
||||||
|
|
||||||
if ci_template.nil?
|
if ci_template.to_s.empty?
|
||||||
Bundler.ui.confirm "Do you want to set up automated testing for your gem? " \
|
Bundler.ui.confirm "Do you want to set up automated testing for your gem? " \
|
||||||
"Continuous integration services make it easy to see if pull requests have passing tests " \
|
"Continuous integration services make it easy to see if pull requests have passing tests " \
|
||||||
"before you merge them. Bundler supports these services:" \
|
"before you merge them. Bundler supports these services:\n" \
|
||||||
"* CircleCI: https://circleci.com/\n" \
|
"* CircleCI: https://circleci.com/\n" \
|
||||||
"* GitHub Actions: https://github.com/features/actions\n" \
|
"* GitHub Actions: https://github.com/features/actions\n" \
|
||||||
"* GitLab CI: https://docs.gitlab.com/ee/ci/\n" \
|
"* GitLab CI: https://docs.gitlab.com/ee/ci/\n" \
|
||||||
"* Travis CI: https://travis-ci.org/\n" \
|
"* Travis CI: https://travis-ci.org/\n" \
|
||||||
"\n"
|
"\n"
|
||||||
|
Bundler.ui.info hint_text("ci")
|
||||||
|
|
||||||
result = Bundler.ui.ask "Enter a service name to generate a CI configuration now and " \
|
result = Bundler.ui.ask "Enter a service name to generate a CI configuration now. " \
|
||||||
"in the future. github/travis/gitlab/circle/(none):"
|
"github/travis/gitlab/circle/(none):"
|
||||||
if result =~ /github|travis|gitlab|circle/
|
if result =~ /github|travis|gitlab|circle/
|
||||||
ci_template = result
|
ci_template = result
|
||||||
else
|
else
|
||||||
|
|
|
@ -739,6 +739,55 @@ RSpec.describe "bundle gem" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "gem.ci set to github and --ci with no arguments", :hint_text do
|
||||||
|
before do
|
||||||
|
bundle "config set gem.ci github"
|
||||||
|
bundle! "gem #{gem_name} --ci"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "generates a GitHub Actions config file" do
|
||||||
|
expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to exist
|
||||||
|
end
|
||||||
|
|
||||||
|
it "hints that --ci is not needed" do
|
||||||
|
hint = "Bundler is configured to generate CI files for github, "\
|
||||||
|
"so --ci is not needed if you want to continue using it. " \
|
||||||
|
"This setting can be changed anytime with `bundle config gem.ci`."
|
||||||
|
expect(out).to match(hint)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "gem.ci setting set to false and --ci with no arguments", :hint_text do
|
||||||
|
before do
|
||||||
|
bundle "config set gem.ci false"
|
||||||
|
bundle! "gem #{gem_name} --ci"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "asks to setup CI" do
|
||||||
|
expect(out).to match("Do you want to set up automated testing for your gem?")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "hints that the choice will only be applied to the current gem" do
|
||||||
|
expect(out).to match("Your choice will only be applied to this gem.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "gem.ci setting not set and --ci with no arguments", :hint_text do
|
||||||
|
before do
|
||||||
|
bundle! "gem #{gem_name} --ci"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "asks to setup CI" do
|
||||||
|
expect(out).to match("Do you want to set up automated testing for your gem?")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "hints that the choice will be applied to future bundle gem calls" do
|
||||||
|
hint = "Future `bundle gem` calls will use your choice. " \
|
||||||
|
"This setting can be changed anytime with `bundle config gem.ci`."
|
||||||
|
expect(out).to match(hint)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "--edit option" do
|
context "--edit option" do
|
||||||
it "opens the generated gemspec in the user's text editor" do
|
it "opens the generated gemspec in the user's text editor" do
|
||||||
output = bundle "gem #{gem_name} --edit=echo"
|
output = bundle "gem #{gem_name} --edit=echo"
|
||||||
|
|
Загрузка…
Ссылка в новой задаче