ci-helper 0.8.0 → 0.10.0

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: 6752c279e742404a6b104c4d4e2bccfaf4c18e17cfb0c6693ce1ddb0ce2b58e1
4
- data.tar.gz: 4e9960ccc6a0f0bd7b1ecf65a4c6df063cf579cdc71338dddb90248065368332
3
+ metadata.gz: 00bf40738c9997e76bf3f9c7339d1608e7bd706d7a93d4f00322f4f5b5336d4d
4
+ data.tar.gz: 6612126f35b0440904ffdada78380edff042b062009d7f51b17df0797c72ee59
5
5
  SHA512:
6
- metadata.gz: 3d8da6805297e53be7955d7219289dbece6f2decacdf760b81061e5745c4066a458b8b23ffa64cf06691ac270b00d58259941523e39ed919d056acc28aff0a85
7
- data.tar.gz: 97b48c63728b3ef1c3a3457a1b5c90e4f2954d250783db38eed9ae6414aeb177cacfca9038d9d46226f6c307f0439a608c38e9bee83ec5999f93d39ba8a2a141
6
+ metadata.gz: 5b0404a8c11b9dc5326654f672befed4bf0ed24d898789013b7eb00c7726b1f28f5e0aa9101cd6d0492426bcbcb79266e76064962184d873733ac392e8eec9be
7
+ data.tar.gz: c64d2b1b049753074b1fe5aae027c928c30e428f4c1f9b9022385568566a2ddb24be0445f5a3e20f713533ed098f6a2efe139eb06c7dd52825cab2a47e532591
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ci-helper (0.8.0)
4
+ ci-helper (0.10.0)
5
5
  colorize (~> 1.1)
6
6
  dry-inflector (~> 1.0)
7
7
  umbrellio-sequel-plugins (~> 0.14)
@@ -9,119 +9,139 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.1.2)
12
+ activesupport (8.1.3)
13
13
  base64
14
14
  bigdecimal
15
- concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ concurrent-ruby (~> 1.0, >= 1.3.1)
16
16
  connection_pool (>= 2.2.5)
17
17
  drb
18
18
  i18n (>= 1.6, < 2)
19
+ json
20
+ logger (>= 1.4.2)
19
21
  minitest (>= 5.1)
20
- mutex_m
21
- tzinfo (~> 2.0)
22
- ast (2.4.2)
23
- base64 (0.2.0)
24
- benchmark (0.4.1)
25
- bigdecimal (3.1.4)
26
- bundler-audit (0.9.1)
27
- bundler (>= 1.2.0, < 3)
22
+ securerandom (>= 0.3)
23
+ tzinfo (~> 2.0, >= 2.0.5)
24
+ uri (>= 0.13.1)
25
+ ast (2.4.3)
26
+ base64 (0.3.0)
27
+ benchmark (0.5.0)
28
+ bigdecimal (4.1.2)
29
+ bundler-audit (0.9.3)
30
+ bundler (>= 1.2.0)
28
31
  thor (~> 1.0)
29
32
  coderay (1.1.3)
30
33
  colorize (1.1.0)
31
- concurrent-ruby (1.2.2)
32
- connection_pool (2.4.1)
33
- diff-lcs (1.5.0)
34
- docile (1.4.0)
35
- drb (2.2.0)
36
- ruby2_keywords
37
- dry-inflector (1.0.0)
38
- i18n (1.14.1)
34
+ concurrent-ruby (1.3.6)
35
+ connection_pool (3.0.2)
36
+ diff-lcs (1.6.2)
37
+ docile (1.4.1)
38
+ drb (2.2.3)
39
+ dry-inflector (1.3.1)
40
+ i18n (1.14.8)
39
41
  concurrent-ruby (~> 1.0)
40
- json (2.7.1)
41
- method_source (1.0.0)
42
- minitest (5.20.0)
43
- mutex_m (0.2.0)
42
+ io-console (0.8.2)
43
+ json (2.19.4)
44
+ language_server-protocol (3.17.0.5)
45
+ lint_roller (1.1.0)
46
+ logger (1.7.0)
47
+ method_source (1.1.0)
48
+ minitest (6.0.5)
49
+ drb (~> 2.0)
50
+ prism (~> 1.5)
44
51
  ostruct (0.6.3)
45
- parallel (1.23.0)
46
- parser (3.2.2.4)
52
+ parallel (1.28.0)
53
+ parser (3.3.11.1)
47
54
  ast (~> 2.4.1)
48
55
  racc
49
- pry (0.14.2)
56
+ prism (1.9.0)
57
+ pry (0.16.0)
50
58
  coderay (~> 1.1)
51
59
  method_source (~> 1.0)
52
- racc (1.7.3)
53
- rack (3.0.8)
60
+ reline (>= 0.6.0)
61
+ racc (1.8.1)
62
+ rack (3.2.6)
54
63
  rainbow (3.1.1)
55
- rake (13.1.0)
56
- regexp_parser (2.8.3)
57
- rexml (3.2.6)
58
- rspec (3.12.0)
59
- rspec-core (~> 3.12.0)
60
- rspec-expectations (~> 3.12.0)
61
- rspec-mocks (~> 3.12.0)
62
- rspec-core (3.12.2)
63
- rspec-support (~> 3.12.0)
64
- rspec-expectations (3.12.3)
64
+ rake (13.4.2)
65
+ regexp_parser (2.12.0)
66
+ reline (0.6.3)
67
+ io-console (~> 0.5)
68
+ rspec (3.13.2)
69
+ rspec-core (~> 3.13.0)
70
+ rspec-expectations (~> 3.13.0)
71
+ rspec-mocks (~> 3.13.0)
72
+ rspec-core (3.13.6)
73
+ rspec-support (~> 3.13.0)
74
+ rspec-expectations (3.13.5)
65
75
  diff-lcs (>= 1.2.0, < 2.0)
66
- rspec-support (~> 3.12.0)
67
- rspec-mocks (3.12.6)
76
+ rspec-support (~> 3.13.0)
77
+ rspec-mocks (3.13.8)
68
78
  diff-lcs (>= 1.2.0, < 2.0)
69
- rspec-support (~> 3.12.0)
70
- rspec-support (3.12.1)
71
- rubocop (1.50.2)
79
+ rspec-support (~> 3.13.0)
80
+ rspec-support (3.13.7)
81
+ rubocop (1.84.2)
72
82
  json (~> 2.3)
83
+ language_server-protocol (~> 3.17.0.2)
84
+ lint_roller (~> 1.1.0)
73
85
  parallel (~> 1.10)
74
- parser (>= 3.2.0.0)
86
+ parser (>= 3.3.0.2)
75
87
  rainbow (>= 2.2.2, < 4.0)
76
- regexp_parser (>= 1.8, < 3.0)
77
- rexml (>= 3.2.5, < 4.0)
78
- rubocop-ast (>= 1.28.0, < 2.0)
88
+ regexp_parser (>= 2.9.3, < 3.0)
89
+ rubocop-ast (>= 1.49.0, < 2.0)
79
90
  ruby-progressbar (~> 1.7)
80
- unicode-display_width (>= 2.4.0, < 3.0)
81
- rubocop-ast (1.30.0)
82
- parser (>= 3.2.1.0)
83
- rubocop-capybara (2.19.0)
84
- rubocop (~> 1.41)
85
- rubocop-config-umbrellio (1.50.0.85)
86
- rubocop (~> 1.50.0)
87
- rubocop-performance (~> 1.17.0)
88
- rubocop-rails (~> 2.19.0)
89
- rubocop-rake (~> 0.6.0)
90
- rubocop-rspec (~> 2.20.0)
91
- rubocop-sequel (~> 0.3.3)
92
- rubocop-performance (1.17.1)
93
- rubocop (>= 1.7.0, < 2.0)
94
- rubocop-ast (>= 0.4.0)
95
- rubocop-rails (2.19.1)
91
+ unicode-display_width (>= 2.4.0, < 4.0)
92
+ rubocop-ast (1.49.1)
93
+ parser (>= 3.3.7.2)
94
+ prism (~> 1.7)
95
+ rubocop-config-umbrellio (1.84.118)
96
+ rubocop (~> 1.84.0)
97
+ rubocop-factory_bot (~> 2.28.0)
98
+ rubocop-performance (~> 1.26.0)
99
+ rubocop-rails (~> 2.34.0)
100
+ rubocop-rake (~> 0.7.0)
101
+ rubocop-rspec (~> 3.9.0)
102
+ rubocop-sequel (~> 0.4.0)
103
+ rubocop-factory_bot (2.28.0)
104
+ lint_roller (~> 1.1)
105
+ rubocop (~> 1.72, >= 1.72.1)
106
+ rubocop-performance (1.26.1)
107
+ lint_roller (~> 1.1)
108
+ rubocop (>= 1.75.0, < 2.0)
109
+ rubocop-ast (>= 1.47.1, < 2.0)
110
+ rubocop-rails (2.34.3)
96
111
  activesupport (>= 4.2.0)
112
+ lint_roller (~> 1.1)
97
113
  rack (>= 1.1)
98
- rubocop (>= 1.33.0, < 2.0)
99
- rubocop-rake (0.6.0)
100
- rubocop (~> 1.0)
101
- rubocop-rspec (2.20.0)
102
- rubocop (~> 1.33)
103
- rubocop-capybara (~> 2.17)
104
- rubocop-sequel (0.3.4)
105
- rubocop (~> 1.0)
114
+ rubocop (>= 1.75.0, < 2.0)
115
+ rubocop-ast (>= 1.44.0, < 2.0)
116
+ rubocop-rake (0.7.1)
117
+ lint_roller (~> 1.1)
118
+ rubocop (>= 1.72.1)
119
+ rubocop-rspec (3.9.0)
120
+ lint_roller (~> 1.1)
121
+ rubocop (~> 1.81)
122
+ rubocop-sequel (0.4.1)
123
+ lint_roller (~> 1.1)
124
+ rubocop (>= 1.72.1, < 2)
106
125
  ruby-progressbar (1.13.0)
107
- ruby2_keywords (0.0.5)
108
- sequel (5.75.0)
126
+ securerandom (0.4.1)
127
+ sequel (5.103.0)
109
128
  bigdecimal
110
129
  simplecov (0.22.0)
111
130
  docile (~> 1.1)
112
131
  simplecov-html (~> 0.11)
113
132
  simplecov_json_formatter (~> 0.1)
114
- simplecov-html (0.12.3)
115
- simplecov-lcov (0.8.0)
133
+ simplecov-html (0.13.2)
134
+ simplecov-lcov (0.9.0)
116
135
  simplecov_json_formatter (0.1.4)
117
- symbiont-ruby (0.7.0)
118
- thor (1.3.0)
136
+ thor (1.5.0)
119
137
  tzinfo (2.0.6)
120
138
  concurrent-ruby (~> 1.0)
121
- umbrellio-sequel-plugins (0.14.0.189)
139
+ umbrellio-sequel-plugins (0.17.2)
122
140
  sequel
123
- symbiont-ruby
124
- unicode-display_width (2.5.0)
141
+ unicode-display_width (3.2.0)
142
+ unicode-emoji (~> 4.1)
143
+ unicode-emoji (4.2.0)
144
+ uri (1.1.1)
125
145
 
126
146
  PLATFORMS
127
147
  arm64-darwin
data/ci_helper.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_runtime_dependency "colorize", "~> 1.1"
28
- spec.add_runtime_dependency "dry-inflector", "~> 1.0"
29
- spec.add_runtime_dependency "umbrellio-sequel-plugins", "~> 0.14"
27
+ spec.add_dependency "colorize", "~> 1.1"
28
+ spec.add_dependency "dry-inflector", "~> 1.0"
29
+ spec.add_dependency "umbrellio-sequel-plugins", "~> 0.14"
30
30
  end
data/lib/ci-helper.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "./ci_helper"
3
+ require_relative "ci_helper"
@@ -21,7 +21,7 @@ module CIHelper
21
21
  end
22
22
 
23
23
  def split_resultset?
24
- boolean_option(:split_resultset)
24
+ boolean_option?(:split_resultset)
25
25
  end
26
26
 
27
27
  def setup_file_path
@@ -6,6 +6,8 @@ module CIHelper
6
6
  def call
7
7
  create_and_migrate_database!
8
8
  execute("bundle exec rake db:seed")
9
+ create_and_migrate_clickhouse_database! if with_clickhouse?
10
+ 0
9
11
  end
10
12
 
11
13
  private
@@ -13,6 +15,10 @@ module CIHelper
13
15
  def env
14
16
  :development
15
17
  end
18
+
19
+ def with_clickhouse?
20
+ boolean_option?(:with_clickhouse)
21
+ end
16
22
  end
17
23
  end
18
24
  end
@@ -7,6 +7,13 @@ module CIHelper
7
7
  create_and_migrate_database!
8
8
  execute_with_env("bundle exec rake db:rollback_new_migrations")
9
9
  execute_with_env("bundle exec rake db:migrate")
10
+
11
+ if with_clickhouse?
12
+ create_and_migrate_clickhouse_database!
13
+ execute_with_env("bundle exec rake ch:rollback_new_migrations")
14
+ execute_with_env("bundle exec rake ch:migrate")
15
+ end
16
+ 0
10
17
  end
11
18
 
12
19
  private
@@ -14,6 +21,10 @@ module CIHelper
14
21
  def env
15
22
  :test
16
23
  end
24
+
25
+ def with_clickhouse?
26
+ boolean_option?(:with_clickhouse)
27
+ end
17
28
  end
18
29
  end
19
30
  end
@@ -33,7 +33,7 @@ module CIHelper
33
33
  end
34
34
 
35
35
  def with_database?
36
- boolean_option(:with_database)
36
+ boolean_option?(:with_database)
37
37
  end
38
38
 
39
39
  def config
@@ -1,15 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "json"
4
+ require "tmpdir"
5
+
3
6
  module CIHelper
4
7
  module Commands
5
8
  class RunSpecs < BaseCommand
6
9
  def call
7
- files_to_run = job_files
8
- return if files_to_run.empty?
10
+ return if all_spec_files.empty?
9
11
 
10
12
  create_and_migrate_database! if with_database?
11
13
  create_and_migrate_clickhouse_database! if with_clickhouse?
12
- execute("bundle exec rspec #{Shellwords.join(files_to_run)}")
14
+
15
+ specs_to_run = job_count == 1 ? job_files : job_examples
16
+ return 0 if specs_to_run.empty?
17
+
18
+ execute("bundle exec rspec #{Shellwords.join(specs_to_run)}")
13
19
  return 0 unless split_resultset?
14
20
 
15
21
  execute("mv coverage/.resultset.json coverage/resultset.#{job_index}.json")
@@ -21,28 +27,47 @@ module CIHelper
21
27
  :test
22
28
  end
23
29
 
30
+ def all_spec_files
31
+ @all_spec_files ||= path.glob("spec/**/*_spec.rb")
32
+ end
33
+
24
34
  def job_files
25
- all_files = path.glob("spec/**/*_spec.rb")
35
+ heavy_files, std_files = all_spec_files.partition { |f| heavy?(relative(f)) }
36
+ sorted_std = std_files.map { |f| [f.size, relative(f)] }.sort.map(&:last)
37
+ distribute(sorted_std + heavy_files)
38
+ end
26
39
 
27
- heavy_files = []
28
- std_files = []
40
+ def job_examples
41
+ heavy, std = example_ids.partition do |id|
42
+ heavy?(id.split("[", 2).first.delete_prefix("./"))
43
+ end
44
+ distribute(std.sort + heavy.sort)
45
+ end
29
46
 
30
- all_files.each do |file|
31
- relative_path = file.relative_path_from(path).to_s
32
- if heavy_specs_paths.any? { |pattern| File.fnmatch?(pattern, relative_path) }
33
- heavy_files << file
34
- else
35
- std_files << file
36
- end
47
+ def example_ids
48
+ Dir.mktmpdir do |dir|
49
+ output_file = File.join(dir, "rspec_examples.json")
50
+ execute(
51
+ "bundle exec rspec --dry-run --format=json --out #{Shellwords.escape(output_file)}",
52
+ )
53
+ JSON.parse(File.read(output_file)).fetch("examples").map { |e| e.fetch("id") }
37
54
  end
55
+ end
38
56
 
39
- sorted_files =
40
- std_files.map { |x| [x.size, x.relative_path_from(path).to_s] }.sort.map(&:last)
41
- (sorted_files + heavy_files).reverse.select.with_index do |_file, index|
57
+ def distribute(items)
58
+ items.reverse.select.with_index do |_item, index|
42
59
  (index % job_count) == (job_index - 1)
43
60
  end
44
61
  end
45
62
 
63
+ def heavy?(relative_path)
64
+ heavy_specs_paths.any? { |pattern| File.fnmatch?(pattern, relative_path) }
65
+ end
66
+
67
+ def relative(file)
68
+ file.relative_path_from(path).to_s
69
+ end
70
+
46
71
  def heavy_specs_paths
47
72
  @heavy_specs_paths ||=
48
73
  begin
@@ -61,15 +86,15 @@ module CIHelper
61
86
  end
62
87
 
63
88
  def with_database?
64
- boolean_option(:with_database)
89
+ boolean_option?(:with_database)
65
90
  end
66
91
 
67
92
  def with_clickhouse?
68
- boolean_option(:with_clickhouse)
93
+ boolean_option?(:with_clickhouse)
69
94
  end
70
95
 
71
96
  def split_resultset?
72
- boolean_option(:split_resultset)
97
+ boolean_option?(:split_resultset)
73
98
  end
74
99
  end
75
100
  end
@@ -6,8 +6,8 @@ module CIHelper
6
6
 
7
7
  class BaseCommand
8
8
  class << self
9
- def call!(**options)
10
- new(**options).call
9
+ def call!(**)
10
+ new(**).call
11
11
  end
12
12
 
13
13
  # :nocov:
@@ -58,7 +58,7 @@ module CIHelper
58
58
  raise Error, message
59
59
  end
60
60
 
61
- def boolean_option(key)
61
+ def boolean_option?(key)
62
62
  options[key] == "true"
63
63
  end
64
64
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CIHelper
4
- VERSION = "0.8.0"
4
+ VERSION = "0.10.0"
5
5
  end
@@ -13,6 +13,7 @@ class SequelManagement
13
13
  self.logger = Logger.new($stdout)
14
14
 
15
15
  define_db_task!
16
+ define_ch_task!
16
17
  end
17
18
 
18
19
  private
@@ -23,6 +24,10 @@ class SequelManagement
23
24
  self.class::MIGRATIONS_PATH
24
25
  end
25
26
 
27
+ def ch_migrations_path
28
+ "db/migrate/clickhouse"
29
+ end
30
+
26
31
  def define_db_task!
27
32
  namespace :db do
28
33
  desc "Rollback all migrations, which doesn't exist in master branch"
@@ -47,6 +52,31 @@ class SequelManagement
47
52
  end
48
53
  end
49
54
 
55
+ def define_ch_task!
56
+ namespace :ch do
57
+ desc "Rollback all migrations, which doesn't exist in master branch"
58
+ task rollback_new_migrations: :environment do
59
+ abort "Shouldn't run in production mode!" if Rails.env.production?
60
+
61
+ logger.info "Begin rolling back new migrations"
62
+
63
+ git_command = "git ls-tree --name-only origin/master #{ch_migrations_path}/"
64
+ migration_files, error, status = Open3.capture3(git_command)
65
+ abort "Can't get list of migration files:\n#{error}" unless status.success?
66
+
67
+ original_migrations = migration_files.split.map { |path| File.basename(path) }
68
+ migrations_to_rollback = (ch_migrator.applied_migrations - original_migrations).sort.reverse
69
+
70
+ next if migrations_to_rollback.empty?
71
+
72
+ logger.info "Rolling back migrations:"
73
+ logger.info migrations_to_rollback.join("\n")
74
+
75
+ ch_rollback!(migrations_to_rollback)
76
+ end
77
+ end
78
+ end
79
+
50
80
  def git_command
51
81
  "git ls-tree --name-only origin/master #{migrations_path}/"
52
82
  end
@@ -58,6 +88,14 @@ class SequelManagement
58
88
  end
59
89
  end
60
90
 
91
+ def ch_migrator
92
+ @ch_migrator ||= begin
93
+ full_path = Rails.root.join(ch_migrations_path)
94
+ Sequel::TimestampMigrator.new(DB, full_path, allow_missing_migration_files: true,
95
+ table: "clickhouse_migrations")
96
+ end
97
+ end
98
+
61
99
  def rollback!(migrations)
62
100
  migrations.each do |migration|
63
101
  migrator.undo(migration.to_i)
@@ -69,6 +107,18 @@ class SequelManagement
69
107
  end
70
108
  end
71
109
  end
110
+
111
+ def ch_rollback!(migrations)
112
+ migrations.each do |migration|
113
+ ch_migrator.undo(migration.to_i)
114
+ rescue Sequel::Migrator::Error => error
115
+ if error.message.include?("does not exist in the filesystem")
116
+ logger.info error.message
117
+ else
118
+ raise error
119
+ end
120
+ end
121
+ end
72
122
  end
73
123
 
74
124
  SequelManagement.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JustAnotherDude
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubygems_version: 3.7.2
113
+ rubygems_version: 3.6.9
114
114
  specification_version: 4
115
115
  summary: Continuous Integration helpers for Ruby
116
116
  test_files: []