summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2020-03-09 10:53:51 +0000
committerBundlerbot <bot@bundler.io>2020-03-09 10:53:51 +0000
commitcb16557d478d76c7d19d3256efc94741e15603c6 (patch)
tree87a42d0579b143dbd45a6b323e3ad6cb5880944b /lib
parent140b5de76f2e23fc44333d55efb689ad27a81828 (diff)
parent8d165d0cfbc58452e922a5ffc584f12340bbad32 (diff)
downloadbundler-staging.tar.gz
Merge #7627staging
7627: Add new option to `bundle gem` for choosing a CI sevice r=colby-swandale a=colby-swandale ### Context At the moment, every gem created with `bundle gem` will have configuration generated for Travis CI regardless of if you want to or not. When this change was introduced, Travis CI was a clear recommendation for most open source projects to use for testing their projects with. But this is no longer true, there are now lots of different CI services and Travis CI is no longer the clear recommendation it once was. ### Changes This PR introduces a new option to `bundle gem` for choosing a CI service or just not generating one at all. ``` Creating gem 'test'... Do you want to add Continuous Integration to your gem? Adding a CI service to your project helps ensure your project is well tested before shipping your gem to users. Bundler recommends several different services for testing your code. For more information about each service, see: * Travis CI: https://travis-ci.org/ * Github Actions: https://github.com/features/actions * Circle CI: https://circleci.com/ * Gitlab CI: https://docs.gitlab.com/ee/ci/ Type 'github', 'travis', 'gitlab' or 'circle' to generate those test files now and in the future. github/travis/gitlab/circle/(none): ``` I decided to add Github Actions, Gitlab, Circle CI along with Travis CI, which i think covers most services most people will typically go with. Each service will generate it's own configuration which is ready to use out the box. Co-authored-by: Colby Swandale <me@colby.fyi> Co-authored-by: Andre Arko <andre@arko.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/cli.rb1
-rw-r--r--lib/bundler/cli/gem.rb43
-rw-r--r--lib/bundler/templates/newgem/.circleci/config.yml.tt13
-rw-r--r--lib/bundler/templates/newgem/.github/workflows/main.yml.tt18
-rw-r--r--lib/bundler/templates/newgem/.gitlab-ci.yml.tt9
5 files changed, 82 insertions, 2 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 6f7ff90dc2..32da68558d 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -570,6 +570,7 @@ module Bundler
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 => "rspec", :aliases => "-t", :banner => "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`."
+ method_option :ci, :type => :string, :desc => "Generate CI configuration, either Github Actions, Travis CI, Gitlab CI or Circle CI. Set a default with `bundle config set gem.ci (github|travis|gitlab|circle)`"
def gem(name)
end
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index 3fd67d9a88..d5cfd91a86 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -84,8 +84,6 @@ module Bundler
config[:test] = test_framework
config[:test_framework_version] = TEST_FRAMEWORK_VERSIONS[test_framework]
- templates.merge!("travis.yml.tt" => ".travis.yml")
-
case test_framework
when "rspec"
templates.merge!(
@@ -109,6 +107,18 @@ module Bundler
end
end
+ config[:ci] = ask_and_set_ci
+ case config[:ci]
+ when "github"
+ templates.merge!(".github/workflows/main.yml.tt" => ".github/workflows/main.yml")
+ when "travis"
+ templates.merge!("travis.yml.tt" => ".travis.yml")
+ when "gitlab"
+ templates.merge!(".gitlab-ci.yml.tt" => ".gitlab-ci.yml")
+ when "circle"
+ templates.merge!(".circleci/config.yml.tt" => ".circleci/config.yml")
+ end
+
if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?",
"This means that any other developer or company will be legally allowed to use your code " \
"for free as long as they admit you created it. You can read more about the MIT license " \
@@ -231,6 +241,35 @@ module Bundler
test_framework
end
+ def ask_and_set_ci
+ ci_template = options[:ci] || Bundler.settings["gem.ci"]
+
+ if ci_template.nil?
+ 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 " \
+ "before you merge them. Bundler supports these services:"\
+ "* Circle CI: https://circleci.com/\n" \
+ "* Github Actions: https://github.com/features/actions\n" \
+ "* Gitlab CI: https://docs.gitlab.com/ee/ci/\n" \
+ "* Travis CI: https://travis-ci.org/\n" \
+ "\n"
+
+ result = Bundler.ui.ask "Enter a service name to generate a CI configuration now and " \
+ "in the future. github/travis/gitlab/circle/(none):"
+ if result =~ /github|travis|gitlab|circle/
+ ci_template = result
+ else
+ ci_template = false
+ end
+ end
+
+ if Bundler.settings["gem.ci"].nil?
+ Bundler.settings.set_global("gem.ci", ci_template)
+ end
+
+ ci_template
+ end
+
def bundler_dependency_version
v = Gem::Version.new(Bundler::VERSION)
req = v.segments[0..1]
diff --git a/lib/bundler/templates/newgem/.circleci/config.yml.tt b/lib/bundler/templates/newgem/.circleci/config.yml.tt
new file mode 100644
index 0000000000..660943a3df
--- /dev/null
+++ b/lib/bundler/templates/newgem/.circleci/config.yml.tt
@@ -0,0 +1,13 @@
+version: 2.1
+jobs:
+ build:
+ docker:
+ - image: ruby:<%= RUBY_VERSION %>
+ steps:
+ - checkout
+ - run:
+ name: Run tests
+ command: |
+ gem install bundler -v <%= Bundler::Version %>
+ bundle install
+ bundle exec rake test
diff --git a/lib/bundler/templates/newgem/.github/workflows/main.yml.tt b/lib/bundler/templates/newgem/.github/workflows/main.yml.tt
new file mode 100644
index 0000000000..929901ac56
--- /dev/null
+++ b/lib/bundler/templates/newgem/.github/workflows/main.yml.tt
@@ -0,0 +1,18 @@
+name: Ruby
+
+on: [push,pull_request]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Ruby <%= ::Gem::Version.new(RUBY_VERSION).segments[0..1].join(".") %>
+ uses: actions/setup-ruby@v1
+ with:
+ ruby-version: <%= ::Gem::Version.new(RUBY_VERSION).segments[0..1].join(".") %>.x
+ - name: Build and test with Rake
+ run: |
+ gem install bundler -v <%= Bundler::VERSION %>
+ bundle install --jobs 4 --retry 3
+ bundle exec rake
diff --git a/lib/bundler/templates/newgem/.gitlab-ci.yml.tt b/lib/bundler/templates/newgem/.gitlab-ci.yml.tt
new file mode 100644
index 0000000000..6acdc1d10c
--- /dev/null
+++ b/lib/bundler/templates/newgem/.gitlab-ci.yml.tt
@@ -0,0 +1,9 @@
+image: ruby:<%= RUBY_VERSION %>
+
+before_script:
+ - gem install bundler
+ - bundle install -v <%= Bundler::VERSION %>
+
+test:
+ script:
+ - bundle exec rake test