Skip to content

Migrate from Travis to Github Actions #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
name: CI

on:
- push
- pull_request

jobs:
rspec:
runs-on: ubuntu-20.04

services:
postgres:
image: 'postgres:13'
ports: ['5432:5432']
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: closure_tree
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

strategy:
fail-fast: false
matrix:
ruby:
- '3.0'
- '2.7'
- '2.6'
- '2.5'
rails:
- activerecord_6.1
- activerecord_6.0
- activerecord_5.2
- activerecord_5.1
- activerecord_5.0
- activerecord_4.2
- activerecord_edge
adapter:
- sqlite3
- mysql2
- postgresql
exclude:
- ruby: '2.7'
rails: activerecord_4.2
- ruby: '3.0'
rails: activerecord_4.2
- ruby: '3.0'
rails: activerecord_5.0
- ruby: '3.0'
rails: activerecord_5.1
- ruby: '3.0'
rails: activerecord_5.2
- ruby: '2.5'
rails: activerecord_edge

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Set DB Adapter
env:
RAILS_VERSION: ${{ matrix.rails }}
DB_ADAPTER: ${{ matrix.adapter }}

# See: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#mysql
run: |
if [ "${DB_ADAPTER}" = "mysql2" ]; then
sudo systemctl start mysql.service
mysql -u root -proot -e 'create database closure_tree;'
fi

- name: Bundle
env:
RAILS_VERSION: ${{ matrix.rails }}
DB_ADAPTER: ${{ matrix.adapter }}
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3

- name: RSpec
env:
RAILS_VERSION: ${{ matrix.rails }}
DB_ADAPTER: ${{ matrix.adapter }}
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}
run: bin/rake --trace spec:all
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ tmp/
*.lock
tmp/
.ruby-*
*.iml
*.iml
coverage/
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--format documentation --color --order random
--color
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

15 changes: 15 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ appraise 'activerecord-6.0' do
end
end

appraise 'activerecord-6.1' do
gem 'activerecord', '~> 6.1.0'
platforms :ruby do
gem 'mysql2'
gem 'pg'
gem 'sqlite3'
end

platforms :jruby do
gem 'activerecord-jdbcmysql-adapter'
gem 'activerecord-jdbcpostgresql-adapter'
gem 'activerecord-jdbcsqlite3-adapter'
end
end

appraise 'activerecord-edge' do
gem 'activerecord', github: 'rails/rails'
platforms :ruby do
Expand Down
17 changes: 7 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
# frozen_string_literal: true

Bundler::GemHelper.install_tasks
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec) do |task|
task.pattern = 'spec/*_spec.rb'
task.pattern = 'spec/closure_tree/*_spec.rb'
end

task :default => :spec
task default: :spec

namespace :spec do
desc 'Run all spec variants'
task :all do
rake = 'bundle exec rake'
rake = 'bin/rake'
fail unless system("#{rake} spec:generators")

[['', ''], ['db_prefix_', ''], ['', '_db_suffix'], ['abc_', '_123']].each do |prefix, suffix|
env = "DB_PREFIX=#{prefix} DB_SUFFIX=#{suffix}"
fail unless system("#{rake} spec #{env}")
Expand Down
29 changes: 29 additions & 0 deletions bin/appraisal
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'appraisal' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("appraisal", "appraisal")
29 changes: 29 additions & 0 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rake", "rake")
29 changes: 29 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
8 changes: 6 additions & 2 deletions closure_tree.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'closure_tree/version'
# frozen_string_literal: true

require_relative 'lib/closure_tree/version'

Gem::Specification.new do |gem|
gem.name = 'closure_tree'
Expand All @@ -26,8 +27,11 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'database_cleaner'
gem.add_development_dependency 'generator_spec'
gem.add_development_dependency 'parallel'
gem.add_development_dependency 'pg'
gem.add_development_dependency 'rspec-instafail'
gem.add_development_dependency 'rspec-rails'
gem.add_development_dependency 'sqlite3'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'timecop'
# gem.add_development_dependency 'byebug'
# gem.add_development_dependency 'ruby-prof' # <- don't need this normally.
Expand Down
19 changes: 19 additions & 0 deletions gemfiles/activerecord_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 6.1.0"

platforms :ruby do
gem "mysql2"
gem "pg"
gem "sqlite3"
end

platforms :jruby do
gem "activerecord-jdbcmysql-adapter"
gem "activerecord-jdbcpostgresql-adapter"
gem "activerecord-jdbcsqlite3-adapter"
end

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/closure_tree/has_closure_tree_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def has_closure_tree_root(assoc_name, options = {})
options[:class_name] ||= assoc_name.to_s.sub(/\Aroot_/, "").classify
options[:foreign_key] ||= self.name.underscore << "_id"

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

# Fetches the association, eager loading all children and given associations
define_method("#{assoc_name}_including_tree") do |*args|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'spec_helper'


describe 'cache invalidation', cache: true do
RSpec.describe 'cache invalidation', cache: true do
before do
Timecop.travel(10.seconds.ago) do
#create a long tree with 2 branch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def assert_lineage(e, m)
expect(m.self_and_ancestors).to eq([m, e])
end

describe CuisineType do
RSpec.describe CuisineType do
it "finds self and parents when children << is used" do
e = CuisineType.new(:name => "e")
m = CuisineType.new(:name => "m")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec_helper"

describe "has_closure_tree_root" do
RSpec.describe "has_closure_tree_root" do
let!(:ct1) { ContractType.create!(name: "Type1") }
let!(:ct2) { ContractType.create!(name: "Type2") }
let!(:user1) { User.create!(email: "1@example.com", group_id: group.id) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe ClosureTree::HierarchyMaintenance do
RSpec.describe ClosureTree::HierarchyMaintenance do
describe '.rebuild!' do
it 'rebuild tree' do
20.times do |counter|
Expand Down
Loading