Skip to content

Commit c2a1238

Browse files
committed
rework freshen to generate github actions scripts
- cleanup config to handle DB versions better - rewrite the "create_databases/drop_databases" to utilize AR's database tasks - update initial gem template
1 parent 4101477 commit c2a1238

19 files changed

Lines changed: 1205 additions & 618 deletions

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# SchemaDev
22

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

87
Development tools for the SchemaPlus family of gems.
98

10-
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.
9+
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.
1110

1211
## Creating a new gem for the SchemaPlus family
1312

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

10099
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.
101100

102-
### .travis.yml
101+
### .github/workflows/prs.yml
103102

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

106105
### README.md
107106

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

132131
require 'schema_dev/tasks'
133132

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

136-
## Relase Notes
135+
## Release Notes
137136

138137
Release notes for schema_dev versions:
139138

bin/schema_dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CLI < Thor
2424
method_option :db, type: :string, desc: "Only execute for the specified database"
2525
end
2626

27-
desc "freshen", "update files that depend on schema_dev.yml: .travis, gemfiles/, README.md"
27+
desc "freshen", "update files that depend on schema_dev.yml: .github/worksflows/prs.yml, gemfiles/, README.md"
2828
def freshen
2929
runner.freshen
3030
end

lib/schema_dev/config.rb

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,57 @@
22
require 'enumerator'
33
require 'pathname'
44
require 'yaml'
5+
require 'rubygems/version'
56

67
module SchemaDev
78
CONFIG_FILE = "schema_dev.yml"
89

910
class Config
1011

11-
attr_accessor :quick, :db, :dbversions, :ruby, :activerecord, :notify, :exclude
12+
attr_accessor :quick, :db, :dbversions, :ruby, :activerecord, :exclude
1213

13-
def self._reset ; @@config = nil end # for use by rspec
14+
def self._reset ; @config = nil end # for use by rspec
1415

1516
def self.read
1617
new(**(YAML.load Pathname.new(CONFIG_FILE).read).symbolize_keys)
1718
end
1819

1920
def self.load
20-
@@config ||= read
21+
@config ||= read
2122
end
2223

2324
def initialize(ruby:, activerecord:, db:, dbversions: nil, exclude: nil, notify: nil, quick: nil)
24-
@ruby = Array.wrap(ruby)
25-
@activerecord = Array.wrap(activerecord)
25+
@ruby = Array.wrap(ruby).map(&:to_s)
26+
@activerecord = Array.wrap(activerecord).map(&:to_s)
2627
@db = Array.wrap(db)
2728
@dbversions = (dbversions || {}).symbolize_keys
28-
@exclude = Array.wrap(exclude).map(&:symbolize_keys).map {|tuple| Tuple.new(**tuple)}
29-
@notify = Array.wrap(notify)
29+
@exclude = Array.wrap(exclude).map(&:symbolize_keys).map {|tuple| Tuple.new(**tuple.transform_values(&:to_s))}
30+
if @activerecord.include?('5.2')
31+
ruby3 = ::Gem::Version.new('3.0')
32+
33+
@ruby.select { |e| ::Gem::Version.new(e) >= ruby3 }.each do |v|
34+
@exclude << Tuple.new(ruby: v, activerecord: '5.2')
35+
end
36+
end
37+
unless notify.nil?
38+
warn "Notify is no longer supported"
39+
end
3040
@quick = Array.wrap(quick || {ruby: @ruby.last, activerecord: @activerecord.last, db: @db.last})
3141
end
3242

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

37-
def dbms_versions_for(db, default = [])
38-
@dbversions.fetch(db, default)
47+
DB_VERSION_DEFAULTS = {
48+
postgresql: ['9.6']
49+
}
50+
51+
def db_versions_for(db)
52+
@dbversions.fetch(db.to_sym, DB_VERSION_DEFAULTS.fetch(db.to_sym, [])).map(&:to_s)
3953
end
4054

41-
def matrix(quick: false, ruby: nil, activerecord: nil, db: nil, excluded: nil)
55+
def matrix(quick: false, ruby: nil, activerecord: nil, db: nil, excluded: nil, with_dbversion: false)
4256
use_ruby = @ruby
4357
use_activerecord = @activerecord
4458
use_db = @db
@@ -56,22 +70,29 @@ def matrix(quick: false, ruby: nil, activerecord: nil, db: nil, excluded: nil)
5670
use_db = [nil] unless use_db.any?
5771

5872
m = use_ruby.product(use_activerecord, use_db)
59-
m = m.map { |_ruby, _activerecord, _db| Tuple.new(ruby: _ruby, activerecord: _activerecord, db: _db) }.compact
73+
m = m.flat_map { |_ruby, _activerecord, _db|
74+
if with_dbversion && !(dbversions = db_versions_for(_db)).empty?
75+
dbversions.map { |v| Tuple.new(ruby: _ruby, activerecord: _activerecord, db: _db, dbversion: v) }
76+
else
77+
[Tuple.new(ruby: _ruby, activerecord: _activerecord, db: _db)]
78+
end
79+
}.compact
6080
m = m.reject { |r| r.match_any?(@exclude) } unless excluded == :none
6181
m = m.map(&:to_hash)
6282

6383
if excluded == :only
64-
matrix(quick: quick, ruby: ruby, activerecord: activerecord, db: db, excluded: :none) - m
84+
matrix(quick: quick, ruby: ruby, activerecord: activerecord, db: db, with_dbversion: with_dbversion, excluded: :none) - m
6585
else
6686
m
6787
end
6888
end
6989

70-
Tuple = Struct.new(:ruby, :activerecord, :db, keyword_init: true) do
90+
Tuple = Struct.new(:ruby, :activerecord, :db, :dbversion, keyword_init: true) do
7191
def match?(other)
7292
return false if self.ruby and other.ruby and self.ruby != other.ruby
7393
return false if self.activerecord and other.activerecord and self.activerecord != other.activerecord
7494
return false if self.db and other.db and self.db != other.db
95+
return false if self.dbversion and other.dbversion and self.dbversion != other.dbversion
7596
true
7697
end
7798

@@ -80,7 +101,7 @@ def match_any?(others)
80101
end
81102

82103
def to_hash
83-
to_h.compact
104+
to_h.compact.transform_values(&:to_s)
84105
end
85106
end
86107
end

lib/schema_dev/gem.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def copy_template
127127

128128
def rename_files
129129
(gem_root + "gitignore").rename gem_root + ".gitignore"
130+
(gem_root + "simplecov").rename gem_root + ".simplecov"
130131
Dir.glob(gem_root + "**/*GEM_NAME*").each do |path|
131132
FileUtils.mv path, path.gsub(/GEM_NAME/, gem_name)
132133
end

0 commit comments

Comments
 (0)