diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f158f2..6d5e0d4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,16 +1,4 @@ --- -# --------------------------------------------------------------------------------------------------------------------- -# CircleCI Snippets -# -# Reusable snippets are defined below this section. These are yaml fragments that can injected into the standard -# CircleCI configuration, reducing the complexity of the entire block. -# --------------------------------------------------------------------------------------------------------------------- -docker_image: &docker_image - image: ${CUSTOMINK_ECR_URL}/customink/base-ruby:2.7-v4.0 - aws_auth: - aws_access_key_id: ${PRODUCTION_AWS_ACCESS_KEY_ID} - aws_secret_access_key: ${PRODUCTION_AWS_SECRET_ACCESS_KEY} - # --------------------------------------------------------------------------------------------------------------------- # CircleCI Commands Configuration # @@ -20,25 +8,26 @@ docker_image: &docker_image # --------------------------------------------------------------------------------------------------------------------- version: 2.1 commands: - bundle_install: - description: "Performs the bundler installation, relying on the CircleCI cache for performance" + appraisal_install: + description: "Performs the installation with Appraisal" + parameters: + ruby-version: + type: string steps: - restore_cache: keys: - - bundler-cache-{{ checksum "is_it_up.gemspec" }} + - appraisal-cache-<< parameters.ruby-version >>-1.0-{{ checksum "is_it_up.gemspec" }} - run: - name: "Bundle Install" - command: bundle install --path=.bundle + name: "Appraisal Install" + command: | + bundle config --local path vendor/bundle + bundle install --jobs 4 --retry 3 + bundle exec appraisal install - save_cache: - key: bundler-cache-{{ checksum "is_it_up.gemspec" }} + key: appraisal-cache-<< parameters.ruby-version >>-1.0-{{ checksum "is_it_up.gemspec" }} paths: - - .bundle - minitest: - description: "Runs Minitest with the correct configuration so it runs in parallel and is configured for CircleCI" - steps: - - run: - name: "Minitest Test Suite" - command: bundle exec rake + - vendor/bundle + # --------------------------------------------------------------------------------------------------------------------- # CircleCI Job Configuration # @@ -48,22 +37,67 @@ commands: # --------------------------------------------------------------------------------------------------------------------- jobs: tests: - working_directory: ~/is_it_up + parameters: + ruby-version: + type: string + gemfile: + type: string docker: - - <<: *docker_image + - image: 916869144969.dkr.ecr.us-east-1.amazonaws.com/customink/base-ruby:<< parameters.ruby-version >>-v5.5 + user: root + aws_auth: + aws_access_key_id: ${PRODUCTION_AWS_ACCESS_KEY_ID} + aws_secret_access_key: ${PRODUCTION_AWS_SECRET_ACCESS_KEY} environment: RAILS_ENV: test + RACK_ENV: test + working_directory: "/app" steps: - checkout - - bundle_install - - minitest + - appraisal_install: + ruby-version: << parameters.ruby-version >> + - run: + name: "Tests" + command: bundle exec appraisal << parameters.gemfile >> rake test + - store_artifacts: + path: ./coverage - store_test_results: - path: test/reports + path: ./test/reports - store_artifacts: - path: coverage + path: ./test/reports + +# --------------------------------------------------------------------------------------------------------------------- +# CircleCI Workflow Execution Order +# +# Here we define the Workflow, the order of the various jobs and their dependencies. +# This allows us to decide whether to run certain tasks sequentially or run several of them in parallel. +# --------------------------------------------------------------------------------------------------------------------- workflows: version: 2.1 build-and-test: jobs: - tests: + name: "Ruby 2.6 Tests with Rails 5.0" + context: customink + gemfile: "rails5.0" + ruby-version: "2.6" + - tests: + name: "Ruby 2.6 Tests with Rails 5.1" + context: customink + gemfile: "rails5.1" + ruby-version: "2.6" + - tests: + name: "Ruby 2.6 Tests with Rails 5.2" + context: customink + gemfile: "rails5.2" + ruby-version: "2.6" + - tests: + name: "Ruby 2.6 Tests with Rails 6.0" + context: customink + gemfile: "rails6.0" + ruby-version: "2.6" + - tests: + name: "Ruby 2.6 Tests with Rails 6.1" context: customink + gemfile: "rails6.1" + ruby-version: "2.6" diff --git a/.gitignore b/.gitignore index 848ea29..8307f3d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ Gemfile.lock InstalledFiles _yardoc +gemfiles/*.gemfile.lock coverage doc/ lib/bundler/man diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..dce333e --- /dev/null +++ b/Appraisals @@ -0,0 +1,30 @@ +# This is the appraisal file that determines which specific gems should be +# tested in various situations. Because Appraisal was originally developed +# for the Travis CI system, a few minor tweaks are added to this file, +# to ensure we can actually run this properly on CircleCI. +# +# The core change is that we perform a Ruby version check in this file to +# exclude certain configurations from specific Ruby machines to simulate +# the configuration we had in Travis CI where we excluded a specific Gemfile from +# a build. That feature does not exist in CircleCI, so to ensure that the +# "bundle exec appraisal install" command works, +# we exclude certain appraisals when the Ruby version doesn't match. +appraise 'rails5.0' do + gem 'rails', '~> 5.0.0' +end + +appraise 'rails5.1' do + gem 'rails', '~> 5.1.0' +end + +appraise 'rails5.2' do + gem 'rails', '~> 5.2.0' +end + +appraise 'rails6.0' do + gem 'rails', '~> 6.0.0' +end + +appraise 'rails6.1' do + gem 'rails', '~> 6.1.0' +end diff --git a/CHANGELOG.md b/CHANGELOG.md index abf1bb7..b5aead1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # IsItUp Changelog +## 1.0.0 +- Added Appraisal for proper testing against various Rails versions +- Updated documentation +- Enforced direct loading of `::Railtie` + ## 0.0.5 - Fix the autoloading for `Railtie` diff --git a/Gemfile b/Gemfile index 1220c72..9962304 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ source 'https://rubygems.org' gemspec group :test do + gem 'appraisal' gem 'minitest-ci', require: false gem 'simplecov', require: false end diff --git a/gemfiles/rails5.0.gemfile b/gemfiles/rails5.0.gemfile new file mode 100644 index 0000000..a675b4a --- /dev/null +++ b/gemfiles/rails5.0.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 5.0.0" + +group :test do + gem "appraisal" + gem "minitest-ci", require: false + gem "simplecov", require: false +end + +gemspec path: "../" diff --git a/gemfiles/rails5.1.gemfile b/gemfiles/rails5.1.gemfile new file mode 100644 index 0000000..a6cef12 --- /dev/null +++ b/gemfiles/rails5.1.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 5.1.0" + +group :test do + gem "appraisal" + gem "minitest-ci", require: false + gem "simplecov", require: false +end + +gemspec path: "../" diff --git a/gemfiles/rails5.2.gemfile b/gemfiles/rails5.2.gemfile new file mode 100644 index 0000000..ff4dc54 --- /dev/null +++ b/gemfiles/rails5.2.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 5.2.0" + +group :test do + gem "appraisal" + gem "minitest-ci", require: false + gem "simplecov", require: false +end + +gemspec path: "../" diff --git a/gemfiles/rails6.0.gemfile b/gemfiles/rails6.0.gemfile new file mode 100644 index 0000000..fbb63ee --- /dev/null +++ b/gemfiles/rails6.0.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 6.0.0" + +group :test do + gem "appraisal" + gem "minitest-ci", require: false + gem "simplecov", require: false +end + +gemspec path: "../" diff --git a/gemfiles/rails6.1.gemfile b/gemfiles/rails6.1.gemfile new file mode 100644 index 0000000..0323667 --- /dev/null +++ b/gemfiles/rails6.1.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 6.1.0" + +group :test do + gem "appraisal" + gem "minitest-ci", require: false + gem "simplecov", require: false +end + +gemspec path: "../" diff --git a/lib/is_it_up.rb b/lib/is_it_up.rb index ad82d24..924e756 100644 --- a/lib/is_it_up.rb +++ b/lib/is_it_up.rb @@ -1,7 +1,12 @@ require "rack" +# This module defines our Gem, and automatically requires the needed files to ensure that the gem can hook into +# the application's middleware stack when needed, or triggers the Rails boot process properly using the Railtie +# framework. +# Do not swap this code to rely on autoload, since this behavior is not compatible with higher Ruby releases. +# We need to code to be loaded immediately, and not on-demand as this will be too late for the Rails boot process. module IsItUp - autoload :VERSION, "is_it_up/version" - autoload :Middleware, "is_it_up/middleware" - autoload :Railtie, "is_it_up/railtie" if defined?(Rails::Railtie) + require_relative 'is_it_up/version' + require_relative 'is_it_up/middleware' + require_relative 'is_it_up/railtie' if defined?(::Rails::Railtie) end diff --git a/lib/is_it_up/version.rb b/lib/is_it_up/version.rb index bc95bd3..dd5246d 100644 --- a/lib/is_it_up/version.rb +++ b/lib/is_it_up/version.rb @@ -1,3 +1,5 @@ module IsItUp - VERSION = "0.0.5" + VERSION = '1.0.0'.freeze + + public_constant :VERSION end