Skip to content
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

Add support for Ruby 3.0.0 #46

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@ language: ruby
services:
- docker
rvm:
- 2.2.10
- 2.3.8
- 2.4.6
- 2.5.5
- 2.6.3
- 2.4.10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Ruby core community dropped support for versions below 2.6, I'm thinking we should drop any versions below 2.6, as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to continue to support these versions as long as it is not inconvenient. On the off chance that someone needs a feature from this version, but they find it difficult to upgrade their Ruby version, I want to be accommodating to their needs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debian oldstable, still in lts, is ruby 2.3.3.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wowwwwwwwww

- 2.5.8
- 2.6.6
- 2.7.2
- 3.0.0
gemfile:
- gemfiles/activesupport_5.gemfile
- gemfiles/activesupport_6.gemfile
matrix:
exclude:
- rvm: 2.2.3
gemfile: gemfiles/activesupport_6.gemfile
- rvm: 2.2.10
gemfile: gemfiles/activesupport_6.gemfile
- rvm: 2.3.8
gemfile: gemfiles/activesupport_6.gemfile
- rvm: 2.4.6
- rvm: 2.4.10
gemfile: gemfiles/activesupport_6.gemfile

before_install: gem install bundler -v 1.15.4
before_install: gem install bundler -v 2.2.16

script:
- bundle exec rake spec_all
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile-runbook
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:2.5
FROM ruby:3.0
RUN apt-get update -qq && apt-get install -y build-essential tmux

RUN mkdir /runbook
Expand Down
1 change: 1 addition & 0 deletions lib/runbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "active_support/deprecation"
require "active_support/inflector"
require "method_source"
require "ruby2_keywords"
require "pastel"
require "sshkit"
require "sshkit/sudo"
Expand Down
2 changes: 1 addition & 1 deletion lib/runbook/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def items
@items ||= []
end

def method_missing(method, *args, &block)
ruby2_keywords def method_missing(method, *args, &block)
if dsl.respond_to?(method)
dsl.send(method, *args, &block)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/runbook/extensions/statements.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Runbook::Extensions
module Statements
module DSL
def method_missing(name, *args, &block)
ruby2_keywords def method_missing(name, *args, &block)
if (klass = Statements::DSL._statement_class(name))
klass.new(*args, &block).tap do |statement|
parent.add(statement)
Expand Down
37 changes: 28 additions & 9 deletions lib/runbook/generators/project/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ def self.long_description
desc: "Target directory for shared runbook code"
class_option :test, type: :string, enum: ["rspec", "minitest"],
default: "rspec", desc: %Q{Test-suite, "rspec" or "minitest"}
class_option :ci, type: :string, enum: ["github", "travis", "gitlab", "circle"],
default: "github", desc: %Q{CI Service, "github", "travis", "gitlab", or "circle"}

def init_gem
bundle_exists = "which bundle 2>&1 1>/dev/null"
raise "Please ensure bundle is installed" unless system(bundle_exists)
bundler_version = Gem::Version.new(Bundler::VERSION)

inside(parent_options[:root]) do
test = "--test #{options[:test]}"
ci = "--ci #{options[:ci]}"
changelog = "--no-changelog" if bundler_version >= Gem::Version.new("2.2.8")
continue = (
run("bundle gem #{_name} #{test} --no-coc --no-mit") ||
run("bundle gem #{_name} #{test} #{ci} --rubocop #{changelog} --no-coc --no-mit") ||
options[:pretend]
)
exit 1 unless continue
Expand All @@ -53,6 +58,9 @@ def remove_unneeded_files
remove_file(readme)

gemfile = File.join(*dirs, "Gemfile")
if File.exist?(gemfile)
@gemfile_file_contents = File.readlines(gemfile)
end
remove_file(gemfile)

base_file = File.join(*dirs, "lib", "#{_name}.rb")
Expand Down Expand Up @@ -102,14 +110,25 @@ def create_gemfile
template("templates/Gemfile.tt", target)

# Add development dependencies from gemspec
return unless @gemspec_file_contents
gems = @gemspec_file_contents.select do |line|
line =~ / spec.add_development_dependency/
end.map do |line|
line.gsub(/ spec.add_development_dependency/, "gem")
end.join

append_to_file(target, "\n#{gems}", verbose: false)
if @gemspec_file_contents
gems = @gemspec_file_contents.select do |line|
line =~ / spec.add_development_dependency/
end.map do |line|
line.gsub(/ spec.add_development_dependency/, "gem")
end.join

append_to_file(target, "\n#{gems}", verbose: false)
end

# Add gemfile gems
if @gemfile_file_contents
gems = @gemfile_file_contents.select do |line|
line =~ /^gem /
end.join

append_to_file(target, "\n#{gems}", verbose: false)
end

end

def create_base_file
Expand Down
3 changes: 2 additions & 1 deletion runbook.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency "activesupport", ">= 5.0.1.x", "< 7.0"
spec.add_runtime_dependency "method_source", "~> 1.0"
spec.add_runtime_dependency "ruby2_keywords", "~> 0.0.4"
spec.add_runtime_dependency "sshkit", "1.21.0"
spec.add_runtime_dependency "sshkit-sudo", "~> 0.1"
spec.add_runtime_dependency "airbrussh", "~> 1.4"
Expand All @@ -42,7 +43,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "appraisal", "~> 2.2"
spec.add_development_dependency "aruba", "~> 0.14"
spec.add_development_dependency "bundler", "~> 1.15"
spec.add_development_dependency "bundler", "~> 2.2"
spec.add_development_dependency "bcrypt_pbkdf", ">= 1.0", "< 2.0"
spec.add_development_dependency "ed25519", ">= 1.2", "< 2.0"
spec.add_development_dependency "pry", "~> 0.13"
Expand Down
33 changes: 25 additions & 8 deletions spec/cli/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,18 @@
let(:root_opt) { "--root #{root}" }
let(:test) { "rspec" }
let(:test_opt) { "--test #{test}" }
let(:ci) { "github" }
let(:ci_opt) { "--ci #{ci}" }
let(:shared_lib_dir) { "lib/my_runbooks" }
let(:shared_lib_dir_opt) { "--shared-lib-dir #{shared_lib_dir}" }
let(:command) { "runbook generate project #{name} #{test_opt} #{shared_lib_dir_opt} #{root_opt}" }
let(:opts) { [test_opt, ci_opt, shared_lib_dir_opt, root_opt].join(" ") }
let(:command) { "runbook generate project #{opts} #{name} " }

it "generates a project" do
last_cmd = last_command_started
bundle_gem_output = %Q{run bundle gem #{name} --test #{test} --no-coc --no-mit from "."}
bundler_version = Gem::Version.new(Bundler::VERSION)
changelog = "--no-changelog" if bundler_version >= Gem::Version.new("2.2.8")
bundle_gem_output = %Q{run bundle gem #{name} --test #{test} --ci #{ci} --rubocop #{changelog} --no-coc --no-mit from "."}
gem_successfully_created = %Q{Gem 'my_runbooks' was successfully created.}
project_generation_output = [
"remove my_runbooks/my_runbooks.gemspec",
Expand Down Expand Up @@ -412,9 +417,10 @@

gemfile = "#{root}/#{name}/Gemfile"
expect(file?(gemfile)).to be_truthy
expect(gemfile).to have_file_content(/gem "bundler"/)
expect(gemfile).to have_file_content(/gem "runbook"/)
expect(gemfile).to have_file_content(/gem "rake"/)
expect(gemfile).to have_file_content(/gem "rspec"/)
expect(gemfile).to have_file_content(/gem "rubocop"/)
end
end

Expand All @@ -424,13 +430,18 @@
let(:root_opt) { "--root #{root}" }
let(:test) { "rspec" }
let(:test_opt) { "--test #{test}" }
let(:ci) { "github" }
let(:ci_opt) { "--ci #{ci}" }
let(:shared_lib_dir) { "lib/my_runbooks" }
let(:shared_lib_dir_opt) { "--shared-lib-dir #{shared_lib_dir}" }
let(:command) { "runbook generate project #{name} #{test_opt} #{shared_lib_dir_opt} #{root_opt} -p" }
let(:opts) { [test_opt, ci_opt, shared_lib_dir_opt, root_opt].join(" ") }
let(:command) { "runbook generate project #{opts} #{name} -p" }

it "does not generate a project" do
last_cmd = last_command_started
bundle_gem_output = %Q{run bundle gem #{name} --test #{test} --no-coc --no-mit from "."}
bundler_version = Gem::Version.new(Bundler::VERSION)
changelog = "--no-changelog" if bundler_version >= Gem::Version.new("2.2.8")
bundle_gem_output = %Q{run bundle gem #{name} --test #{test} --ci #{ci} --rubocop #{changelog} --no-coc --no-mit from "."}
gem_successfully_created = %Q{Gem 'my_runbooks' was successfully created.}
project_generation_output = [
"remove my_runbooks/my_runbooks.gemspec",
Expand Down Expand Up @@ -473,13 +484,18 @@
let(:root_opt) { "--root #{root}" }
let(:test) { "rspec" }
let(:test_opt) { "--test #{test}" }
let(:ci) { "github" }
let(:ci_opt) { "--ci #{ci}" }
let(:shared_lib_dir) { "lib/my_runbooks" }
let(:shared_lib_dir_opt) { "--shared-lib-dir #{shared_lib_dir}" }
let(:command) { "runbook generate project #{name} #{test_opt} #{shared_lib_dir_opt} #{root_opt}" }
let(:opts) { [test_opt, ci_opt, shared_lib_dir_opt, root_opt].join(" ") }
let(:command) { "runbook generate project #{opts} #{name} " }

it "does not generate a project" do
last_cmd = last_command_started
bundle_gem_output = %Q{run bundle gem #{name} --test #{test} --no-coc --no-mit from "."}
bundler_version = Gem::Version.new(Bundler::VERSION)
changelog = "--no-changelog" if bundler_version >= Gem::Version.new("2.2.8")
bundle_gem_output = %Q{run bundle gem #{name} --test #{test} --ci #{ci} --rubocop #{changelog} --no-coc --no-mit from "."}
invalid_gem_name = %Q{Invalid gem name 7l Please give a name which does not start with numbers.}
project_generation_output = [
"remove my_runbooks/my_runbooks.gemspec",
Expand Down Expand Up @@ -513,9 +529,10 @@

gemfile = "#{root}/#{name}/Gemfile"
expect(file?(gemfile)).to be_falsey
expect(gemfile).to_not have_file_content(/gem "bundler"/)
expect(gemfile).to_not have_file_content(/gem "runbook"/)
expect(gemfile).to_not have_file_content(/gem "rake"/)
expect(gemfile).to_not have_file_content(/gem "rspec"/)
expect(gemfile).to_not have_file_content(/gem "rubocop"/)
expect(last_command_stopped.exit_status).to_not eq(0)
end
end
Expand Down