ci-helper 0.2.2 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 770629db9e962c008f6abed96b6385e4678857c5da98782086978d09785691b9
4
- data.tar.gz: e3cc5ce56806745706527a916cf5cc6c0488111cf1eba4b5edc781da930a38cc
3
+ metadata.gz: 01b88f245129abe666d9e52f64a749f4f8a03cd831f2896cd76bb55447d6deac
4
+ data.tar.gz: c26bf42cfa1630fb7bc8926c187b4a4b19d7b16efdc584aeea087bcee8016bc0
5
5
  SHA512:
6
- metadata.gz: d2e061a61d6fbc3944501ccb1a62aac9a37935d570d05ddf65aa964e33d3b035f5267da5affe5f7ac1a0f976e5f3427f2bec55d976ec961a2d180a25a00d256c
7
- data.tar.gz: f88a6d6bcda60a37ee75385f9baf4eb254eae2c2e0facdc61b02d95ee2846866582e5deb042e367ae4e92496ef676e89e4158e54f995aa4303ddf0f395e3a2d7
6
+ metadata.gz: 93c3507199dacbd55ce9d2f3076117df7005f3bacee604c3a1fe14521f47b0194acf5fe5c778c5159221a3e0c856dfcfb062a200f49c2206147e550186cb5663
7
+ data.tar.gz: e3257ec1a7df016bbbe195a9ae9b9cde553745041995b8588999f6cab26ae01f53b0f9e278a5f0912bb559ffed0010d29b90d829036649b072f845ec24a9c513
@@ -13,6 +13,9 @@ on:
13
13
  pull_request:
14
14
  branches: [ master ]
15
15
 
16
+ env:
17
+ FULL_COVERAGE_CHECK: true
18
+
16
19
  jobs:
17
20
  test-latest:
18
21
 
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,21 @@ 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
+ Accepted flags: `--split-resultset`, `--setup-file-path`.
67
+ * `--split-resultset` — if you execute command `RunSpecs` with `--split-resultset true`,
68
+ you also should set this flag to `true`. If this flag set to `true`, final coverage will be
69
+ calculated by merging results in all files, matching the mask `coverage/resultset.*.json`.
70
+ By default final coverage is calculated using result from `coverage/.resultset.json`.
71
+ * `--setup-file-path` — relative path to your `.rb` file, which setups `SimpleCov`.
72
+ Usually it is `spec_helper.rb`.
73
+
74
+ ### Rake Tasks
75
+
76
+ As you can see, some commands use generic rake tasks. To make tasks available in your application,
77
+ you need to require the file `ci_helper/railtie`. Also, you can require it directly in `Gemfile`:
78
+ `gem "ci-helper", require: "ci_helper/railtie, group: :test`.
79
+ Or if you haven't set `require` option to `false`, rake tasks loads automatically.
64
80
 
65
81
  ### Script
66
82
 
@@ -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,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+
5
+ module CIHelper
6
+ module Commands
7
+ class CheckCoverage < BaseCommand
8
+ def call
9
+ require(path.join(setup_file_path)) unless setup_file_path.nil?
10
+
11
+ ::SimpleCov.collate(files)
12
+ 0
13
+ end
14
+
15
+ private
16
+
17
+ def files
18
+ return path.glob("coverage/resultset.*.json") if split_resultset?
19
+
20
+ [path.join("coverage/.resultset.json")]
21
+ end
22
+
23
+ def split_resultset?
24
+ options[:split_resultset] == "true"
25
+ end
26
+
27
+ def setup_file_path
28
+ options[:setup_file_path]
29
+ end
30
+ end
31
+ end
32
+ 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.2"
4
+ VERSION = "0.3.2"
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.2
4
+ version: 0.3.2
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-24 00:00:00.000000000 Z
11
+ date: 2020-10-16 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
@@ -1,104 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ci-helper (0.2.2)
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