Skip to content

Commit

Permalink
Merge pull request #220 from watermarkchurch/middleman
Browse files Browse the repository at this point in the history
Get core wcc-contentful gem working without rails
  • Loading branch information
gburgett committed Mar 26, 2020
2 parents 6316de9 + 039909e commit 8c5cd55
Show file tree
Hide file tree
Showing 44 changed files with 844 additions and 276 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -15,6 +15,9 @@
.bundle
.ruby-version

# these are generated by bin/use from the Appraisal gems
wcc-*/Gemfile

# exports and error logs from contentful
contentful-export*
contentful-*-error-log-*
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Expand Up @@ -9,6 +9,7 @@ AllCops:

# generated by appraisals
- 'gemfiles/**/*'
- '*/Gemfile'

# auto generated by rails

Expand Down
34 changes: 22 additions & 12 deletions .travis.yml
Expand Up @@ -4,29 +4,39 @@ cache:
directories:
- /tmp/vendor/bundle
- node_modules
rvm:
- 2.3.8
- 2.5.3
gemfile:
- gemfiles/rails_5.2.gemfile
- gemfiles/rails_5.0.gemfile
addons:
postgresql: "10"
apt:
packages:
- postgresql-10
- postgresql-client-10
before_install: gem install bundler -v 1.16.1
before_install: gem install bundler -v 1.17.3
install:
- bin/use
- bundle install --path /tmp/vendor/bundle
- bin/bundle install --path /tmp/vendor/bundle
script:
- export COVERALLS_PARALLEL=true
- bin/bundle exec rspec --format documentation --order rand
# only run coverage on the wcc-contentful gem
- bundle exec rake coverage
- bundle exec rake coverage:coveralls
jobs:
include:
- rvm: 2.5.7
gemfile: gemfiles/rails_5.2_ruby_2.5.7.gemfile
- rvm: 2.3.8
gemfile: gemfiles/rails_5.2_ruby_2.3.8.gemfile
- rvm: 2.5.7
gemfile: gemfiles/rails_5.0_ruby_2.5.7.gemfile
- rvm: 2.3.8
gemfile: gemfiles/rails_5.0_ruby_2.3.8.gemfile
- rvm: 2.5.7
gemfile: gemfiles/middleman_4.2_ruby_2.5.7.gemfile
- stage: coverage
script:
- bundle exec rake coverage
- bundle exec rake coverage:coveralls
# Keep in mind to overwrite these here
rvm: 2.5.7
gemfile: gemfiles/rails_5.2_ruby_2.5.7.gemfile
- stage: lint
before_script:
- npm install
Expand All @@ -36,7 +46,7 @@ jobs:
- bundle exec erblint '*/app/views/**/*.erb'
- npm run lint
# Keep in mind to overwrite these here
rvm: 2.5
gemfile: gemfiles/rails_5.2.gemfile
rvm: 2.5.7
gemfile: gemfiles/rails_5.2_ruby_2.5.7.gemfile
notifications:
webhooks: https://coveralls.io/webhook
45 changes: 38 additions & 7 deletions Appraisals
@@ -1,11 +1,42 @@
# frozen_string_literal: true

appraise 'rails-5.2' do
gem 'rails', '~> 5.2.0'
gem 'railties', '~> 5.2.0'
end
rubies =
[
'2.3.8',
'2.5.7'
].map { |r| Gem::Version.new(r) }

rubies.each do |ruby_version|
common =
proc do
ruby ruby_version.to_s
end

appraise "rails-5.2_ruby-#{ruby_version}" do
gem 'rails', '~> 5.2.0'
gem 'railties', '~> 5.2.0'

group :test do
gem 'rspec-rails', '~> 3.7'
end

instance_exec(&common)
end

appraise "rails-5.0_ruby-#{ruby_version}" do
gem 'rails', '~> 5.0.0'
gem 'railties', '~> 5.0.0'

group :test do
gem 'rspec-rails', '~> 3.7'
end

instance_exec(&common)
end

appraise "middleman-4.2_ruby-#{ruby_version}" do
gem 'middleman', '~> 4.2'

appraise 'rails-5.0' do
gem 'rails', '~> 5.0.0'
gem 'railties', '~> 5.0.0'
instance_exec(&common)
end
end
7 changes: 3 additions & 4 deletions Gemfile
Expand Up @@ -3,9 +3,10 @@
source 'https://rubygems.org'

# Development tools intended to be run in the root
group :development, :test do
group :development do
gem 'appraisal'
gem 'bump', '~> 0.8.0'
gem 'coveralls', '~> 0.8.22'
gem 'danger-wcc', '~> 0.0.5'
gem 'erb_lint', require: false
gem 'guard'
Expand All @@ -14,7 +15,5 @@ group :development, :test do
gem 'guard-shell', '~> 0.7.1'
gem 'rake', '~> 13.0'
gem 'rubocop', '0.68', require: false
gem 'simplecov', '~> 0.16'
end

gemspec path: './wcc-contentful'
gemspec path: './wcc-contentful-app'
77 changes: 65 additions & 12 deletions README.md
Expand Up @@ -11,35 +11,88 @@ Contentful.
## Supported Rails versions

Please see the [most recent Travis-CI build](https://travis-ci.org/watermarkchurch/wcc-contentful) for the most
up-to-date list of supported Rails versions. At the time of this writing, the gem officially supports
the following:
up-to-date list of supported framework environments. At the time of this writing,
the gem officially supports the following:

* Ruby versions:
* 2.5
* 2.3
* Rails versions:
* 5.2
* 5.0
* Framework versions:
* Rails 5.2
* Rails 5.0
* Middleman 4.2

Pull requests are welcome to enable supporting other ruby and rails versions!
Pull requests are welcome to enable supporting other frameworks!

To get started in testing a new Ruby version, use `rvm` or `rbenv` to choose your
rails version and then run all specs using the `bin/bundle` helper:
ruby version. Then, check out the appropriate Gemfile using the `bin/use` helper:

```bash
$ rbenv local 2.2.6
$ gem install bundler
$ bundle install
$ bin/bundle exec rspec
$ bin/use gemfiles/rails_5.2.gemfile
```

To get started testing a new rails version, add the appropriate combination of gems to the `Appraisals` file
and run `bundle exec appraisal install` to generate the appropriate gemfile in the `gemfiles` directory.
Then you can use the `bin/bundle` helper to run tests, while setting the BUNDLE_GEMFILE:
Now each of the `wcc-` gems has a Gemfile based on that Appraisal gemfile. `cd`
into the gem's directory and run `bundle install` to install the gems.

### Adding a new Rails version

To get started testing a new framework, add the appropriate combination of gems to the `Appraisals` file
and run `bundle exec appraisal install` to generate the appropriate gemfile in the `gemfiles` directory:

```diff
diff --git a/Appraisals b/Appraisals
index 041abea..917142f 100644
--- a/Appraisals
+++ b/Appraisals
@@ -1,5 +1,9 @@
# frozen_string_literal: true

+appraise 'sinatra-2.0' do
+ gem 'sinatra', '~> 2.0.0'
+end
+
appraise 'rails-5.2' do
gem 'rails', '~> 5.2.0'
gem 'railties', '~> 5.2.0'
```

Then you can use the `bin/use` helper to check out that set of gems:

```bash
$ bundle exec appraisal install
$ BUNDLE_GEMFILE=`pwd`/gemfiles/rails_4.2.gemfile bin/bundle exec rspec
$ bin/use gemfiles/rails_6.0.gemfile
```

And build a helper that conditionally includes your framework specs based on whether
that gem is installed. Example:

```rb
# spec/active_record_helper.rb

require 'spec_helper'

begin
gem 'activerecord'
require 'active_record'
rescue Gem::LoadError => e
# active_record is not loaded in this test run
warn "WARNING: Cannot load active_record - some tests will be skipped\n#{e}"
end

if defined?(ActiveJob)
ActiveJob::Base.queue_adapter = :test
else
RSpec.configure do |c|
# skip active record based specs
c.before(:each, active_record: true) do
skip 'activerecord is not loaded'
end
end
end

```

## Contributing
Expand Down
5 changes: 4 additions & 1 deletion Rakefile
Expand Up @@ -20,7 +20,10 @@ GEMS.each do |name|
end

task :coverage do
system('rspec', chdir: name)
Bundler.with_clean_env do
warn "#{name} $ bundle exec rspec"
system('bundle exec rspec', chdir: name)
end
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions bin/bundle
Expand Up @@ -2,10 +2,6 @@

set -e

if [[ -z "$BUNDLE_GEMFILE" ]]; then
export BUNDLE_GEMFILE=`pwd`/Gemfile
fi

gems=(wcc-*)

for gem in "${gems[@]}"
Expand All @@ -14,7 +10,7 @@ do
(
cd $gem;
echo "$(basename `pwd`) $ bundle $*";
bundle "$@";
BUNDLE_GEMFILE=`pwd`/Gemfile bundle "$@";
)
done

29 changes: 29 additions & 0 deletions bin/use
@@ -0,0 +1,29 @@
#! /bin/bash

gemfile="$1"
[[ -z "$gemfile" ]] && gemfile="$BUNDLE_GEMFILE"
[[ -z "$gemfile" ]] && echo "No Gemfile specified" && exit -1;

gemfile=$(cd "$(dirname "$gemfile")"; pwd -P)/$(basename "$gemfile")

gems=(wcc-*)

echo "Using ${gemfile} in ${gems[*]}"

for gem in "${gems[@]}"
do
# in a subshell, CD into the directory and update the gemfile
(
cd $gem;
cp $gemfile Gemfile
echo "gemspec" >> Gemfile

# does this gem depend on any others?
for dep in "${gems[@]}"
do
if grep "spec.add_dependency '$dep'" "$gem.gemspec"; then
echo "gem '$dep', path: File.expand_path('../$dep', __dir__)" >> Gemfile
fi
done
)
done
22 changes: 22 additions & 0 deletions gemfiles/middleman_4.2_ruby_2.3.8.gemfile
@@ -0,0 +1,22 @@
# This file was generated by Appraisal

source "https://rubygems.org"

ruby "2.3.8"

gem "middleman", "~> 4.2"

group :development do
gem "appraisal"
gem "bump", "~> 0.8.0"
gem "coveralls", "~> 0.8.22"
gem "danger-wcc", "~> 0.0.5"
gem "erb_lint", require: false
gem "guard"
gem "guard-rspec"
gem "guard-rubocop"
gem "guard-shell", "~> 0.7.1"
gem "rake", "~> 13.0"
gem "rubocop", "0.68", require: false
gem "simplecov", "~> 0.16"
end
22 changes: 22 additions & 0 deletions gemfiles/middleman_4.2_ruby_2.5.7.gemfile
@@ -0,0 +1,22 @@
# This file was generated by Appraisal

source "https://rubygems.org"

ruby "2.5.7"

gem "middleman", "~> 4.2"

group :development do
gem "appraisal"
gem "bump", "~> 0.8.0"
gem "coveralls", "~> 0.8.22"
gem "danger-wcc", "~> 0.0.5"
gem "erb_lint", require: false
gem "guard"
gem "guard-rspec"
gem "guard-rubocop"
gem "guard-shell", "~> 0.7.1"
gem "rake", "~> 13.0"
gem "rubocop", "0.68", require: false
gem "simplecov", "~> 0.16"
end
Expand Up @@ -2,21 +2,26 @@

source "https://rubygems.org"

ruby "2.3.8"

gem "rails", "~> 5.0.0"
gem "railties", "~> 5.0.0"

group :development, :test do
group :development do
gem "appraisal"
gem "bump", "~> 0.6.1"
gem "bump", "~> 0.8.0"
gem "coveralls", "~> 0.8.22"
gem "danger-wcc", "~> 0.0.5"
gem "erb_lint", require: false
gem "guard"
gem "guard-rspec"
gem "guard-rubocop"
gem "guard-shell", "~> 0.7.1"
gem "rake", "~> 12.3"
gem "rubocop", '0.68', require: false
gem "rake", "~> 13.0"
gem "rubocop", "0.68", require: false
gem "simplecov", "~> 0.16"
end

gemspec path: "../wcc-contentful"
gemspec path: "../wcc-contentful-app"
group :test do
gem "rspec-rails", "~> 3.7"
end

0 comments on commit 8c5cd55

Please sign in to comment.