knapsack_pro 4.1.0 → 5.1.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: bf60d8383722268ee562e030a1012cf20544e072faf94017bf21e417782cc4a5
4
- data.tar.gz: 91f304357d4228bdfda1c43e3387681abfe56fcbf2e75f202df565cbff0f3ec0
3
+ metadata.gz: d4e0c8f7bd4c8bf4c50885cdbcbecf34222a3d1ab46d3be52d937d940a0ba5c0
4
+ data.tar.gz: b8a68e22c872686d20fc6fac50ec3d02bad449768da522eb36ed86db5d331dfc
5
5
  SHA512:
6
- metadata.gz: 533b1f156df0b779e1ebe476ed87a9f3811929ae4a4e271bb2d880f8deda2f0e23da41ae727d5c3d38a3828f50dce5ed99c10af5857d0abdb45a674f6a128bf2
7
- data.tar.gz: c3f1f95e7ed656c0347d09650f08b11f3a5987df3e31a54fb3b9cecc0113dd5c5e1181615803f8f938f1402b70ee3ca2649f6db5e64b135590e2e2d10c94b528
6
+ metadata.gz: 34d669379edb42f5a3e3eaf9075320bd1e2457ec48dfae86d94e2fa21eb4562d1fcc2db66ed49749ef78a641741d934e6d978bc9cc557d5985e49eb9bbed133d
7
+ data.tar.gz: bde90595bb3123c0c10b53d58de5b78637a2c30679f3ab5e37283735ce3a4f6bcbc19a39be7fcf691f6878f5be0018d16e3eb0bc8adc9f2d6f23827de72f0bb2
data/CHANGELOG.md CHANGED
@@ -1,16 +1,43 @@
1
- # Change Log
1
+ # Changelog
2
+
3
+ ### 5.1.0
4
+
5
+ * Mask user seats data instead of hashing it
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/202
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v5.0.0...v5.1.0
10
+
11
+
12
+ ### 5.0.0
13
+
14
+ * __(breaking change)__ Use `KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true` as default value in Queue Mode and use `false` for proper CI providers
15
+
16
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/198
17
+
18
+ * Detect CI from environment and get the correct ENVs instead of trying all of them and risk conflicts
19
+
20
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/201
21
+
22
+ * Set `RAILS_ENV=test` / `RACK_ENV=test` in Queue Mode
23
+
24
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/199
25
+
26
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v4.1.0...v5.0.0
2
27
 
3
28
  ### 4.1.0
4
29
 
5
30
  * Add support for CI node retry count on GitHub Actions
6
31
 
32
+ __(breaking change)__ for open-source forked repositories using GitHub Actions. See a fix in PR description:
33
+
7
34
  https://github.com/KnapsackPro/knapsack_pro-ruby/pull/197
8
35
 
9
36
  https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v4.0.0...v4.1.0
10
37
 
11
38
  ### 4.0.0
12
39
 
13
- * Raise when `KNAPSACK_PRO_CI_NODE_BUILD_ID` is missing
40
+ * __(breaking change)__ Raise when `KNAPSACK_PRO_CI_NODE_BUILD_ID` is missing
14
41
 
15
42
  https://github.com/KnapsackPro/knapsack_pro-ruby/pull/195
16
43
 
@@ -15,7 +15,7 @@ module KnapsackPro
15
15
  :node_total => args.fetch(:node_total),
16
16
  :node_index => args.fetch(:node_index),
17
17
  :ci_build_id => KnapsackPro::Config::Env.ci_node_build_id,
18
- :user_seat => KnapsackPro::Config::Env.user_seat_hash,
18
+ :user_seat => KnapsackPro::Config::Env.masked_user_seat,
19
19
  }
20
20
 
21
21
  unless request_hash[:cache_read_attempt]
@@ -16,7 +16,7 @@ module KnapsackPro
16
16
  :node_total => args.fetch(:node_total),
17
17
  :node_index => args.fetch(:node_index),
18
18
  :node_build_id => KnapsackPro::Config::Env.ci_node_build_id,
19
- :user_seat => KnapsackPro::Config::Env.user_seat_hash,
19
+ :user_seat => KnapsackPro::Config::Env.masked_user_seat,
20
20
  }
21
21
 
22
22
  if request_hash[:can_initialize_queue] && !request_hash[:attempt_connect_to_queue]
@@ -26,6 +26,14 @@ module KnapsackPro
26
26
  def project_dir
27
27
  ENV['APPVEYOR_BUILD_FOLDER']
28
28
  end
29
+
30
+ def detected
31
+ ENV.key?('APPVEYOR') ? self.class : nil
32
+ end
33
+
34
+ def fixed_queue_split
35
+ false
36
+ end
29
37
  end
30
38
  end
31
39
  end
@@ -25,6 +25,13 @@ module KnapsackPro
25
25
 
26
26
  def user_seat
27
27
  end
28
+
29
+ def detected
30
+ end
31
+
32
+ def fixed_queue_split
33
+ true
34
+ end
28
35
  end
29
36
  end
30
37
  end
@@ -33,6 +33,14 @@ module KnapsackPro
33
33
  def user_seat
34
34
  ENV['BUILDKITE_BUILD_AUTHOR'] || ENV['BUILDKITE_BUILD_CREATOR']
35
35
  end
36
+
37
+ def detected
38
+ ENV.key?('BUILDKITE') ? self.class : nil
39
+ end
40
+
41
+ def fixed_queue_split
42
+ true
43
+ end
36
44
  end
37
45
  end
38
46
  end
@@ -29,6 +29,14 @@ module KnapsackPro
29
29
  def user_seat
30
30
  ENV['CIRCLE_USERNAME'] || ENV['CIRCLE_PR_USERNAME']
31
31
  end
32
+
33
+ def detected
34
+ ENV.key?('CIRCLECI') ? self.class : nil
35
+ end
36
+
37
+ def fixed_queue_split
38
+ false
39
+ end
32
40
  end
33
41
  end
34
42
  end
@@ -25,6 +25,14 @@ module KnapsackPro
25
25
  def project_dir
26
26
  ENV['CIRRUS_WORKING_DIR']
27
27
  end
28
+
29
+ def detected
30
+ ENV.key?('CIRRUS_CI') ? self.class : nil
31
+ end
32
+
33
+ def fixed_queue_split
34
+ false
35
+ end
28
36
  end
29
37
  end
30
38
  end
@@ -26,6 +26,14 @@ module KnapsackPro
26
26
  def project_dir
27
27
  # not provided
28
28
  end
29
+
30
+ def detected
31
+ ENV.key?('CF_BUILD_ID') ? self.class : nil
32
+ end
33
+
34
+ def fixed_queue_split
35
+ false
36
+ end
29
37
  end
30
38
  end
31
39
  end
@@ -25,6 +25,14 @@ module KnapsackPro
25
25
  def project_dir
26
26
  # not provided
27
27
  end
28
+
29
+ def detected
30
+ ENV['CI_NAME'] == 'codeship' ? self.class : nil
31
+ end
32
+
33
+ def fixed_queue_split
34
+ true
35
+ end
28
36
  end
29
37
  end
30
38
  end
@@ -41,6 +41,14 @@ module KnapsackPro
41
41
  def user_seat
42
42
  ENV['GITHUB_ACTOR']
43
43
  end
44
+
45
+ def detected
46
+ ENV.key?('GITHUB_ACTIONS') ? self.class : nil
47
+ end
48
+
49
+ def fixed_queue_split
50
+ true
51
+ end
44
52
  end
45
53
  end
46
54
  end
@@ -37,6 +37,14 @@ module KnapsackPro
37
37
  ENV['GITLAB_USER_NAME'] || # Gitlab Release 10.0
38
38
  ENV['GITLAB_USER_EMAIL'] # Gitlab Release 8.12
39
39
  end
40
+
41
+ def detected
42
+ ENV.key?('GITLAB_CI') ? self.class : nil
43
+ end
44
+
45
+ def fixed_queue_split
46
+ false
47
+ end
40
48
  end
41
49
  end
42
50
  end
@@ -25,6 +25,14 @@ module KnapsackPro
25
25
  def project_dir
26
26
  '/app' if node_build_id
27
27
  end
28
+
29
+ def detected
30
+ ENV.key?('HEROKU_TEST_RUN_ID') ? self.class : nil
31
+ end
32
+
33
+ def fixed_queue_split
34
+ false
35
+ end
28
36
  end
29
37
  end
30
38
  end
@@ -26,6 +26,14 @@ module KnapsackPro
26
26
  def project_dir
27
27
  ENV['SEMAPHORE_PROJECT_DIR']
28
28
  end
29
+
30
+ def detected
31
+ ENV.key?('SEMAPHORE_BUILD_NUMBER') ? self.class : nil
32
+ end
33
+
34
+ def fixed_queue_split
35
+ false
36
+ end
29
37
  end
30
38
  end
31
39
  end
@@ -29,6 +29,15 @@ module KnapsackPro
29
29
  "#{ENV['HOME']}/#{ENV['SEMAPHORE_GIT_DIR']}"
30
30
  end
31
31
  end
32
+
33
+ def detected
34
+ # check 2 keys to be sure we are using Semaphore 2.0
35
+ ENV.key?('SEMAPHORE') && ENV.key?('SEMAPHORE_WORKFLOW_ID') ? self.class : nil
36
+ end
37
+
38
+ def fixed_queue_split
39
+ false
40
+ end
32
41
  end
33
42
  end
34
43
  end
@@ -17,6 +17,14 @@ module KnapsackPro
17
17
  def project_dir
18
18
  ENV['TRAVIS_BUILD_DIR']
19
19
  end
20
+
21
+ def detected
22
+ ENV.key?('TRAVIS') ? self.class : nil
23
+ end
24
+
25
+ def fixed_queue_split
26
+ true
27
+ end
20
28
  end
21
29
  end
22
30
  end
@@ -64,9 +64,10 @@ module KnapsackPro
64
64
  ci_env_for(:user_seat)
65
65
  end
66
66
 
67
- def user_seat_hash
67
+ def masked_user_seat
68
68
  return unless user_seat
69
- Digest::SHA2.hexdigest(user_seat)
69
+
70
+ user_seat.gsub(/(?<=\w{2})[a-zA-Z]/, "*")
70
71
  end
71
72
 
72
73
  def test_file_pattern
@@ -186,7 +187,16 @@ module KnapsackPro
186
187
  end
187
188
 
188
189
  def fixed_queue_split
189
- ENV.fetch('KNAPSACK_PRO_FIXED_QUEUE_SPLIT', false)
190
+ @fixed_queue_split ||= begin
191
+ env_name = 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT'
192
+ computed = ENV.fetch(env_name, ci_env_for(:fixed_queue_split)).to_s
193
+
194
+ if !ENV.key?(env_name)
195
+ KnapsackPro.logger.info("#{env_name} is not set. Using default value: #{computed}. Learn more at #{KnapsackPro::Urls::FIXED_QUEUE_SPLIT}")
196
+ end
197
+
198
+ computed
199
+ end
190
200
  end
191
201
 
192
202
  def fixed_queue_split?
@@ -246,17 +256,17 @@ module KnapsackPro
246
256
  end
247
257
 
248
258
  def ci_env_for(env_name)
249
- value = nil
250
- ci_list = KnapsackPro::Config::CI.constants - [:Base, :GitlabCI]
251
- # load GitLab CI first to avoid edge case with order of loading envs for CI_NODE_INDEX
252
- ci_list = [:GitlabCI] + ci_list
253
- ci_list.each do |ci_name|
254
- ci_class = Object.const_get("KnapsackPro::Config::CI::#{ci_name}")
255
- ci = ci_class.new
256
- value = ci.send(env_name)
257
- break unless value.nil?
259
+ detected_ci.new.send(env_name)
260
+ end
261
+
262
+ def detected_ci
263
+ detected = KnapsackPro::Config::CI.constants.map do |constant|
264
+ Object.const_get("KnapsackPro::Config::CI::#{constant}").new.detected
258
265
  end
259
- value
266
+ .compact
267
+ .first
268
+
269
+ detected || KnapsackPro::Config::CI::Base
260
270
  end
261
271
 
262
272
  def log_level
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '4.1.0'
2
+ VERSION = '5.1.0'
3
3
  end
@@ -3,6 +3,11 @@ require 'knapsack_pro'
3
3
  namespace :knapsack_pro do
4
4
  namespace :queue do
5
5
  task :cucumber, [:cucumber_args] do |_, args|
6
+ Kernel.system("RAILS_ENV=test RACK_ENV=test #{$PROGRAM_NAME} 'knapsack_pro:queue:cucumber_go[#{args[:cucumber_args]}]'")
7
+ Kernel.exit($?.exitstatus)
8
+ end
9
+
10
+ task :cucumber_go, [:cucumber_args] do |_, args|
6
11
  KnapsackPro::Runners::Queue::CucumberRunner.run(args[:cucumber_args])
7
12
  end
8
13
  end
@@ -3,6 +3,11 @@ require 'knapsack_pro'
3
3
  namespace :knapsack_pro do
4
4
  namespace :queue do
5
5
  task :minitest, [:minitest_args] do |_, args|
6
+ Kernel.system("RAILS_ENV=test RACK_ENV=test #{$PROGRAM_NAME} 'knapsack_pro:queue:minitest_go[#{args[:minitest_args]}]'")
7
+ Kernel.exit($?.exitstatus)
8
+ end
9
+
10
+ task :minitest_go, [:minitest_args] do |_, args|
6
11
  KnapsackPro::Runners::Queue::MinitestRunner.run(args[:minitest_args])
7
12
  end
8
13
  end
@@ -3,6 +3,11 @@ require 'knapsack_pro'
3
3
  namespace :knapsack_pro do
4
4
  namespace :queue do
5
5
  task :rspec, [:rspec_args] do |_, args|
6
+ Kernel.system("RAILS_ENV=test RACK_ENV=test #{$PROGRAM_NAME} 'knapsack_pro:queue:rspec_go[#{args[:rspec_args]}]'")
7
+ Kernel.exit($?.exitstatus)
8
+ end
9
+
10
+ task :rspec_go, [:rspec_args] do |_, args|
6
11
  KnapsackPro::Runners::Queue::RSpecRunner.run(args[:rspec_args])
7
12
  end
8
13
  end
@@ -6,7 +6,7 @@ describe KnapsackPro::Client::API::V1::BuildDistributions do
6
6
  let(:node_total) { double }
7
7
  let(:node_index) { double }
8
8
  let(:ci_build_id) { double }
9
- let(:user_seat_hash) { double }
9
+ let(:masked_user_seat) { double }
10
10
  let(:test_files) { double }
11
11
 
12
12
  subject do
@@ -23,7 +23,7 @@ describe KnapsackPro::Client::API::V1::BuildDistributions do
23
23
  before do
24
24
  expect(KnapsackPro::Config::Env).to receive(:fixed_test_suite_split).and_return(fixed_test_suite_split)
25
25
  expect(KnapsackPro::Config::Env).to receive(:ci_node_build_id).and_return(ci_build_id)
26
- expect(KnapsackPro::Config::Env).to receive(:user_seat_hash).and_return(user_seat_hash)
26
+ expect(KnapsackPro::Config::Env).to receive(:masked_user_seat).and_return(masked_user_seat)
27
27
  end
28
28
 
29
29
  context 'when cache_read_attempt=true' do
@@ -42,7 +42,7 @@ describe KnapsackPro::Client::API::V1::BuildDistributions do
42
42
  node_total: node_total,
43
43
  node_index: node_index,
44
44
  ci_build_id: ci_build_id,
45
- user_seat: user_seat_hash,
45
+ user_seat: masked_user_seat,
46
46
  }
47
47
  }).and_return(action)
48
48
  expect(subject).to eq action
@@ -65,7 +65,7 @@ describe KnapsackPro::Client::API::V1::BuildDistributions do
65
65
  node_total: node_total,
66
66
  node_index: node_index,
67
67
  ci_build_id: ci_build_id,
68
- user_seat: user_seat_hash,
68
+ user_seat: masked_user_seat,
69
69
  test_files: test_files
70
70
  }
71
71
  }).and_return(action)
@@ -7,7 +7,7 @@ describe KnapsackPro::Client::API::V1::Queues do
7
7
  let(:node_index) { double }
8
8
  let(:test_files) { double }
9
9
  let(:node_build_id) { double }
10
- let(:user_seat_hash) { double }
10
+ let(:masked_user_seat) { double }
11
11
 
12
12
  subject do
13
13
  described_class.queue(
@@ -24,7 +24,7 @@ describe KnapsackPro::Client::API::V1::Queues do
24
24
  before do
25
25
  expect(KnapsackPro::Config::Env).to receive(:fixed_queue_split).and_return(fixed_queue_split)
26
26
  expect(KnapsackPro::Config::Env).to receive(:ci_node_build_id).and_return(node_build_id)
27
- expect(KnapsackPro::Config::Env).to receive(:user_seat_hash).and_return(user_seat_hash)
27
+ expect(KnapsackPro::Config::Env).to receive(:masked_user_seat).and_return(masked_user_seat)
28
28
  end
29
29
 
30
30
  context 'when can_initialize_queue=true and attempt_connect_to_queue=true' do
@@ -45,7 +45,7 @@ describe KnapsackPro::Client::API::V1::Queues do
45
45
  node_total: node_total,
46
46
  node_index: node_index,
47
47
  node_build_id: node_build_id,
48
- user_seat: user_seat_hash,
48
+ user_seat: masked_user_seat,
49
49
  }
50
50
  }).and_return(action)
51
51
  expect(subject).to eq action
@@ -70,7 +70,7 @@ describe KnapsackPro::Client::API::V1::Queues do
70
70
  node_total: node_total,
71
71
  node_index: node_index,
72
72
  node_build_id: node_build_id,
73
- user_seat: user_seat_hash,
73
+ user_seat: masked_user_seat,
74
74
  test_files: test_files
75
75
  }
76
76
  }).and_return(action)
@@ -96,7 +96,7 @@ describe KnapsackPro::Client::API::V1::Queues do
96
96
  node_total: node_total,
97
97
  node_index: node_index,
98
98
  node_build_id: node_build_id,
99
- user_seat: user_seat_hash,
99
+ user_seat: masked_user_seat,
100
100
  }
101
101
  }).and_return(action)
102
102
  expect(subject).to eq action
@@ -207,22 +207,26 @@ describe KnapsackPro::Config::Env do
207
207
  end
208
208
  end
209
209
 
210
- describe '.user_seat_hash' do
211
- subject { described_class.user_seat_hash }
210
+ describe '.masked_seat_hash' do
211
+ subject { described_class.masked_user_seat }
212
212
 
213
213
  before do
214
214
  expect(described_class).to receive(:user_seat).at_least(1).and_return(user_seat)
215
215
  end
216
216
 
217
- context 'when the user seat has a value' do
217
+ context 'when the user seat is a name' do
218
218
  let(:user_seat) { 'John Doe' }
219
219
 
220
- it 'returns a SHA256 hash for the user seat' do
221
- expect(subject).to eq '6cea57c2fb6cbc2a40411135005760f241fffc3e5e67ab99882726431037f908'
222
- end
220
+ it { expect(subject).to eq 'Jo** Do*' }
221
+ end
222
+
223
+ context 'when the user seat is an e-mail' do
224
+ let(:user_seat) { 'john.doe@example.com' }
225
+
226
+ it { expect(subject).to eq 'jo**.do*@ex*****.co*' }
223
227
  end
224
228
 
225
- context 'when the user seat has no value' do
229
+ context 'when the user seat is nil' do
226
230
  let(:user_seat) { nil }
227
231
 
228
232
  it { expect(subject).to be_nil }
@@ -632,20 +636,6 @@ describe KnapsackPro::Config::Env do
632
636
  end
633
637
  end
634
638
 
635
- describe '.fixed_test_suite_split' do
636
- subject { described_class.fixed_test_suite_split }
637
-
638
- context 'when ENV exists' do
639
- before { stub_const("ENV", { 'KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT' => false }) }
640
- it { should eq false }
641
- end
642
-
643
- context "when ENV doesn't exist" do
644
- before { stub_const("ENV", {}) }
645
- it { should be true }
646
- end
647
- end
648
-
649
639
  describe '.fixed_test_suite_split?' do
650
640
  subject { described_class.fixed_test_suite_split? }
651
641
 
@@ -667,38 +657,94 @@ describe KnapsackPro::Config::Env do
667
657
  end
668
658
  end
669
659
 
670
- describe '.fixed_queue_split' do
671
- subject { described_class.fixed_queue_split }
672
-
673
- context 'when ENV exists' do
674
- before { stub_const("ENV", { 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => true }) }
675
- it { should eq true }
676
- end
677
-
678
- context "when ENV doesn't exist" do
679
- before { stub_const("ENV", {}) }
680
- it { should be false }
681
- end
682
- end
683
-
684
660
  describe '.fixed_queue_split?' do
685
661
  subject { described_class.fixed_queue_split? }
662
+ after(:each) { described_class.remove_instance_variable(:@fixed_queue_split) }
686
663
 
687
664
  context 'when ENV exists' do
688
- context 'when KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true' do
689
- before { stub_const("ENV", { 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'true' }) }
690
- it { should be true }
665
+ context 'when KNAPSACK_PRO_FIXED_QUEUE_SPLIT=false' do
666
+ [
667
+ ['AppVeyor', { 'APPVEYOR' => '123' }],
668
+ ['Buildkite', { 'BUILDKITE' => 'true' }],
669
+ ['CircleCI', { 'CIRCLECI' => 'true' }],
670
+ ['Cirrus CI', { 'CIRRUS_CI' => 'true' }],
671
+ ['Codefresh', { 'CF_BUILD_ID' => '123' }],
672
+ ['Codeship', { 'CI_NAME' => 'codeship' }],
673
+ ['GitHub Actions', { 'GITHUB_ACTIONS' => 'true' }],
674
+ ['GitLab CI', { 'GITLAB_CI' => 'true' }],
675
+ ['Heroku CI', { 'HEROKU_TEST_RUN_ID' => '123' }],
676
+ ['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }],
677
+ ['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }],
678
+ ['Travis CI', { 'TRAVIS' => 'true' }],
679
+ ['Unsupported', {}],
680
+ ].each do |ci, env|
681
+ it "on #{ci} it is false" do
682
+ logger = instance_double(Logger)
683
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
684
+ expect(logger).not_to receive(:info)
685
+
686
+ stub_const("ENV", env.merge({ 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'false' }))
687
+
688
+ expect(subject).to eq(false)
689
+ end
690
+ end
691
691
  end
692
692
 
693
- context 'when KNAPSACK_PRO_FIXED_QUEUE_SPLIT=false' do
694
- before { stub_const("ENV", { 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'false' }) }
695
- it { should be false }
693
+ context 'when KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true' do
694
+ [
695
+ ['AppVeyor', { 'APPVEYOR' => '123' }],
696
+ ['Buildkite', { 'BUILDKITE' => 'true' }],
697
+ ['CircleCI', { 'CIRCLECI' => 'true' }],
698
+ ['Cirrus CI', { 'CIRRUS_CI' => 'true' }],
699
+ ['Codefresh', { 'CF_BUILD_ID' => '123' }],
700
+ ['Codeship', { 'CI_NAME' => 'codeship' }],
701
+ ['GitHub Actions', { 'GITHUB_ACTIONS' => 'true' }],
702
+ ['GitLab CI', { 'GITLAB_CI' => 'true' }],
703
+ ['Heroku CI', { 'HEROKU_TEST_RUN_ID' => '123' }],
704
+ ['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }],
705
+ ['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }],
706
+ ['Travis CI', { 'TRAVIS' => 'true' }],
707
+ ['Unsupported', {}],
708
+ ].each do |ci, env|
709
+ it "on #{ci} it is true" do
710
+ logger = instance_double(Logger)
711
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
712
+ expect(logger).not_to receive(:info)
713
+
714
+ stub_const("ENV", env.merge({ 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'true' }))
715
+
716
+ expect(subject).to eq(true)
717
+ end
718
+ end
696
719
  end
697
720
  end
698
721
 
699
722
  context "when ENV doesn't exist" do
700
- before { stub_const("ENV", {}) }
701
- it { should be false }
723
+ [
724
+ ['AppVeyor', { 'APPVEYOR' => '123' }, false],
725
+ ['Buildkite', { 'BUILDKITE' => 'true' }, true],
726
+ ['CircleCI', { 'CIRCLECI' => 'true' }, false],
727
+ ['Cirrus CI', { 'CIRRUS_CI' => 'true' }, false],
728
+ ['Codefresh', { 'CF_BUILD_ID' => '123' }, false],
729
+ ['Codeship', { 'CI_NAME' => 'codeship' }, true],
730
+ ['GitHub Actions', { 'GITHUB_ACTIONS' => 'true' }, true],
731
+ ['GitLab CI', { 'GITLAB_CI' => 'true' }, false],
732
+ ['Heroku CI', { 'HEROKU_TEST_RUN_ID' => '123' }, false],
733
+ ['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }, false],
734
+ ['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }, false],
735
+ ['Travis CI', { 'TRAVIS' => 'true' }, true],
736
+ ['Unsupported', {}, true],
737
+ ].each do |ci, env, expected|
738
+ it "on #{ci} it is #{expected}" do
739
+ logger = instance_double(Logger)
740
+ expect(KnapsackPro).to receive(:logger).and_return(logger)
741
+ expect(logger).to receive(:info).with("KNAPSACK_PRO_FIXED_QUEUE_SPLIT is not set. Using default value: #{expected}. Learn more at #{KnapsackPro::Urls::FIXED_QUEUE_SPLIT}")
742
+
743
+ stub_const("ENV", env)
744
+
745
+ expect(subject).to eq(expected)
746
+ end
747
+ end
702
748
  end
703
749
  end
704
750
 
@@ -895,57 +941,6 @@ describe KnapsackPro::Config::Env do
895
941
  end
896
942
  end
897
943
 
898
- describe '.ci_env_for' do
899
- let(:env_name) { :node_total }
900
-
901
- subject { described_class.ci_env_for(env_name) }
902
-
903
- context 'when CI has no value for env_name method' do
904
- before do
905
- expect(KnapsackPro::Config::CI::Circle).to receive_message_chain(:new, env_name).and_return(nil)
906
- expect(KnapsackPro::Config::CI::Semaphore).to receive_message_chain(:new, env_name).and_return(nil)
907
- expect(KnapsackPro::Config::CI::Buildkite).to receive_message_chain(:new, env_name).and_return(nil)
908
- end
909
-
910
- it do
911
- expect(subject).to be_nil
912
- end
913
- end
914
-
915
- context 'when CI has value for env_name method' do
916
- let(:circle_env) { double(:circle) }
917
- let(:semaphore_env) { double(:semaphore) }
918
- let(:buildkite_env) { double(:buildkite) }
919
-
920
- before do
921
- allow(KnapsackPro::Config::CI::Circle).to receive_message_chain(:new, env_name).and_return(circle_env)
922
- allow(KnapsackPro::Config::CI::Semaphore).to receive_message_chain(:new, env_name).and_return(semaphore_env)
923
- allow(KnapsackPro::Config::CI::Buildkite).to receive_message_chain(:new, env_name).and_return(buildkite_env)
924
- end
925
-
926
- context do
927
- let(:buildkite_env) { nil }
928
- let(:semaphore_env) { nil }
929
-
930
- it { should eq circle_env }
931
- end
932
-
933
- context do
934
- let(:circle_env) { nil }
935
- let(:buildkite_env) { nil }
936
-
937
- it { should eq semaphore_env }
938
- end
939
-
940
- context do
941
- let(:circle_env) { nil }
942
- let(:semaphore_env) { nil }
943
-
944
- it { should eq buildkite_env }
945
- end
946
- end
947
- end
948
-
949
944
  describe '.log_level' do
950
945
  subject { described_class.log_level }
951
946
 
@@ -1022,4 +1017,28 @@ describe KnapsackPro::Config::Env do
1022
1017
  expect(described_class.test_runner_adapter).to eql 'RSpecAdapter'
1023
1018
  end
1024
1019
  end
1020
+
1021
+ describe '.detected_ci' do
1022
+ [
1023
+ ['AppVeyor', { 'APPVEYOR' => '123' }, KnapsackPro::Config::CI::AppVeyor],
1024
+ ['Buildkite', { 'BUILDKITE' => 'true' }, KnapsackPro::Config::CI::Buildkite],
1025
+ ['CircleCI', { 'CIRCLECI' => 'true' }, KnapsackPro::Config::CI::Circle],
1026
+ ['Cirrus CI', { 'CIRRUS_CI' => 'true' }, KnapsackPro::Config::CI::CirrusCI],
1027
+ ['Codefresh', { 'CF_BUILD_ID' => '123' }, KnapsackPro::Config::CI::Codefresh],
1028
+ ['Codeship', { 'CI_NAME' => 'codeship' }, KnapsackPro::Config::CI::Codeship],
1029
+ ['GitHub Actions', { 'GITHUB_ACTIONS' => 'true' }, KnapsackPro::Config::CI::GithubActions],
1030
+ ['GitLab CI', { 'GITLAB_CI' => 'true' }, KnapsackPro::Config::CI::GitlabCI],
1031
+ ['Heroku CI', { 'HEROKU_TEST_RUN_ID' => '123' }, KnapsackPro::Config::CI::Heroku],
1032
+ ['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }, KnapsackPro::Config::CI::Semaphore],
1033
+ ['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }, KnapsackPro::Config::CI::Semaphore2],
1034
+ ['Travis CI', { 'TRAVIS' => 'true' }, KnapsackPro::Config::CI::Travis],
1035
+ ['Unsupported', {}, KnapsackPro::Config::CI::Base],
1036
+ ].each do |ci, env, expected|
1037
+ it "detects #{ci}" do
1038
+ stub_const("ENV", env)
1039
+
1040
+ expect(described_class.detected_ci).to eq(expected)
1041
+ end
1042
+ end
1043
+ end
1025
1044
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-23 00:00:00.000000000 Z
11
+ date: 2023-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -389,7 +389,7 @@ metadata:
389
389
  documentation_uri: https://docs.knapsackpro.com/integration/
390
390
  homepage_uri: https://knapsackpro.com
391
391
  source_code_uri: https://github.com/KnapsackPro/knapsack_pro-ruby
392
- post_install_message:
392
+ post_install_message:
393
393
  rdoc_options: []
394
394
  require_paths:
395
395
  - lib
@@ -404,8 +404,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
404
404
  - !ruby/object:Gem::Version
405
405
  version: '0'
406
406
  requirements: []
407
- rubygems_version: 3.4.10
408
- signing_key:
407
+ rubygems_version: 3.3.7
408
+ signing_key:
409
409
  specification_version: 4
410
410
  summary: Knapsack Pro splits tests across parallel CI nodes and ensures each parallel
411
411
  job finish work at a similar time.