Skip to content

Commit

Permalink
Fixes #27: upgrade gems, add rubocop plugins
Browse files Browse the repository at this point in the history
 * Bump up Ruby versions
 * Deprecate Ruby 2.5
 * Fix Rubocop errors
 * Bump version to 0.4.0
 * Upgrade CodeCov; don't fail CI
  • Loading branch information
kigster committed Jun 30, 2024
1 parent ccc6084 commit aa4add4
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 98 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
19 changes: 8 additions & 11 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 @@ -20,21 +20,18 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bun

- name: Run Specs
run: make test-all

- name: Rubocop
run: bundle exec rubocop
run: bundle exec rubocop --parallel

- 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
files: codecov-result.json
flags: unittests # optional
name: codecov-umbrella # optional
fail_ci_if_error: false # optional (default = false)
verbose: true # optional (default = false)

files: coverage/coverage.xml
flags: rspecs # optional
token: ${{ secrets.CODECOV_TOKEN }} # required
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

16 changes: 16 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
comment:
layout: "reach,diff,flags,tree,betaprofiling"
show_critical_paths: true
coverage:
status:
project:
default: # This can be anything, but it needs to exist as the name
# basic settings
target: auto
threshold: 5%
base: auto
if_ci_failed: error #success, failure, error, ignore
only_pulls: false
flags:
- rspecs
paths:
- lib
informational: true
removed_code_behavior: off

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
2 changes: 1 addition & 1 deletion lib/puma/daemon/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Puma
module Daemon
VERSION = '0.3.2'
VERSION = '0.4.0'

Check warning on line 5 in lib/puma/daemon/version.rb

View check run for this annotation

Codecov / codecov/patch

lib/puma/daemon/version.rb#L5

Added line #L5 was not covered by tests
end
end
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
Loading

0 comments on commit aa4add4

Please sign in to comment.