Skip to content

Commit 22bbbf1

Browse files
authored
Migrate from Travis to Github Actions (#373)
Ruby 3.0 support
1 parent 07f4dfd commit 22bbbf1

37 files changed

+372
-195
lines changed

.github/workflows/ci.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
name: CI
3+
4+
on:
5+
- push
6+
- pull_request
7+
8+
jobs:
9+
rspec:
10+
runs-on: ubuntu-20.04
11+
12+
services:
13+
postgres:
14+
image: 'postgres:13'
15+
ports: ['5432:5432']
16+
env:
17+
POSTGRES_PASSWORD: postgres
18+
POSTGRES_DB: closure_tree
19+
options: >-
20+
--health-cmd pg_isready
21+
--health-interval 10s
22+
--health-timeout 5s
23+
--health-retries 5
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
ruby:
29+
- '3.0'
30+
- '2.7'
31+
- '2.6'
32+
- '2.5'
33+
rails:
34+
- activerecord_6.1
35+
- activerecord_6.0
36+
- activerecord_5.2
37+
- activerecord_5.1
38+
- activerecord_5.0
39+
- activerecord_4.2
40+
- activerecord_edge
41+
adapter:
42+
- sqlite3
43+
- mysql2
44+
- postgresql
45+
exclude:
46+
- ruby: '2.7'
47+
rails: activerecord_4.2
48+
- ruby: '3.0'
49+
rails: activerecord_4.2
50+
- ruby: '3.0'
51+
rails: activerecord_5.0
52+
- ruby: '3.0'
53+
rails: activerecord_5.1
54+
- ruby: '3.0'
55+
rails: activerecord_5.2
56+
- ruby: '2.5'
57+
rails: activerecord_edge
58+
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v2
62+
63+
- name: Setup Ruby
64+
uses: ruby/setup-ruby@v1
65+
with:
66+
ruby-version: ${{ matrix.ruby }}
67+
68+
- name: Set DB Adapter
69+
env:
70+
RAILS_VERSION: ${{ matrix.rails }}
71+
DB_ADAPTER: ${{ matrix.adapter }}
72+
73+
# See: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#mysql
74+
run: |
75+
if [ "${DB_ADAPTER}" = "mysql2" ]; then
76+
sudo systemctl start mysql.service
77+
mysql -u root -proot -e 'create database closure_tree;'
78+
fi
79+
80+
- name: Bundle
81+
env:
82+
RAILS_VERSION: ${{ matrix.rails }}
83+
DB_ADAPTER: ${{ matrix.adapter }}
84+
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
85+
run: |
86+
gem install bundler
87+
bundle config path vendor/bundle
88+
bundle install --jobs 4 --retry 3
89+
90+
- name: RSpec
91+
env:
92+
RAILS_VERSION: ${{ matrix.rails }}
93+
DB_ADAPTER: ${{ matrix.adapter }}
94+
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
95+
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}
96+
run: bin/rake --trace spec:all

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ tmp/
1313
*.lock
1414
tmp/
1515
.ruby-*
16-
*.iml
16+
*.iml
17+
coverage/

.rspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--format documentation --color --order random
1+
--color

.travis.yml

-36
This file was deleted.

Appraisals

+15
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ appraise 'activerecord-6.0' do
7474
end
7575
end
7676

77+
appraise 'activerecord-6.1' do
78+
gem 'activerecord', '~> 6.1.0'
79+
platforms :ruby do
80+
gem 'mysql2'
81+
gem 'pg'
82+
gem 'sqlite3'
83+
end
84+
85+
platforms :jruby do
86+
gem 'activerecord-jdbcmysql-adapter'
87+
gem 'activerecord-jdbcpostgresql-adapter'
88+
gem 'activerecord-jdbcsqlite3-adapter'
89+
end
90+
end
91+
7792
appraise 'activerecord-edge' do
7893
gem 'activerecord', github: 'rails/rails'
7994
platforms :ruby do

Rakefile

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
begin
2-
require 'bundler/setup'
3-
rescue LoadError
4-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5-
end
1+
# frozen_string_literal: true
62

7-
Bundler::GemHelper.install_tasks
3+
require 'bundler/gem_tasks'
4+
require 'rspec/core/rake_task'
85

9-
require "rspec/core/rake_task"
106
RSpec::Core::RakeTask.new(:spec) do |task|
11-
task.pattern = 'spec/*_spec.rb'
7+
task.pattern = 'spec/closure_tree/*_spec.rb'
128
end
139

14-
task :default => :spec
10+
task default: :spec
1511

1612
namespace :spec do
1713
desc 'Run all spec variants'
1814
task :all do
19-
rake = 'bundle exec rake'
15+
rake = 'bin/rake'
2016
fail unless system("#{rake} spec:generators")
17+
2118
[['', ''], ['db_prefix_', ''], ['', '_db_suffix'], ['abc_', '_123']].each do |prefix, suffix|
2219
env = "DB_PREFIX=#{prefix} DB_SUFFIX=#{suffix}"
2320
fail unless system("#{rake} spec #{env}")

bin/appraisal

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'appraisal' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("appraisal", "appraisal")

bin/rake

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rake' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("rake", "rake")

bin/rspec

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rspec' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("rspec-core", "rspec")

closure_tree.gemspec

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
2-
require 'closure_tree/version'
1+
# frozen_string_literal: true
2+
3+
require_relative 'lib/closure_tree/version'
34

45
Gem::Specification.new do |gem|
56
gem.name = 'closure_tree'
@@ -26,8 +27,11 @@ Gem::Specification.new do |gem|
2627
gem.add_development_dependency 'database_cleaner'
2728
gem.add_development_dependency 'generator_spec'
2829
gem.add_development_dependency 'parallel'
30+
gem.add_development_dependency 'pg'
2931
gem.add_development_dependency 'rspec-instafail'
3032
gem.add_development_dependency 'rspec-rails'
33+
gem.add_development_dependency 'sqlite3'
34+
gem.add_development_dependency 'simplecov'
3135
gem.add_development_dependency 'timecop'
3236
# gem.add_development_dependency 'byebug'
3337
# gem.add_development_dependency 'ruby-prof' # <- don't need this normally.

gemfiles/activerecord_6.1.gemfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "activerecord", "~> 6.1.0"
6+
7+
platforms :ruby do
8+
gem "mysql2"
9+
gem "pg"
10+
gem "sqlite3"
11+
end
12+
13+
platforms :jruby do
14+
gem "activerecord-jdbcmysql-adapter"
15+
gem "activerecord-jdbcpostgresql-adapter"
16+
gem "activerecord-jdbcsqlite3-adapter"
17+
end
18+
19+
gemspec path: "../"

lib/closure_tree/has_closure_tree_root.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def has_closure_tree_root(assoc_name, options = {})
88
options[:class_name] ||= assoc_name.to_s.sub(/\Aroot_/, "").classify
99
options[:foreign_key] ||= self.name.underscore << "_id"
1010

11-
has_one assoc_name, -> { where(parent: nil) }, options
11+
has_one assoc_name, -> { where(parent: nil) }, **options
1212

1313
# Fetches the association, eager loading all children and given associations
1414
define_method("#{assoc_name}_including_tree") do |*args|

spec/cache_invalidation_spec.rb spec/closure_tree/cache_invalidation_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'spec_helper'
22

3-
4-
describe 'cache invalidation', cache: true do
3+
RSpec.describe 'cache invalidation', cache: true do
54
before do
65
Timecop.travel(10.seconds.ago) do
76
#create a long tree with 2 branch

spec/cuisine_type_spec.rb spec/closure_tree/cuisine_type_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def assert_lineage(e, m)
99
expect(m.self_and_ancestors).to eq([m, e])
1010
end
1111

12-
describe CuisineType do
12+
RSpec.describe CuisineType do
1313
it "finds self and parents when children << is used" do
1414
e = CuisineType.new(:name => "e")
1515
m = CuisineType.new(:name => "m")

spec/has_closure_tree_root_spec.rb spec/closure_tree/has_closure_tree_root_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "spec_helper"
22

3-
describe "has_closure_tree_root" do
3+
RSpec.describe "has_closure_tree_root" do
44
let!(:ct1) { ContractType.create!(name: "Type1") }
55
let!(:ct2) { ContractType.create!(name: "Type2") }
66
let!(:user1) { User.create!(email: "[email protected]", group_id: group.id) }

spec/hierarchy_maintenance_spec.rb spec/closure_tree/hierarchy_maintenance_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'spec_helper'
22

3-
describe ClosureTree::HierarchyMaintenance do
3+
RSpec.describe ClosureTree::HierarchyMaintenance do
44
describe '.rebuild!' do
55
it 'rebuild tree' do
66
20.times do |counter|

0 commit comments

Comments
 (0)