Skip to content
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
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
ruby:
- '2.4'
- '2.5'
- '2.6'
- '2.7'
- '3.0'
- '3.1'
- '3.2'
- '3.3'
include:
- ruby: 'head'
continue-on-error: true
- ruby: 'jruby-9.4'
continue-on-error: true
# Ruby 2.2-2.3 are very old and may have stability issues
- ruby: '2.2'
continue-on-error: true
- ruby: '2.3'
continue-on-error: true

continue-on-error: ${{ matrix.continue-on-error || false }}

services:
postgres:
image: postgres:13
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: 111
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: 111
MYSQL_DATABASE: leafy_test
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

env:
COVERAGE: 1

steps:
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Run tests
run: bundle exec rspec

- name: Upload coverage to Codecov
if: matrix.ruby == '3.3'
uses: codecov/codecov-action@v4
with:
files: ./coverage/.resultset.json
flags: ruby-${{ matrix.ruby }}
fail_ci_if_error: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
Gemfile.lock
.ruby-version
.docker
vendor/
81 changes: 81 additions & 0 deletions GITHUB_ACTIONS_MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Migration from Travis CI to GitHub Actions

## Changes Made

### 1. GitHub Actions Workflow (`.github/workflows/ci.yml`)
- Created a new CI workflow that tests against multiple Ruby versions
- **Ruby versions tested**: 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, head, jruby-9.4
- Set up PostgreSQL and MySQL services (matching your docker-compose setup)
- Integrated Code Climate test reporter for coverage (only on Ruby 3.3)
- Allow failures for Ruby head and JRuby (won't block CI)

### 2. Updated `leafy.gemspec`
- Improved ActiveRecord version selection based on Ruby version:
- Ruby 2.2-2.4: ActiveRecord ~> 5.2
- Ruby 2.5-2.6: ActiveRecord ~> 6.0
- Ruby 2.7+: ActiveRecord ~> 6.1
- Added pg version constraint `< 2.0` for better compatibility

### 3. Updated `Gemfile`
- Made Ruby 3.4+ bundled gems conditional (only loaded when RUBY_VERSION >= 3.4.0)
- This ensures older Ruby versions don't have issues with gems they don't need

### 4. Updated `spec/spec_helper.rb`
- Made bundled gem requires conditional for Ruby 3.4+
- Ensures compatibility across all Ruby versions

### 5. Updated `README.md`
- Replaced Travis CI badge with GitHub Actions badge

## Testing the Setup

### Local Testing
Ensure tests still pass locally:
```bash
bundle install
bundle exec rspec
```

### Testing with Different Ruby Versions (using Docker)
```bash
# Ruby 2.7
docker run -it --rm -v $(pwd):/app -w /app ruby:2.7 bash -c "bundle install && bundle exec rspec"

# Ruby 3.0
docker run -it --rm -v $(pwd):/app -w /app ruby:3.0 bash -c "bundle install && bundle exec rspec"

# Ruby 3.1
docker run -it --rm -v $(pwd):/app -w /app ruby:3.1 bash -c "bundle install && bundle exec rspec"
```

## What to Do Next

1. **Commit the changes**:
```bash
git add .github/workflows/ci.yml
git add Gemfile leafy.gemspec spec/spec_helper.rb README.md
git rm .travis.yml
git commit -m "Migrate from Travis CI to GitHub Actions"
```

2. **Push to GitHub**:
```bash
git push origin master
```

3. **Verify the workflow**:
- Go to your repository on GitHub
- Click on the "Actions" tab
- You should see the CI workflow running
- Check that tests pass for all Ruby versions

## Notes

- The workflow runs on every push to `master`/`main` branches and on pull requests
- Ruby 2.2-2.4 may have limitations with newer gems, so ActiveRecord 5.2 is used
- Ruby 3.4+ requires explicit bundled gem declarations (erb, logger, mutex_m, etc.)
- Code Climate coverage is only uploaded from Ruby 3.3 builds to avoid duplicates

## Cleanup

You can safely delete `.travis.yml` after confirming GitHub Actions is working.
24 changes: 24 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,27 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in leafy.gemspec
gemspec

# Ruby 2.5+ bundled gems needed by ActiveRecord 6.0+
if RUBY_VERSION >= "2.5.0"
gem 'logger'
end

# Ruby 3.0+ additional bundled gems
if RUBY_VERSION >= "3.0.0"
gem 'mutex_m'
gem 'base64'
gem 'benchmark' # Needed by ActiveSupport in Ruby 3.3+/4.x
end

# Ruby 3.1+ additional bundled gems
if RUBY_VERSION >= "3.1.0"
gem 'csv'
end

# Ruby 3.4+ additional bundled gems
if RUBY_VERSION >= "3.4.0"
gem 'erb'
gem 'bigdecimal'
gem 'drb'
end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Leafy [![Build Status](https://travis-ci.org/estepnv/leafy.svg?branch=master)](https://travis-ci.org/estepnv/leafy) [![Maintainability](https://api.codeclimate.com/v1/badges/5108d8a1ac5e2915f30f/maintainability)](https://codeclimate.com/github/estepnv/leafy/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/5108d8a1ac5e2915f30f/test_coverage)](https://codeclimate.com/github/estepnv/leafy/test_coverage)
# Leafy [![CI](https://github.com/estepnv/leafy/actions/workflows/ci.yml/badge.svg)](https://github.com/estepnv/leafy/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/estepnv/leafy/branch/master/graph/badge.svg)](https://codecov.io/gh/estepnv/leafy) [![Maintainability](https://api.codeclimate.com/v1/badges/5108d8a1ac5e2915f30f/maintainability)](https://codeclimate.com/github/estepnv/leafy/maintainability)

A toolkit for dynamic custom attributes for Ruby applications.

Expand Down
37 changes: 30 additions & 7 deletions leafy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,40 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "simplecov", '~> 0.17.1'

if RUBY_VERSION >= "2.5.0"
spec.add_development_dependency "activerecord", "~> 6.0"
# ActiveRecord version based on Ruby version
if RUBY_VERSION >= "2.7.0"
spec.add_development_dependency "activerecord", "~> 6.1.0"
elsif RUBY_VERSION >= "2.5.0"
spec.add_development_dependency "activerecord", "~> 6.0.0"
else
spec.add_development_dependency "activerecord", "~> 5.2"
spec.add_development_dependency "activerecord", "~> 5.2.0"
end

if RUBY_ENGINE == "jruby"
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "51"
spec.add_development_dependency "pg_jruby"
# JDBC adapter version must match ActiveRecord version
if RUBY_VERSION >= "2.7.0"
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "~> 61.0"
elsif RUBY_VERSION >= "2.5.0"
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "~> 60.0"
else
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "~> 52.0"
end
spec.add_development_dependency "jdbc-postgres"
else
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "pg"
# sqlite3 version based on Ruby version (1.4+ requires Ruby 2.5+)
if RUBY_VERSION >= "2.5.0"
spec.add_development_dependency "sqlite3", "~> 1.4"
else
spec.add_development_dependency "sqlite3", "~> 1.3.0"
end
# pg version constraint for older Ruby versions
if RUBY_VERSION >= "2.5.0"
spec.add_development_dependency "pg", "< 2.0"
elsif RUBY_VERSION >= "2.4.0"
spec.add_development_dependency "pg", "~> 1.0"
else
# Ruby 2.2-2.3 need older pg version to avoid segfaults
spec.add_development_dependency "pg", "~> 0.21.0"
end
end
end
4 changes: 2 additions & 2 deletions lib/leafy/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def self.version

module VERSION
MAJOR = 0
MINOR = 1
TINY = 1
MINOR = 2
TINY = 0
PRE = nil

STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
Expand Down
6 changes: 3 additions & 3 deletions spec/leafy/mixin/active_record/fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class FieldsHost < ActiveRecord::Base
end

after do
Object.send(:remove_const, 'SchemaHost')
Object.send(:remove_const, 'FieldsHost')
Object.send(:remove_const, 'SchemaHost') if Object.const_defined?('SchemaHost')
Object.send(:remove_const, 'FieldsHost') if Object.const_defined?('FieldsHost')
end


Expand Down Expand Up @@ -161,7 +161,7 @@ class FieldsHost < ActiveRecord::Base

context 'pg json/jsonb' do
before do
pool = ActiveRecord::Base.establish_connection(adapter: 'postgresql', host: '127.0.0.1', port: '5432', user: 'root', password: '111')
pool = ActiveRecord::Base.establish_connection(adapter: 'postgresql', host: '127.0.0.1', port: '5432', database: 'postgres', user: 'root', password: '111')
pool.with_connection do |conn|

conn.create_table(:schema_hosts, force: true) do |t|
Expand Down
2 changes: 1 addition & 1 deletion spec/leafy/mixin/active_record/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

context 'pg json/jsonb' do
before do
pool = ActiveRecord::Base.establish_connection(adapter: 'postgresql', host: '127.0.0.1', port: '5432', user: 'root', password: '111')
pool = ActiveRecord::Base.establish_connection(adapter: 'postgresql', host: '127.0.0.1', port: '5432', database: 'postgres', user: 'root', password: '111')
pool.with_connection do |conn|
conn.create_table(:schema_hosts, force: true) do |t|
t.jsonb :leafy_data
Expand Down
2 changes: 1 addition & 1 deletion spec/leafy/mixin/poro/fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def leafy_fields
end

after do
Object.send(:remove_const, "FieldsHost")
Object.send(:remove_const, "FieldsHost") if Object.const_defined?("FieldsHost")
end

let(:instance) { FieldsHost.new }
Expand Down
29 changes: 28 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# frozen_string_literal: true

# Ruby 2.5+ compatibility: logger needed by ActiveRecord 6.0+
if RUBY_VERSION >= "2.5.0"
require 'logger'
end

# Ruby 3.0+ compatibility: require bundled gems that are needed by dependencies
if RUBY_VERSION >= "3.0.0"
require 'mutex_m'
require 'base64'
require 'benchmark' # Needed by ActiveSupport in Ruby 3.3+/4.x
end

# Ruby 3.1+ additional bundled gems
if RUBY_VERSION >= "3.1.0"
require 'csv'
end

# Ruby 3.4+ additional bundled gems
if RUBY_VERSION >= "3.4.0"
require 'erb'
require 'bigdecimal'
require 'drb'
end

require "bundler/setup"
require "leafy"

Expand All @@ -8,7 +32,10 @@
RSpec.configure do |config|
if !!ENV['COVERAGE']
require 'simplecov'
SimpleCov.start
SimpleCov.start do
add_filter '/spec/'
add_filter '/vendor/'
end
end


Expand Down
Loading