ci-helper 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16a693137d6056e1974c2a2d23200ef231fa4f47daf5089e7d864b4d5a000c8f
4
- data.tar.gz: bb295befcb67ffadbc7bee5aa27fd741aae1ceb086074eeefa31e954fc3a4b2a
3
+ metadata.gz: af54c4df4f96a962deb3ab2acbbbf2b189d1a14f945f1ad17501a196237babdc
4
+ data.tar.gz: 73211997e92fca4b8873e9e0e1c8dafc4f208cba7c41618500d136ec639c7e62
5
5
  SHA512:
6
- metadata.gz: 3b45bbdc2a858c9ed54f5f239cf901907fec77daf441c5df537cf2b733e9ce5ba4292c9b527ff67cb761e54163fc9dd0481413f112ea1742d285f9f2de5a3dad
7
- data.tar.gz: 4bc6630a050a3c37143cedcf22ca7c6328fc3603cca3d6f9a4d04b59d5c402c0648ccc72de7fa2a4d414d7aa0c93de612233c99a0b4424f516fc7a091388fd7c
6
+ metadata.gz: 3efa5ce49a800e019fa1a5b86f3d6d46132b91fb5eeb343d52f72a2052b5beec94ce8001e3c54edf180a2c7a45588217a464085aa4b191064106204f29ccf317
7
+ data.tar.gz: 6a91623e8a061aab27caa74e6f74a7dbf24a095ff821b5984fbd62672976f69dbf8615cf7772334e212e6052ee699cb538198efac70b2f31a6f00984fb59d46f
@@ -13,8 +13,11 @@ on:
13
13
  pull_request:
14
14
  branches: [ master ]
15
15
 
16
+ env:
17
+ FULL_COVERAGE_CHECK: true
18
+
16
19
  jobs:
17
- test:
20
+ test-latest:
18
21
 
19
22
  runs-on: ubuntu-latest
20
23
 
@@ -24,7 +27,7 @@ jobs:
24
27
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
28
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
29
  # uses: ruby/setup-ruby@v1
27
- uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
30
+ uses: ruby/setup-ruby@v1
28
31
  with:
29
32
  ruby-version: 2.7
30
33
  - name: Install dependencies
@@ -43,3 +46,39 @@ jobs:
43
46
  uses: coverallsapp/github-action@v1.1.1
44
47
  with:
45
48
  github-token: ${{ secrets.GITHUB_TOKEN }}
49
+ specs-for-26:
50
+ runs-on: ubuntu-latest
51
+
52
+ steps:
53
+ - uses: actions/checkout@v2
54
+ - name: Set up Ruby
55
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
56
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
57
+ # uses: ruby/setup-ruby@v1
58
+ uses: ruby/setup-ruby@v1
59
+ with:
60
+ ruby-version: 2.6
61
+ - name: Install dependencies
62
+ run: bundle install && gem install bundler-audit
63
+ - name: Build and install gem to systems gems
64
+ run: bundle exec rake install
65
+ - name: Run specs
66
+ run: ci-helper RunSpecs
67
+ specs-for-25:
68
+ runs-on: ubuntu-latest
69
+
70
+ steps:
71
+ - uses: actions/checkout@v2
72
+ - name: Set up Ruby
73
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
74
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
75
+ # uses: ruby/setup-ruby@v1
76
+ uses: ruby/setup-ruby@v1
77
+ with:
78
+ ruby-version: 2.5
79
+ - name: Install dependencies
80
+ run: bundle install && gem install bundler-audit
81
+ - name: Build and install gem to systems gems
82
+ run: bundle exec rake install
83
+ - name: Run specs
84
+ run: ci-helper RunSpecs
data/.gitignore CHANGED
@@ -6,3 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+
10
+ Gemfile.lock
@@ -10,3 +10,7 @@ Naming/MethodParameterName:
10
10
 
11
11
  RSpec/EmptyLineAfterHook:
12
12
  Enabled: false
13
+
14
+ Naming/FileName:
15
+ Exclude:
16
+ - lib/ci-helper.rb
data/README.md CHANGED
@@ -42,11 +42,12 @@ List of available commands:
42
42
  * **CheckDBDevelopment** — executes rails db commands (`db:drop`, `db:create`, `db:migrate`)
43
43
  and seeds database. Does not accept flags.
44
44
  * **CheckDBRollback** — executes rails db commands with additional command
45
- `db:rollback_new_migrations`, which rollbacks migrations,
46
- added in tested branch. Does not accept flags.
45
+ `db:rollback_new_migrations`, which rollbacks migrations, added in tested branch.
46
+ Does not accept flags. Gem provides this rake task, but only for `Sequel`.
47
+ If you want to use `ActiveRecord::Migrator`, you'll have to write rake task by your own.
47
48
  * **RubocopLint** — executes rubocop linter. Does not accept flags.
48
49
  * **RunSpecs** — executes `rspec` in project root.
49
- Accepted flags: `--node-index`, `node-total`, `with-database`, `split-resultset`.
50
+ Accepted flags: `--node-index`, `node-total`, `with-database`, `split-resultset`.
50
51
  * `--node-index` — if you run specs in parallel in CI, then you might use this flag.
51
52
  * `--node-total` — if you run specs in parallel in CI, then you might use this flag.
52
53
  * `--with-database` — if you want to prepare database before executing specs,
@@ -61,6 +62,20 @@ Accepted flags: `--node-index`, `node-total`, `with-database`, `split-resultset`
61
62
  delimited by coma.
62
63
  * `--ignored-paths [values]` - accepts path patterns that should be ignored,
63
64
  delimited by coma.
65
+ * **CheckCoverage** — checks coverage by executing `SimpleCov::collate`.
66
+ You should set `SimpleCov::minimum_coverage` in your `spec_helper.rb` file.
67
+ Accepted flags: `--split-resultset`.
68
+ * `--split-resultset` — if you execute command `RunSpecs` with `--split-resultset true`,
69
+ you also should set this flag to `true`. If this flag set to `true`, final coverage will be
70
+ calculated by merging results in all files, matching the mask `coverage/resultset.*.json`.
71
+ By default final coverage is calculated using result from `coverage/.resultset.json`.
72
+
73
+ ### Rake Tasks
74
+
75
+ As you can see, some commands use generic rake tasks. To make tasks available in your application,
76
+ you need to require the file `ci_helper/railtie`. Also, you can require it directly in `Gemfile`:
77
+ `gem "ci-helper", require: "ci_helper/railtie, group: :test`.
78
+ Or if you haven't set `require` option to `false`, rake tasks loads automatically.
64
79
 
65
80
  ### Script
66
81
 
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "CIHelper is a gem with Continuous Integration helpers for Ruby"
13
13
  spec.homepage = "https://github.com/umbrellio/ci_helper"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/umbrellio/ci_helper"
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_runtime_dependency "colorize", "~> 0.8"
28
28
  spec.add_runtime_dependency "dry-inflector", "~> 0.2"
29
+ spec.add_runtime_dependency "umbrellio-sequel-plugins", "~> 0.4"
29
30
 
30
31
  spec.add_development_dependency "bundler"
31
32
  spec.add_development_dependency "bundler-audit"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./ci_helper"
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module CIHelper
4
+ end
5
+
3
6
  require "colorized_string"
4
7
  require "delegate"
5
8
  require "dry/inflector"
@@ -14,5 +17,6 @@ require "ci_helper/tools/colorize"
14
17
  require "ci_helper/tools/inflector"
15
18
  require "ci_helper/version"
16
19
 
17
- module CIHelper
18
- end
20
+ # :nocov:
21
+ require "ci_helper/railtie" if defined?(Rails)
22
+ # :nocov:
@@ -12,7 +12,7 @@ module CIHelper
12
12
 
13
13
  # :nocov:
14
14
  def process_stdout
15
- @process_stdout ||= STDOUT
15
+ @process_stdout ||= $stdout
16
16
  end
17
17
  # :nocov:
18
18
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CIHelper
4
+ module Commands
5
+ class CheckCoverage < BaseCommand
6
+ def call
7
+ SimpleCov.collate(files)
8
+ 0
9
+ end
10
+
11
+ private
12
+
13
+ def files
14
+ return path.glob("coverage/resultset.*.json") if split_resultset?
15
+
16
+ [path.join("coverage/.resultset.json")]
17
+ end
18
+
19
+ def split_resultset?
20
+ options[:split_resultset] == "true"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CIHelper
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load "tasks/sequel_management.rake"
7
+ end
8
+ end
9
+ end
@@ -5,9 +5,11 @@ module CIHelper
5
5
  class Inflector < Delegator
6
6
  include Singleton
7
7
 
8
+ # rubocop:disable Lint/MissingSuper
8
9
  def initialize
9
10
  @inflector = Dry::Inflector.new { |inflections| inflections.acronym "DB" }
10
11
  end
12
+ # rubocop:enable Lint/MissingSuper
11
13
 
12
14
  def __getobj__
13
15
  @inflector
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CIHelper
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "logger"
4
+ require "sequel/timestamp_migrator_undo_extension"
5
+
6
+ class SequelManagement
7
+ include Rake::DSL
8
+
9
+ MIGRATIONS_PATH = "db/migrate"
10
+
11
+ def initialize
12
+ self.logger = Logger.new($stdout)
13
+
14
+ define_db_task!
15
+ end
16
+
17
+ private
18
+
19
+ attr_accessor :logger
20
+
21
+ def migrations_path
22
+ self.class::MIGRATIONS_PATH
23
+ end
24
+
25
+ def define_db_task!
26
+ namespace :db do
27
+ desc "Rollback all migrations, which doesn't exist in master branch"
28
+ task rollback_new_migrations: :environment do
29
+ abort "Shouldn't run in production mode!" if Rails.env.production?
30
+
31
+ logger.info "Begin rolling back new migrations"
32
+
33
+ original_migrations = `#{git_command}`.split.map { |path| File.basename(path) }
34
+ migrations_to_rollback = (migrator.applied_migrations - original_migrations).sort.reverse
35
+
36
+ next if migrations_to_rollback.empty?
37
+
38
+ logger.info "Rolling back migrations:"
39
+ logger.info migrations_to_rollback.join("\n")
40
+
41
+ rollback!(migrations_to_rollback)
42
+ end
43
+ end
44
+ end
45
+
46
+ def git_command
47
+ "git ls-tree --name-only origin/master #{migrations_path}/"
48
+ end
49
+
50
+ def migrator
51
+ @migrator ||= begin
52
+ full_path = Rails.root.join(migrations_path)
53
+ Sequel::TimestampMigrator.new(DB, full_path, allow_missing_migration_files: true)
54
+ end
55
+ end
56
+
57
+ def rollback!(migrations)
58
+ migrations.each do |migration|
59
+ migrator.undo(migration.to_i)
60
+ rescue Sequel::Migrator::Error => error
61
+ if error.message.include?("does not exist in the filesystem")
62
+ logger.info error.message
63
+ else
64
+ raise error
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ SequelManagement.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JustAnotherDude
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-07 00:00:00.000000000 Z
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: umbrellio-sequel-plugins
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +178,6 @@ files:
164
178
  - ".rspec"
165
179
  - ".rubocop.yml"
166
180
  - Gemfile
167
- - Gemfile.lock
168
181
  - LICENSE.txt
169
182
  - README.md
170
183
  - Rakefile
@@ -172,18 +185,22 @@ files:
172
185
  - bin/setup
173
186
  - ci_helper.gemspec
174
187
  - exe/ci-helper
188
+ - lib/ci-helper.rb
175
189
  - lib/ci_helper.rb
176
190
  - lib/ci_helper/cli.rb
177
191
  - lib/ci_helper/commands.rb
178
192
  - lib/ci_helper/commands/bundler_audit.rb
193
+ - lib/ci_helper/commands/check_coverage.rb
179
194
  - lib/ci_helper/commands/check_db_development.rb
180
195
  - lib/ci_helper/commands/check_db_rollback.rb
181
196
  - lib/ci_helper/commands/check_spec_suffixes.rb
182
197
  - lib/ci_helper/commands/rubocop_lint.rb
183
198
  - lib/ci_helper/commands/run_specs.rb
199
+ - lib/ci_helper/railtie.rb
184
200
  - lib/ci_helper/tools/colorize.rb
185
201
  - lib/ci_helper/tools/inflector.rb
186
202
  - lib/ci_helper/version.rb
203
+ - lib/tasks/sequel_management.rake
187
204
  homepage: https://github.com/umbrellio/ci_helper
188
205
  licenses:
189
206
  - MIT
@@ -198,14 +215,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
215
  requirements:
199
216
  - - ">="
200
217
  - !ruby/object:Gem::Version
201
- version: 2.7.0
218
+ version: 2.5.0
202
219
  required_rubygems_version: !ruby/object:Gem::Requirement
203
220
  requirements:
204
221
  - - ">="
205
222
  - !ruby/object:Gem::Version
206
223
  version: '0'
207
224
  requirements: []
208
- rubygems_version: 3.1.3
225
+ rubygems_version: 3.1.4
209
226
  signing_key:
210
227
  specification_version: 4
211
228
  summary: Continuous Integration helpers for Ruby
@@ -1,104 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ci-helper (0.2.0)
5
- colorize (~> 0.8)
6
- dry-inflector (~> 0.2)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (6.0.3.1)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- zeitwerk (~> 2.2, >= 2.2.2)
17
- ast (2.4.1)
18
- bundler-audit (0.7.0.1)
19
- bundler (>= 1.2.0, < 3)
20
- thor (>= 0.18, < 2)
21
- coderay (1.1.3)
22
- colorize (0.8.1)
23
- concurrent-ruby (1.1.6)
24
- diff-lcs (1.3)
25
- docile (1.3.2)
26
- dry-inflector (0.2.0)
27
- i18n (1.8.3)
28
- concurrent-ruby (~> 1.0)
29
- jaro_winkler (1.5.4)
30
- method_source (1.0.0)
31
- minitest (5.14.1)
32
- parallel (1.19.2)
33
- parser (2.7.1.3)
34
- ast (~> 2.4.0)
35
- pry (0.13.1)
36
- coderay (~> 1.1)
37
- method_source (~> 1.0)
38
- rack (2.2.3)
39
- rainbow (3.0.0)
40
- rake (13.0.1)
41
- rexml (3.2.4)
42
- rspec (3.9.0)
43
- rspec-core (~> 3.9.0)
44
- rspec-expectations (~> 3.9.0)
45
- rspec-mocks (~> 3.9.0)
46
- rspec-core (3.9.2)
47
- rspec-support (~> 3.9.3)
48
- rspec-expectations (3.9.2)
49
- diff-lcs (>= 1.2.0, < 2.0)
50
- rspec-support (~> 3.9.0)
51
- rspec-mocks (3.9.1)
52
- diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.9.0)
54
- rspec-support (3.9.3)
55
- rubocop (0.81.0)
56
- jaro_winkler (~> 1.5.1)
57
- parallel (~> 1.10)
58
- parser (>= 2.7.0.1)
59
- rainbow (>= 2.2.2, < 4.0)
60
- rexml
61
- ruby-progressbar (~> 1.7)
62
- unicode-display_width (>= 1.4.0, < 2.0)
63
- rubocop-config-umbrellio (0.81.0.78)
64
- rubocop (= 0.81.0)
65
- rubocop-performance (= 1.5.2)
66
- rubocop-rails (= 2.5.0)
67
- rubocop-rspec (= 1.38.1)
68
- rubocop-performance (1.5.2)
69
- rubocop (>= 0.71.0)
70
- rubocop-rails (2.5.0)
71
- activesupport
72
- rack (>= 1.1)
73
- rubocop (>= 0.72.0)
74
- rubocop-rspec (1.38.1)
75
- rubocop (>= 0.68.1)
76
- ruby-progressbar (1.10.1)
77
- simplecov (0.18.5)
78
- docile (~> 1.1)
79
- simplecov-html (~> 0.11)
80
- simplecov-html (0.12.2)
81
- simplecov-lcov (0.8.0)
82
- thor (1.0.1)
83
- thread_safe (0.3.6)
84
- tzinfo (1.2.7)
85
- thread_safe (~> 0.1)
86
- unicode-display_width (1.7.0)
87
- zeitwerk (2.3.0)
88
-
89
- PLATFORMS
90
- ruby
91
-
92
- DEPENDENCIES
93
- bundler
94
- bundler-audit
95
- ci-helper!
96
- pry
97
- rake
98
- rspec
99
- rubocop-config-umbrellio
100
- simplecov
101
- simplecov-lcov
102
-
103
- BUNDLED WITH
104
- 2.1.4