Skip to content

Commit

Permalink
Fixes #27: upgrade gems, add more rubocop plugins
Browse files Browse the repository at this point in the history
 * Bump up Ruby versions
 * Deprecate Ruby 2.5
 * Fix Rubocop errors
  • Loading branch information
kigster committed Jun 30, 2024
1 parent ccc6084 commit 6316a0b
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
alias be='bundle exec'
alias bep='bundle exec puma -C config/puma.rb --debug -v --redirect-stderr puma.stderr --redirect-stdout puma.stdout spec/rackup/bind.ru'


[[ -f .envrc.local ]] && source .envrc.local
13 changes: 5 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [3.2.0, 3.1.3, 3.0.5, 2.7.2, 2.6.6, 2.5.7]
ruby-version: [3.3.1, 3.2.4, 3.1.5, 3.0.7, 2.7.8, 2.6.10]

env:
RUBY_VERSION: ${{ matrix.ruby-version }}
Expand All @@ -27,14 +27,11 @@ jobs:
- name: Rubocop
run: bundle exec rubocop

- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
directory: coverage
env_vars: RUBY_VERSION
fail_ci_if_error: true # optional (default = false)
files: codecov-result.json
flags: unittests # optional
token: ${{ secrets.CODECOV_TOKEN }} # required
name: codecov-umbrella # optional
fail_ci_if_error: false # optional (default = false)
verbose: true # optional (default = false)

verbose: true # optional (default = false)`
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
/tmp/pids/*
/Gemfile
**/.DS_Store
.envrc.local
15 changes: 14 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

inherit_gem:
relaxed-rubocop: .rubocop.yml

AllCops:
TargetRubyVersion: 2.4
NewCops: enable
SuggestExtensions: true
TargetRubyVersion: 2.6

Style/OptionalBooleanParameter:
Exclude:
Expand All @@ -24,5 +30,12 @@ Naming/FileName:
Exclude:
- 'lib/puma-daemon.rb'

Rake/Desc:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Max: 20


# Gemspec/DevelopmentDependencies:
# Enabled: false
15 changes: 14 additions & 1 deletion Gemfile.puma-v5
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ gem 'puma', '~> 5.0'
gem 'rack', '~> 2'
gem 'rake', '~> 13.0'

group :development, :test do
gem 'asciidoctor'
gem 'yard'
end

group :test do
gem 'codecov', require: false
gem 'httparty'
gem 'relaxed-rubocop'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 0.80'
gem 'rspec-its'
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'simplecov'
gem 'simplecov-cobertura', require: false
end
15 changes: 14 additions & 1 deletion Gemfile.puma-v6
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ gem 'puma', '~> 6.0'
gem 'rack', '~> 2'
gem 'rake', '~> 13.0'

group :development, :test do
gem 'asciidoctor'
gem 'yard'
end

group :test do
gem 'codecov', require: false
gem 'httparty'
gem 'relaxed-rubocop'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 0.80'
gem 'rspec-its'
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'simplecov'
gem 'simplecov-cobertura', require: false
end
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# vim: tabstop=8
# vim: shiftwidth=8
# vim: ts=8
# vim: sw=8
# vim: noexpandtab

# grep '^[a-z\-]*:' Makefile | cut -d: -f 1 | tr '\n' ' '
.PHONY: help docker-build docker-bash
.PHONY: help docker-build docker-bash puma-v5 puma-v6 test test-all rubocop generate-pdf

RUBY_VERSION := $(cat .ruby-version)
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
Expand All @@ -14,7 +14,7 @@ CURRENT_DIR := $(notdir $(patsubst %/,%,$(dir $(MAKEFILE_PATH))))
PUMAD_HOME := $(shell dirname $(MAKEFILE_PATH))

help: ## Prints help message auto-generated from the comments.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

puma-v5: ## Installs puma 5.0.0
@ln -nfs Gemfile.puma-v5 Gemfile
Expand All @@ -37,7 +37,7 @@ rubocop: ## Run rubocop
@bundle check || bundle install
@bundle exec rubocop --format=progress


docker-build-ruby: ## Builds the Docker image by compiling ruby 3.0.0
@docker build -f Dockerfile.build -t puma-daemon:latest .

Expand All @@ -55,5 +55,5 @@ generate-pdf: ## Regenerates README,pdf from README.adoc
@bash -c "source ~/.bashmatic/init.sh && ~/.bashmatic/bin/adoc2pdf README.adoc"

clean: ## Clean-up
@rm -rf Gemfile Gemfile.lock coverage
@rm -rf Gemfile Gemfile.lock coverage

7 changes: 4 additions & 3 deletions lib/puma/daemon/runner_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module Puma
module Daemon
# noinspection RubySuperCallWithoutSuperclassInspection
module RunnerAdapter
class << self
def included(base)
Expand All @@ -14,7 +15,7 @@ def included(base)

base.class_eval do
def output_header(mode)
super(mode)
super

Check warning on line 18 in lib/puma/daemon/runner_adapter.rb

View check run for this annotation

Codecov / codecov/patch

lib/puma/daemon/runner_adapter.rb#L18

Added line #L18 was not covered by tests

daemonize! if daemon?
end
Expand All @@ -35,10 +36,10 @@ def daemonize!
end

def log(str)
return if str =~ /Ctrl-C/
return if str.include?('Ctrl-C')

Check warning on line 39 in lib/puma/daemon/runner_adapter.rb

View check run for this annotation

Codecov / codecov/patch

lib/puma/daemon/runner_adapter.rb#L39

Added line #L39 was not covered by tests

begin
super(str)
super

Check warning on line 42 in lib/puma/daemon/runner_adapter.rb

View check run for this annotation

Codecov / codecov/patch

lib/puma/daemon/runner_adapter.rb#L42

Added line #L42 was not covered by tests
rescue StandardError
puts(str)
end
Expand Down
15 changes: 3 additions & 12 deletions puma-daemon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Gem::Specification.new do |spec|
spec.summary = "Restore somewhat Puma's ability to self-daemonize, since Puma 5.0 dropped it"
spec.description = <<~DESCRIPTION
In version 5.0 the authors of the popular Ruby web server Puma chose to remove the
In version 5.0 the authors of the popular Ruby web server Puma chose to remove the#{' '}
daemonization support from Puma, because the code wasn't wall maintained,
and because other and better options exist for production deployments. For example
systemd, Docker/Kubernetes, Heroku, etc.
systemd, Docker/Kubernetes, Heroku, etc.#{' '}
Having said that, it was neat and often useful to daemonize Puma in development.
This gem adds this support to Puma 5 & 6 (hopefully) without breaking anything in Puma
Expand All @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/kigster/puma-daemon'
spec.license = 'MIT'

spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
spec.required_ruby_version = Gem::Requirement.new('>= 2.6')

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/kigster/puma-daemon'
Expand All @@ -46,15 +46,6 @@ Gem::Specification.new do |spec|
spec.add_dependency 'puma', '>= 5.0'
spec.add_dependency 'rack'

spec.add_development_dependency 'asciidoctor'
spec.add_development_dependency 'codecov'
spec.add_development_dependency 'httparty'
spec.add_development_dependency 'relaxed-rubocop'
spec.add_development_dependency 'rspec-its'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'yard'

# For more information and examples about making a new gem, checkout our
# guide at: https://bundler.io/guides/creating_gem.html
spec.metadata['rubygems_mfa_required'] = 'true'
Expand Down
49 changes: 34 additions & 15 deletions spec/puma/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,58 @@ module Puma
end
end

it(:puma_default_options) { should_not be_nil }
it(:puma_default_options) { is_expected.not_to be_nil }

context 'default_dsl' do
describe '#default_dsl' do
subject { config.default_dsl.options }
its([:daemon]) { should be true }
end

context 'user_dsl' do
subject { config.user_dsl.options }
its([:daemon]) { should be true }
its([:binds]) { should eq ['tcp://0.0.0.0:3001'] }
its([:daemon]) { is_expected.to be true }
end

describe 'config: daemonize(false)' do
let(:daemonize) { false }
context 'user_dsl' do
describe '#user_dsl' do
describe 'when using default options' do
subject { config.user_dsl.options }
its([:daemon]) { should be false }

its([:daemon]) { is_expected.to be true }
its([:binds]) { is_expected.to eq ['tcp://0.0.0.0:3001'] }
end

describe 'when daemonize is false)' do
subject { config.user_dsl.options }

let(:daemonize) { false }

its([:daemon]) { is_expected.to be false }
end
end

context 'file_dsl' do
describe 'file_dsl' do
subject { config.options }

let(:config) do
::Puma::Configuration.new do |c|
c.rackup 'spec/rackup/bind.ru'
c.port 3000
end.tap(&:load)
end

its([:binds]) { is_expected.to eq ['tcp://0.0.0.0:3000'] }
its([:daemon]) { is_expected.to be true }
end

describe 'pidfile' do
subject { config.options }

its([:binds]) { should eq ['tcp://0.0.0.0:3000'] }
its([:daemon]) { should be true }
let(:pidfile) { Tempfile.new('pidfile') }
let(:config) do
::Puma::Configuration.new do |c|
c.pidfile(pidfile)
c.port 3000
end.tap(&:load)
end

its([:binds]) { is_expected.to eq ['tcp://0.0.0.0:3000'] }
its([:daemon]) { is_expected.to be true }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/puma/daemon/runner_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Daemon

before {
adapter.has_demonized = false
expect(::Process).to receive(:daemon)
allow(::Process).to receive(:daemon)
}

its(:daemonize!) { is_expected.to be_truthy }
Expand Down
34 changes: 17 additions & 17 deletions spec/puma/daemon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

module Puma
RSpec.describe Daemon do
it 'has a version number' do
expect(Daemon::VERSION).not_to be nil
end

let(:environment) { 'production' }
let(:wait_booted) { -> { wait.sysread 1 } }
let(:cli) { ::Puma::Daemon::CLI.new(argv).cli }
let(:argv) { [] }
let(:wait_booted) { -> { wait.sysread 1 } }
let(:environment) { 'production' }

include TmpPath
after do
@wait&.close
@ready&.close
end

before do
@environment = 'production'
Expand All @@ -22,33 +22,32 @@ module Puma
@tmp_path1 = tmp_path('puma-test-1')
@tmp_path2 = tmp_path('puma-test-2')

File.unlink @tmp_path1 if File.exist? @tmp_path1
File.unlink @tmp_path2 if File.exist? @tmp_path2
FileUtils.rm_f @tmp_path1
FileUtils.rm_f @tmp_path2

@wait, @ready = IO.pipe
end

after do
@wait&.close
@ready&.close
it 'has a version number' do
expect(Daemon::VERSION).not_to be_nil
end

let(:cli) { ::Puma::Daemon::CLI.new(argv).cli }
include TmpPath

context 'runners' do
describe 'when starting Runners' do
describe 'single-process daemon' do
let(:argv) { [] }

describe Single do
subject(:single) { ::Puma::Const::VERSION =~ /^5/ ? described_class.new(cli.launcher, cli.instance_variable_get(:@events)) : described_class.new(cli.launcher) }
subject(:single) { ::Puma::Const::VERSION.match?(/^5/) ? described_class.new(cli.launcher, cli.instance_variable_get(:@events)) : described_class.new(cli.launcher) }
# This is not a real test
it { is_expected.to respond_to :daemonize! }
end
end

describe 'multi-process cluster daemon' do
describe 'when using multi-process cluster daemon' do
describe Cluster do
subject(:single) { ::Puma::Const::VERSION =~ /^5/ ? described_class.new(cli.launcher, cli.instance_variable_get(:@events)) : described_class.new(cli.launcher) }
subject(:single) { ::Puma::Const::VERSION.match?(/^5/) ? described_class.new(cli.launcher, cli.instance_variable_get(:@events)) : described_class.new(cli.launcher) }
let(:url) { "unix://#{@tmp_path1}" }
let(:argv) do
['-b', "unix://#{@tmp_path2}",
Expand All @@ -58,6 +57,7 @@ module Puma
'--control-token', '',
'spec/rackup/lobster.ru']
end

# This is not a real test
it { is_expected.to respond_to :daemonize! }
end
Expand Down
Loading

0 comments on commit 6316a0b

Please sign in to comment.