Skip to content
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

Switch from travis to Github actions #27

Merged
merged 3 commits into from
Apr 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI PR Builds

on:
push:
branches:
- master
pull_request:

concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby-version: ['2.5', '2.6', '2.7', '3.0']
steps:
- uses: actions/checkout@v2

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

- name: 'Run bundle update'
run: bundle update

- name: Run tests
run: bundle exec rake spec

- name: Coveralls Parallel
uses: coverallsapp/github-action@master
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best practice I've seen recommended is to pin a specific version/SHA and use dependabot for upgrading the pinned dependency. Not sure how we want to do it here, though -- this potentially has an impact on the action we generate as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a relatively simple command and maintained by the coveralls devs. yeah ideally they should have an @v1 branch but alas they do not. My concern of locking it to a specific hash is if they change something for their infrastructure it'll break anyways..

Anyways.. @ashkulz re-review this branch again though as I finally got "everything" working with GH actions (including all the DB testing used by the other gems)

Next-up is adding in rails 7.0 (since they have RC1 out)

with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.ruby-version }}
parallel: true
finish:
needs: 'test'
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
18 changes: 18 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SimpleCov.configure do
enable_coverage :branch
add_filter '/spec/'

add_group 'Binaries', '/bin/'
add_group 'Libraries', '/lib/'

if ENV['CI']
require 'simplecov-lcov'

SimpleCov::Formatter::LcovFormatter.config do |c|
c.report_with_single_file = true
c.single_report_path = 'coverage/lcov.info'
end

formatter SimpleCov::Formatter::LcovFormatter
end
end
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# SchemaDev

[![Gem Version](https://badge.fury.io/rb/schema_dev.svg)](http://badge.fury.io/rb/schema_dev)
[![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_dev.svg)](http://travis-ci.org/SchemaPlus/schema_dev)
[![Build Status](https://github.com/SchemaPlus/schema_dev/actions/workflows/prs.yml/badge.svg)](https://github.com/SchemaPlus/schema_dev/actions)
[![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_dev.svg)](https://coveralls.io/r/SchemaPlus/schema_dev)
[![Dependency Status](https://gemnasium.com/SchemaPlus/schema_dev.svg)](https://gemnasium.com/SchemaPlus/schema_dev)

Development tools for the SchemaPlus family of gems.

Provides support for working with multiple ruby versions, ActiveRecord, and db versions. In particular provides a command `schema_dev` for running rspec (or whatever) on the matrix or a slice or element of it. It also auto-generates the `.travis.yml` file for [travis-ci](https://travis-ci.org) testing.
Provides support for working with multiple ruby versions, ActiveRecord, and db versions. In particular provides a command `schema_dev` for running rspec (or whatever) on the matrix or a slice or element of it. It also auto-generates the `.github/workflows/prs.yml` file for [github actions](https://docs.github.com/en/actions) testing.

## Creating a new gem for the SchemaPlus family

Expand Down Expand Up @@ -99,9 +98,9 @@ Note that freshening the gemfiles happens automatically whenever you run a schem

If you need to include extra specifications in the Gemfile (e.g. to specify a path for a gem), you can create a file `Gemfile.local` in the project root, and its contents will be included in the Gemfile.

### .travis.yml
### .github/workflows/prs.yml

The `.travis.yml` file gets created automatically. Don't edit it by hand.
The `.github/workflows/prs.yml` file gets created automatically. Don't edit it by hand.

### README.md

Expand Down Expand Up @@ -131,9 +130,9 @@ The client gem's `Rakefile` includes:

require 'schema_dev/tasks'

Which defines the rake task `create_databases` and also a task for travis-ci
Which defines the rake task `create_databases` and also a task for github actions

## Relase Notes
## Release Notes

Release notes for schema_dev versions:

Expand Down
4 changes: 0 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@ require "bundler/gem_tasks"

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

require 'coveralls/rake/task'
Coveralls::RakeTask.new
task :travis => [:spec, 'coveralls:push']
2 changes: 1 addition & 1 deletion bin/schema_dev
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CLI < Thor
method_option :db, type: :string, desc: "Only execute for the specified database"
end

desc "freshen", "update files that depend on schema_dev.yml: .travis, gemfiles/, README.md"
desc "freshen", "update files that depend on schema_dev.yml: .github/worksflows/prs.yml, gemfiles/, README.md"
def freshen
runner.freshen
end
Expand Down
49 changes: 35 additions & 14 deletions lib/schema_dev/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,57 @@
require 'enumerator'
require 'pathname'
require 'yaml'
require 'rubygems/version'

module SchemaDev
CONFIG_FILE = "schema_dev.yml"

class Config

attr_accessor :quick, :db, :dbversions, :ruby, :activerecord, :notify, :exclude
attr_accessor :quick, :db, :dbversions, :ruby, :activerecord, :exclude

def self._reset ; @@config = nil end # for use by rspec
def self._reset ; @config = nil end # for use by rspec

def self.read
new(**(YAML.load Pathname.new(CONFIG_FILE).read).symbolize_keys)
end

def self.load
@@config ||= read
@config ||= read
end

def initialize(ruby:, activerecord:, db:, dbversions: nil, exclude: nil, notify: nil, quick: nil)
@ruby = Array.wrap(ruby)
@activerecord = Array.wrap(activerecord)
@ruby = Array.wrap(ruby).map(&:to_s)
@activerecord = Array.wrap(activerecord).map(&:to_s)
@db = Array.wrap(db)
@dbversions = (dbversions || {}).symbolize_keys
@exclude = Array.wrap(exclude).map(&:symbolize_keys).map {|tuple| Tuple.new(**tuple)}
@notify = Array.wrap(notify)
@exclude = Array.wrap(exclude).map(&:symbolize_keys).map {|tuple| Tuple.new(**tuple.transform_values(&:to_s))}
if @activerecord.include?('5.2')
ruby3 = ::Gem::Version.new('3.0')

@ruby.select { |e| ::Gem::Version.new(e) >= ruby3 }.each do |v|
@exclude << Tuple.new(ruby: v, activerecord: '5.2')
end
end
unless notify.nil?
warn "Notify is no longer supported"
end
@quick = Array.wrap(quick || {ruby: @ruby.last, activerecord: @activerecord.last, db: @db.last})
end

def dbms
@dbms ||= [:postgresql, :mysql].select{|dbm| @db.grep(/^#{dbm}/).any?}
end

def dbms_versions_for(db, default = [])
@dbversions.fetch(db, default)
DB_VERSION_DEFAULTS = {
postgresql: ['9.6']
}

def db_versions_for(db)
@dbversions.fetch(db.to_sym, DB_VERSION_DEFAULTS.fetch(db.to_sym, [])).map(&:to_s)
end

def matrix(quick: false, ruby: nil, activerecord: nil, db: nil, excluded: nil)
def matrix(quick: false, ruby: nil, activerecord: nil, db: nil, excluded: nil, with_dbversion: false)
use_ruby = @ruby
use_activerecord = @activerecord
use_db = @db
Expand All @@ -56,22 +70,29 @@ def matrix(quick: false, ruby: nil, activerecord: nil, db: nil, excluded: nil)
use_db = [nil] unless use_db.any?

m = use_ruby.product(use_activerecord, use_db)
m = m.map { |_ruby, _activerecord, _db| Tuple.new(ruby: _ruby, activerecord: _activerecord, db: _db) }.compact
m = m.flat_map { |_ruby, _activerecord, _db|
if with_dbversion && !(dbversions = db_versions_for(_db)).empty?
dbversions.map { |v| Tuple.new(ruby: _ruby, activerecord: _activerecord, db: _db, dbversion: v) }
else
[Tuple.new(ruby: _ruby, activerecord: _activerecord, db: _db)]
end
}.compact
m = m.reject { |r| r.match_any?(@exclude) } unless excluded == :none
m = m.map(&:to_hash)

if excluded == :only
matrix(quick: quick, ruby: ruby, activerecord: activerecord, db: db, excluded: :none) - m
matrix(quick: quick, ruby: ruby, activerecord: activerecord, db: db, with_dbversion: with_dbversion, excluded: :none) - m
else
m
end
end

Tuple = Struct.new(:ruby, :activerecord, :db, keyword_init: true) do
Tuple = Struct.new(:ruby, :activerecord, :db, :dbversion, keyword_init: true) do
def match?(other)
return false if self.ruby and other.ruby and self.ruby != other.ruby
return false if self.activerecord and other.activerecord and self.activerecord != other.activerecord
return false if self.db and other.db and self.db != other.db
return false if self.dbversion and other.dbversion and self.dbversion != other.dbversion
true
end

Expand All @@ -80,7 +101,7 @@ def match_any?(others)
end

def to_hash
to_h.compact
to_h.compact.transform_values(&:to_s)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/schema_dev/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def copy_template

def rename_files
(gem_root + "gitignore").rename gem_root + ".gitignore"
(gem_root + "simplecov").rename gem_root + ".simplecov"
Dir.glob(gem_root + "**/*GEM_NAME*").each do |path|
FileUtils.mv path, path.gsub(/GEM_NAME/, gem_name)
end
Expand Down