Skip to content

Commit

Permalink
Merge pull request #28 from kigster/kig/puma-rubocop-update
Browse files Browse the repository at this point in the history
Fixes #27: upgrade gems, add more rubocop plugins
  • Loading branch information
kigster authored Jun 30, 2024
2 parents ccc6084 + 03a607c commit fe58304
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 105 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
34 changes: 19 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Ruby

on: [push,pull_request]
on: [pull_request, workflow_dispatch]

jobs:
build:
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,25 @@ 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

- uses: codecov/codecov-action@v3
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)

run: bundle exec rubocop --parallel

- name: Upload to Codecov
run: |
if [[ $(ruby -e 'puts RUBY_VERSION') == '3.3.1' ]]; then
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov
fi
# - uses: codecov/codecov-action@v4
# with:
# fail_ci_if_error: false # optional (default = false)
# 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

36 changes: 33 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
comment:
layout: "reach,diff,flags,tree,betaprofiling"
show_critical_paths: true
codecov:
ci:
- "github.com"
max_report_age: 24
disable_default_path_fixes: no
require_ci_to_pass: yes
notify:
after_n_builds: 1
wait_for_ci: yes

github_checks:
annotations: true

coverage:
range: 50..75
round: down
precision: 2
status:
patch: false
project:
puma-daemon: # This can be anything, but it needs to exist as the name
# basic settings
target: 80%
threshold: 5%
base: auto
if_ci_failed: ignore #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

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')

begin
super(str)
super
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'
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 fe58304

Please sign in to comment.