Skip to content

Commit

Permalink
Pivot to GitHub Actions
Browse files Browse the repository at this point in the history
In late 2020, Travis CI decided to discontinue unlimited free builds
for public projects. While they still hand out free build minutes
for opensource project, they do this through an application process,
thereby making it difficult to quickly contribure:

https://www.jeffgeerling.com/blog/2020/travis-cis-new-pricing-plan-threw-wrench-my-open-source-works

Since GitHub Actions still allows unlimited build time for public
project, it became the go-to CI for opensource projects on GitHub.

We also update the test build to include Rails 6 and 7.
  • Loading branch information
leoarnold committed Jul 5, 2022
1 parent 1029813 commit edb50ce
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_GITHUB__HTTPS: "true"
76 changes: 76 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
on:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
ruby:
- ruby-head
- jruby-head
rails:
- 7
- master
rails_api_only:
- 0
- 1
jruby_ar_jdbc_adapter_version:
- v70.0.pre
experimental:
- true
include:
- ruby: 2.7
rails: 5
rails_api_only: 0
experimental: false
- ruby: 2.7
rails: 5
rails_api_only: 1
experimental: false
- ruby: 2.7
rails: 6
rails_api_only: 0
experimental: false
- ruby: 2.7
rails: 6
rails_api_only: 1
experimental: false
- ruby: 3.1
rails: 7
rails_api_only: 0
experimental: false
- ruby: 3.1
rails: 7
rails_api_only: 1
experimental: false
- ruby: jruby-9.1
rails: 5
rails_api_only: 0
jruby_ar_jdbc_adapter_version: v52.8
experimental: false
- ruby: jruby-9.2
rails: 6
rails_api_only: 0
jruby_ar_jdbc_adapter_version: v60.0
experimental: false

steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
env:
RAILS_VERSION: ${{ matrix.rails }}
RAILS_API_ONLY: ${{ matrix.rails_api_only }}
JRUBY_AR_JDBC_ADAPTER_VERSION: ${{ matrix.jruby_ar_jdbc_adapter_version }}
- run: bundle exec rake
env:
RAILS_VERSION: ${{ matrix.rails }}
RAILS_API_ONLY: ${{ matrix.rails_api_only }}
JRUBY_AR_JDBC_ADAPTER_VERSION: ${{ matrix.jruby_ar_jdbc_adapter_version }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.gem
.bundle
Gemfile.lock

pkg/*
tmp/*
44 changes: 1 addition & 43 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,6 @@
language: ruby
cache: bundler
rvm:
- 2.5.0
- 2.4.4
- 2.3.5
- jruby-9.1.13.0
- ruby-head
- jruby-head
env:
- RAILS_VERSION=master
- RAILS_VERSION=master RAILS_API_ONLY=1
- RAILS_VERSION=5.2
- RAILS_VERSION=5.2 RAILS_API_ONLY=1
- RAILS_VERSION=5.1
- RAILS_VERSION=5.1 RAILS_API_ONLY=1
- RAILS_VERSION=5.0
- RAILS_VERSION=5.0 RAILS_API_ONLY=1
matrix:
include:
- rvm: 2.2.8
env: RAILS_VERSION=4.2
- rvm: 2.1.10
env: RAILS_VERSION=4.2
- rvm: 2.0.0
env: RAILS_VERSION=4.2
- rvm: 2.2.8
env: RAILS_VERSION=4.1
- rvm: 2.1.10
env: RAILS_VERSION=4.1
- rvm: 2.0.0
env: RAILS_VERSION=4.1
exclude:
- rvm: 2.4.4
env: RAILS_VERSION=master
- rvm: 2.4.4
env: RAILS_VERSION=master RAILS_API_ONLY=1
- rvm: 2.3.5
env: RAILS_VERSION=master
- rvm: 2.3.5
env: RAILS_VERSION=master RAILS_API_ONLY=1
allow_failures:
- rvm: jruby-9.1.13.0
- rvm: ruby-head
- rvm: jruby-head
ruby: 2.5.0
before_deploy: bundle exec rake assets:compile
deploy:
provider: rubygems
Expand Down
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ group :test do
gem 'sassc-rails'
end

gem "activerecord-jdbcsqlite3-adapter", platform: :jruby,
github: "jruby/activerecord-jdbc-adapter"
if RUBY_PLATFORM == 'java'
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby,
github: "jruby/activerecord-jdbc-adapter", tag: ENV['JRUBY_AR_JDBC_ADAPTER_VERSION']
end

gem "minitest", ">= 4.2"
gem "capybara", ">= 2.6"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[<img src="https://travis-ci.org/voormedia/flipflop.svg?branch=master" alt="Build Status">](https://travis-ci.org/voormedia/flipflop)
![GitHub Actions](https://github.com/voormedia/flipflop/actions/workflows/test.yml/badge.svg)

# Flipflop your features

Expand Down
4 changes: 2 additions & 2 deletions lib/flipflop/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def feature(feature, **options)
FeatureSet.current.add(feature)
end

def strategy(strategy = nil, **options)
def strategy(strategy = nil, **options, &block)
if block_given?
options[:name] = strategy.to_s
options[:lambda] = Proc.new
options[:lambda] = block
strategy = Strategies::LambdaStrategy
end

Expand Down
2 changes: 2 additions & 0 deletions lib/flipflop/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def feature_set
end

def respond_to_missing?(method, include_private = false)
return false if method == :use_relative_model_naming?

method[-1] == "?"
end

Expand Down
3 changes: 2 additions & 1 deletion lib/flipflop/strategies/cookie_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def switch!(feature, enabled)
end

def clear!(feature)
request.cookie_jar.delete(cookie_key(feature), **@options)
options = @options.dup
request.cookie_jar.delete(cookie_key(feature), **options)
end

protected
Expand Down
34 changes: 28 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "minitest/autorun"

require "action_controller"
require "action_controller/test_case"
require "rails/generators"

# Who is setting this to true? :o
Expand All @@ -14,6 +15,7 @@ def create_request
env = Rack::MockRequest.env_for("/example")
request = ActionDispatch::TestRequest.new(env)
request.host = "example.com"
request.session = ActionController::TestSession.new

class << request
def cookie_jar
Expand Down Expand Up @@ -46,7 +48,7 @@ def capture_stderr
end

def reload_constant(name)
ActiveSupport::Dependencies.remove_constant(name.to_s)
Object.send(:remove_const, name.to_s)
path = ActiveSupport::Dependencies.search_for_file(name.to_s.underscore).sub!(/\.rb\z/, "")
ActiveSupport::Dependencies.loaded.delete(path)
Object.const_get(name)
Expand Down Expand Up @@ -112,10 +114,11 @@ def create!

Rails::Generators::AppGenerator.new([path],
quiet: true,
api: ENV["RAILS_API_ONLY"].to_i.nonzero?,
api: rails_api_only?,
skip_active_job: true,
skip_active_storage: true,
skip_action_cable: true,
skip_action_mailer: true,
skip_bootsnap: true,
skip_bundle: true,
skip_puma: true,
Expand All @@ -128,6 +131,13 @@ def create!
skip_turbolinks: true,
).invoke_all

if rails_api_only?
project_root = Pathname.new(__dir__.to_s).parent
manifest_path = project_root.join(path).join("app/assets/config/manifest.js")
manifest_path.dirname.mkpath
manifest_path.write(project_root.join("app/assets/config/manifest.js").read)
end

# Remove bootsnap if present, this interferes with reloading apps.
boot_path = File.expand_path("../../" + path + "/config/boot.rb", __FILE__)
File.write(boot_path, File.read(boot_path).gsub("require 'bootsnap/setup'", ""))
Expand All @@ -146,11 +156,17 @@ def load!
require "rails"
require "flipflop/engine"

ActiveSupport::Dependencies.autoloaded_constants.clear
ActiveSupport::Dependencies.autoload_paths = []
ActiveSupport::Dependencies.autoload_once_paths = []
load File.expand_path("../../#{path}/config/application.rb", __FILE__)
Zeitwerk::Registry.loaders.each(&:unregister) if defined?(Zeitwerk)
load File.expand_path("../../#{path}/config/environments/test.rb", __FILE__)
Rails.application.config.cache_classes = false
Rails.application.config.action_view.raise_on_missing_translations = true
if Gem::Version.new(Rails.version) < Gem::Version.new('7')
Rails.application.config.action_view.raise_on_missing_translations = true
else
Rails.application.config.i18n.raise_on_missing_translations = true
end
Rails.application.config.i18n.enforce_available_locales = false
Rails.application.config.autoloader = :classic # Disable Zeitwerk in Rails 6+

Expand All @@ -166,7 +182,9 @@ def load!
Rails.application.config.action_view.finalize_compiled_template_methods = ActionView::Railtie::NULL_OPTION
end

Rails.application.config.active_support.remove_deprecated_time_with_zone_name = false
Rails.application.initialize!
Zeitwerk::Registry.loaders.each(&:unregister) if defined?(Zeitwerk)

I18n.locale = :en

Expand Down Expand Up @@ -202,12 +220,16 @@ def unload!
Rails.instance_variable_set(:@application, nil)
I18n::Railtie.instance_variable_set(:@i18n_inited, false)

ActiveSupport::Dependencies.remove_constant(name.camelize)
ActiveSupport::Dependencies.remove_constant("Flipflop::Feature")
Object.send(:remove_const, name.camelize)
Flipflop.send(:remove_const, "Feature")
end

private

def rails_api_only?
ENV["RAILS_API_ONLY"].to_i.nonzero?
end

def path
"tmp/" + name
end
Expand Down
5 changes: 3 additions & 2 deletions test/unit/feature_definition_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

it "should have location" do
# Because we have no indirection via FeatureSet, the location is minitest.
assert_equal "instance_eval", subject.location.label
assert ["block in let", "instance_eval"].include?(subject.location.label)
end
end

Expand Down Expand Up @@ -71,7 +71,8 @@

it "should have location" do
# Because we have no indirection via FeatureSet, the location is minitest.
assert_equal "instance_eval", subject.location.label
expected = RUBY_PLATFORM == "java" ? "block in let" : "instance_eval"
assert_equal expected, subject.location.label
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/tasks/support/methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def with_feature_and_strategy(strategy = 'Test')
describe 'when the strategy is not switchable' do
it 'raises an error' do
with_feature_and_strategy 'Lambda' do |strategy, feature|
-> { subject.switch_feature!('world_domination', 'lambda', true) }.must_raise
_{ subject.switch_feature!('world_domination', 'lambda', true) }.must_raise
end
end
end
Expand Down

0 comments on commit edb50ce

Please sign in to comment.