Skip to content

Commit

Permalink
Cleanup to prepare the gem for Ruby 2.7 as minimum version.
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann Mayer <hermann.mayer92@gmail.com>
  • Loading branch information
Jack12816 committed Jan 16, 2023
1 parent 7d4fdab commit 27ce706
Show file tree
Hide file tree
Showing 20 changed files with 210 additions and 125 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ concurrency:
jobs:
docs:
name: Build gem documentation
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
Expand All @@ -19,7 +19,7 @@ jobs:
with:
ruby-version: 2.5
bundler-cache: true
rubygems: latest
rubygems: '3.3.26'

- name: Prepare the virtual environment
uses: hausgold/actions/ci@master
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ concurrency:
jobs:
test:
name: 'Test the gem (Ruby ${{ matrix.ruby }})'
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
ruby: [2.3, 2.4, 2.5, 2.6]
ruby: ['2.5', '2.7']
steps:
- uses: actions/checkout@v3

Expand All @@ -27,7 +27,7 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
rubygems: latest
rubygems: '3.3.26'

- name: Prepare the virtual environment
uses: hausgold/actions/ci@master
Expand All @@ -44,7 +44,7 @@ jobs:

trigger-docs:
name: Trigger the documentation upload
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
timeout-minutes: 2
needs: test
if: github.ref == 'refs/heads/master'
Expand Down
3 changes: 2 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--backtrace
--force-color
--format documentation
--color
21 changes: 19 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
require: rubocop-rspec
require:
- rubocop-rspec
- rubocop-rails

Rails:
Enabled: true

Documentation:
Style/Documentation:
Enabled: true

AllCops:
NewCops: enable
SuggestExtensions: false
DisplayCopNames: true
TargetRubyVersion: 2.5
TargetRailsVersion: 5.2
Exclude:
- bin/**/*
- vendor/**/*
Expand All @@ -23,6 +28,10 @@ Metrics/BlockLength:
- '**/*.rake'
- doc/**/*.rb

# MFA is not yet enabled for our gems yet.
Gemspec/RequireMFA:
Enabled: false

# Document all the things.
Style/DocumentationMethod:
Enabled: true
Expand Down Expand Up @@ -51,3 +60,11 @@ RSpec/FilePath:
# Because we just implemented the ActiveRecord API.
Rails/SkipsModelValidations:
Enabled: false

# We stay with the original Ruby Style Guide recommendation.
Layout/LineLength:
Max: 80

# We highly depend on memoized helpers across the specs.
RSpec/MultipleMemoizedHelpers:
Enabled: false
12 changes: 12 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# frozen_string_literal: true

require 'simplecov-html'
require 'simplecov_json_formatter'

SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
[
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter
]
)

SimpleCov.start 'test_frameworks' do
add_filter '/vendor/bundle/'
end
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### next

* Bundler >= 2.3 is from now on required as minimal version (#18)
* Dropped support for Ruby < 2.5 (#18)
* Dropped support for Rails < 5.2 (#18)
* Updated all development/runtime gems to their latest
Ruby 2.5 compatible version (#18)

### 0.4.1

* Added `InvoiceComment` models (#17)
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM hausgold/ruby:2.5
MAINTAINER Hermann Mayer <hermann.mayer@hausgold.de>

# Update system gem
RUN gem update --system
RUN gem update --system '3.3.26'

# Install system packages and the latest bundler
RUN apt-get update -yqqq && \
Expand All @@ -11,8 +11,7 @@ RUN apt-get update -yqqq && \
ca-certificates \
bash-completion inotify-tools && \
echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && /usr/sbin/locale-gen && \
gem install bundler -v '~> 2.0' --no-document --no-prerelease && \
gem install bundler -v '~> 1.0' --no-document --no-prerelease
gem install bundler -v '~> 2.3.0' --no-document --no-prerelease

# Add new web user
RUN mkdir /app && \
Expand Down
3 changes: 0 additions & 3 deletions Envfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_ALL=en_US.UTF-8

# Just fix this, so Appraisals with Rails 4 are working fine
BUNDLER_VERSION=1.17.3
44 changes: 44 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
(directories %w[lib spec]).select do |d|
if Dir.exist?(d)
d
else
UI.warning("Directory #{d} does not exist")
end
end

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

# NOTE: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: 'bundle exec rspec' do
watch('spec/spec_helper.rb') { 'spec' }
watch(%r{^lib/billomat.rb}) { 'spec' }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/billomat/([^\\]+)\.rb$}) do |m|
"spec/#{m[1]}_spec.rb"
end
watch(%r{^lib/billomat/([^\\]+)/(.*)\.rb$}) do |m|
"spec/#{m[1]}/#{m[2]}_spec.rb"
end
end
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 HAUSGOLD | talocasa GmbH
Copyright (c) 2023 HAUSGOLD | talocasa GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
28 changes: 21 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SHELL := bash
# Environment switches
MAKE_ENV ?= docker
COMPOSE_RUN_SHELL_FLAGS ?= --rm
BASH_RUN_SHELL_FLAGS ?=

# Directories
VENDOR_DIR ?= vendor/bundle
Expand All @@ -27,7 +28,9 @@ XARGS ?= xargs
# Container binaries
BUNDLE ?= bundle
GEM ?= gem
GUARD ?= guard
RAKE ?= rake
RSPEC ?= rspec
RUBOCOP ?= rubocop
YARD ?= yard

Expand All @@ -38,7 +41,8 @@ define run-shell
$(COMPOSE) run $(COMPOSE_RUN_SHELL_FLAGS) \
-e LANG=en_US.UTF-8 -e LANGUAGE=en_US.UTF-8 -e LC_ALL=en_US.UTF-8 \
-e HOME=/home/web -e BUNDLE_APP_CONFIG=/app/.bundle \
-u `$(ID) -u` test bash -c 'sleep 0.1; echo; $(1)'
-u `$(ID) -u` test \
bash $(BASH_RUN_SHELL_FLAGS) -c 'sleep 0.1; echo; $(1)'
endef
else ifeq ($(MAKE_ENV),baremetal)
define run-shell
Expand All @@ -50,11 +54,11 @@ all:
# Billomat
#
# install Install the dependencies
# update Update the local Gemset dependencies
# clean Clean the dependencies
#
# test Run the whole test suite
# test-style Test the code styles
# watch Watch for code changes and rerun the test suite
#
# docs Generate the Ruby documentation of the library
# stats Print the code statistics (library and test suite)
Expand All @@ -64,12 +68,22 @@ all:
# shell Run an interactive shell on the container
# shell-irb Run an interactive IRB shell on the container

.interactive:
@$(eval BASH_RUN_SHELL_FLAGS = --login)

install:
# Install the dependencies
@$(MKDIR) -p $(VENDOR_DIR)
@$(call run-shell,$(BUNDLE) check || $(BUNDLE) install --path $(VENDOR_DIR))
@$(call run-shell,GEM_HOME=vendor/bundle/ruby/$${RUBY_MAJOR}.0 \
$(GEM) install bundler -v "~> 1.0")

update:
# Install the dependencies
@$(MKDIR) -p $(VENDOR_DIR)
@$(call run-shell,$(BUNDLE) update)

watch: install .interactive
# Watch for code changes and rerun the test suite
@$(call run-shell,$(BUNDLE) exec $(GUARD))

test: \
test-specs \
Expand All @@ -90,8 +104,8 @@ clean:
# Clean the dependencies
@$(RM) -rf $(VENDOR_DIR)
@$(RM) -rf $(VENDOR_DIR)/Gemfile.lock
@$(RM) -rf pkg
@$(RM) -rf coverage
@$(RM) -rf .bundle .yardoc coverage pkg Gemfile.lock doc/api \
.rspec_status

clean-containers:
# Clean running containers
Expand All @@ -102,7 +116,7 @@ endif
clean-images:
# Clean build images
ifeq ($(MAKE_ENV),docker)
@-$(DOCKER) images | $(GREP) rimless \
@-$(DOCKER) images | $(GREP) $(shell basename "`pwd`") \
| $(AWK) '{ print $$3 }' \
| $(XARGS) -rn1 $(DOCKER) rmi -f
endif
Expand Down
78 changes: 12 additions & 66 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,22 @@

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rails/code_statistics'
require 'pp'
require 'countless/rake_tasks'

RSpec::Core::RakeTask.new(:spec)

task default: :spec

# Load some railties tasks
load 'rails/tasks/statistics.rake'
load 'rails/tasks/annotations.rake'

# Clear the default statistics directory constant
#
# rubocop:disable Style/MutableConstant because we define it
Object.send(:remove_const, :STATS_DIRECTORIES)
::STATS_DIRECTORIES = []
# rubocop:enable Style/MutableConstant

# Monkey patch the Rails +CodeStatistics+ class to support configurable
# patterns per path. This is reuqired to support top-level only file matches.
class CodeStatistics
DEFAULT_PATTERN = /^(?!\.).*?\.(rb|js|coffee|rake)$/.freeze

# Pass the possible +pattern+ argument down to the
# +calculate_directory_statistics+ method call.
def calculate_statistics
Hash[@pairs.map do |pair|
[pair.first, calculate_directory_statistics(*pair[1..-1])]
end]
end

# Match the pattern against the individual file name and the relative file
# path. This allows top-level only matches.
def calculate_directory_statistics(directory, pattern = DEFAULT_PATTERN)
stats = CodeStatisticsCalculator.new

Dir.foreach(directory) do |file_name|
path = "#{directory}/#{file_name}"

if File.directory?(path) && (/^\./ !~ file_name)
stats.add(calculate_directory_statistics(path, pattern))
elsif file_name =~ pattern || path =~ pattern
stats.add_by_file_path(path)
end
end

stats
end
end

# Configure all code statistics directories
vendors = [
[:unshift, 'Top-levels', 'lib', %r{lib(/billomat)?/[^/]+\.rb$}],
[:unshift, 'Top-levels specs', 'spec', %r{spec/[^/]+_spec\.rb$}],

[:unshift, 'Actions', 'lib/billomat/actions'],

[:unshift, 'Models matchers', 'lib/billomat/models'],
[:unshift, 'Models matchers specs', 'spec/models']
].reverse

vendors.each do |method, type, dir, pattern|
::STATS_DIRECTORIES.send(method, [type, dir, pattern].compact)
::CodeStatistics::TEST_TYPES << type if type.include? 'specs'
end

# Setup annotations
ENV['SOURCE_ANNOTATION_DIRECTORIES'] = 'spec,doc'

desc 'Enumerate all annotations'
task :notes do
SourceAnnotationExtractor.enumerate '@?OPTIMIZE|@?FIXME|@?TODO', tag: true
Countless.configure do |config|
config.stats_base_directories = [
{ name: 'Top-levels', dir: 'lib',
pattern: %r{/lib(/billomat)?/[^/]+\.rb$} },
{ name: 'Top-levels specs', test: true, dir: 'spec',
pattern: %r{/spec(/billomat)?/[^/]+_spec\.rb$} },
{ name: 'Actions', pattern: 'lib/billomat/actions/**/*.rb' },
{ name: 'Models matchers', pattern: 'lib/billomat/models/**/*.rb' },
{ name: 'Models matchers specs', test: true,
pattern: 'spec/models/**/*_spec.rb' }
]
end
Loading

0 comments on commit 27ce706

Please sign in to comment.