knapsack_pro 0.37.0 → 0.38.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +38 -1
- data/lib/knapsack_pro.rb +1 -0
- data/lib/knapsack_pro/config/ci/gitlab_ci.rb +35 -0
- data/lib/knapsack_pro/version.rb +1 -1
- data/lib/tasks/install.rake +18 -0
- data/spec/knapsack_pro/config/ci/gitlab_ci_spec.rb +88 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58513c4532159921b31333f16c66a2558d5d1d37
|
4
|
+
data.tar.gz: efe8d50df9c61c480cf2a98429569d86f84d85c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f8f2c220f41c9becf921e5d144192d7d52d175f3f2a8ea1d4492049a3f2dd47de5479dbd02d8f4ea8b5a15caf6810e6e1cecf748cf5d378ab01f7013824b7a2
|
7
|
+
data.tar.gz: c647fe42e829f4c04ff61d445e8244ad6919891681769730a193a7237d2b8236e1aae4eff851379927e85c96f6b95d027021dd0e74fbdc71076f336808267855
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,17 @@
|
|
2
2
|
|
3
3
|
* TODO
|
4
4
|
|
5
|
+
### 0.38.0
|
6
|
+
|
7
|
+
* Add support for Gitlab CI.
|
8
|
+
|
9
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/36
|
10
|
+
|
11
|
+
* More info about Buildkite in installer.
|
12
|
+
* More info about CircleCI in installer.
|
13
|
+
|
14
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.37.0...v0.38.0
|
15
|
+
|
5
16
|
### 0.37.0
|
6
17
|
|
7
18
|
* Add another explanation why test files could not be executed on CI node in Queue Mode.
|
data/README.md
CHANGED
@@ -96,6 +96,7 @@ The knapsack_pro has also [queue mode](#queue-mode) to get most optimal test sui
|
|
96
96
|
- [Info for Travis users](#info-for-travis-users)
|
97
97
|
- [Info for semaphoreapp.com users](#info-for-semaphoreappcom-users)
|
98
98
|
- [Info for buildkite.com users](#info-for-buildkitecom-users)
|
99
|
+
- [Info for Gitlab CI users](#info-for-gitlab-ci-users)
|
99
100
|
- [Info for snap-ci.com users](#info-for-snap-cicom-users)
|
100
101
|
- [Info for Jenkins users](#info-for-jenkins-users)
|
101
102
|
- [FAQ](#faq)
|
@@ -724,6 +725,40 @@ Here you can find article [how to set up a new pipeline for your project in Buil
|
|
724
725
|
* [Buildkite Rails Parallel Example with Knapsack Pro](https://github.com/KnapsackPro/buildkite-rails-parallel-example-with-knapsack_pro)
|
725
726
|
* [Buildkite Rails Docker Parallel Example with Knapsack Pro](https://github.com/KnapsackPro/buildkite-rails-docker-parallel-example-with-knapsack_pro)
|
726
727
|
|
728
|
+
#### Info for Gitlab CI users
|
729
|
+
|
730
|
+
Gitlab CI does not provide parallel jobs environment variables so you will have to define `KNAPSACK_PRO_CI_NODE_TOTAL` and `KNAPSACK_PRO_CI_NODE_INDEX` for each parallel job running as part of the same `test` stage. Below is relevant part of `.gitlab-ci.yml` configuration for 2 parallel jobs.
|
731
|
+
|
732
|
+
```
|
733
|
+
# .gitlab-ci.yml
|
734
|
+
stages:
|
735
|
+
- test
|
736
|
+
|
737
|
+
variables:
|
738
|
+
KNAPSACK_PRO_CI_NODE_TOTAL: 2
|
739
|
+
|
740
|
+
# first CI node running in parallel
|
741
|
+
test_ci_node_0:
|
742
|
+
stage: test
|
743
|
+
script:
|
744
|
+
- export KNAPSACK_PRO_CI_NODE_INDEX=0
|
745
|
+
# Cucumber tests in Knapsack Pro Regular Mode (deterministic test suite split)
|
746
|
+
- bundle exec rake knapsack_pro:cucumber
|
747
|
+
# RSpec tests in Knapsack Pro Queue Mode (dynamic test suite split)
|
748
|
+
# It will autobalance bulid because it is executed after Cucumber tests.
|
749
|
+
- bundle exec rake knapsack_pro:queue:rspec
|
750
|
+
|
751
|
+
# second CI node running in parallel
|
752
|
+
test_ci_node_1:
|
753
|
+
stage: test
|
754
|
+
script:
|
755
|
+
- export KNAPSACK_PRO_CI_NODE_INDEX=1
|
756
|
+
- bundle exec rake knapsack_pro:cucumber
|
757
|
+
- bundle exec rake knapsack_pro:queue:rspec
|
758
|
+
```
|
759
|
+
|
760
|
+
Remember to add API tokens like `KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER` and `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` to [Secret Variables](https://gitlab.com/help/ci/variables/README.md#secret-variables) in `Gitlab CI Settings -> CI/CD Pipelines -> Secret Variables`.
|
761
|
+
|
727
762
|
#### Info for snap-ci.com users
|
728
763
|
|
729
764
|
Knapsack Pro supports snap-ci.com ENVs `SNAP_WORKER_TOTAL` and `SNAP_WORKER_INDEX`. The only thing you need to do is to configure number of workers for your project in configuration settings in order to enable parallelism. Next thing is to set below commands to be executed in your stage:
|
@@ -1167,6 +1202,7 @@ Now you need to set parallel_tests command per CI node:
|
|
1167
1202
|
|
1168
1203
|
```
|
1169
1204
|
export PARALLEL_TESTS_CONCURRENCY=2; # this must be export
|
1205
|
+
RAILS_ENV=test \
|
1170
1206
|
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=xxx \
|
1171
1207
|
KNAPSACK_PRO_CI_NODE_TOTAL=$YOUR_CI_NODE_TOTAL \
|
1172
1208
|
KNAPSACK_PRO_CI_NODE_INDEX=$YOUR_CI_NODE_INDEX \
|
@@ -1177,6 +1213,7 @@ Now you need to set parallel_tests command per CI node:
|
|
1177
1213
|
|
1178
1214
|
```
|
1179
1215
|
export PARALLEL_TESTS_CONCURRENCY=2; # this must be export
|
1216
|
+
RAILS_ENV=test \
|
1180
1217
|
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=xxx \
|
1181
1218
|
KNAPSACK_PRO_CI_NODE_TOTAL=$YOUR_CI_NODE_TOTAL \
|
1182
1219
|
KNAPSACK_PRO_CI_NODE_INDEX=$YOUR_CI_NODE_INDEX \
|
@@ -1190,7 +1227,7 @@ Please note you need to update `$YOUR_CI_NODE_TOTAL` and `$YOUR_CI_NODE_INDEX` t
|
|
1190
1227
|
# KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=xxx can be set in CircleCI ENV settings
|
1191
1228
|
test:
|
1192
1229
|
override:
|
1193
|
-
- export PARALLEL_TESTS_CONCURRENCY=2; KNAPSACK_PRO_CI_NODE_TOTAL=$CIRCLE_NODE_TOTAL KNAPSACK_PRO_CI_NODE_INDEX=$CIRCLE_NODE_INDEX bundle exec parallel_test -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests':
|
1230
|
+
- export PARALLEL_TESTS_CONCURRENCY=2; RAILS_ENV=test KNAPSACK_PRO_CI_NODE_TOTAL=$CIRCLE_NODE_TOTAL KNAPSACK_PRO_CI_NODE_INDEX=$CIRCLE_NODE_INDEX bundle exec parallel_test -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests':
|
1194
1231
|
parallel: true # Caution: there are 8 spaces indentation!
|
1195
1232
|
```
|
1196
1233
|
|
data/lib/knapsack_pro.rb
CHANGED
@@ -12,6 +12,7 @@ require_relative 'knapsack_pro/utils'
|
|
12
12
|
require_relative 'knapsack_pro/logger_wrapper'
|
13
13
|
require_relative 'knapsack_pro/config/ci/base'
|
14
14
|
require_relative 'knapsack_pro/config/ci/circle'
|
15
|
+
require_relative 'knapsack_pro/config/ci/gitlab_ci'
|
15
16
|
require_relative 'knapsack_pro/config/ci/semaphore'
|
16
17
|
require_relative 'knapsack_pro/config/ci/buildkite'
|
17
18
|
require_relative 'knapsack_pro/config/ci/travis'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# https://docs.gitlab.com/ce/ci/variables/
|
2
|
+
module KnapsackPro
|
3
|
+
module Config
|
4
|
+
module CI
|
5
|
+
class GitlabCI < Base
|
6
|
+
def node_total
|
7
|
+
# not provided by Gitlab CI
|
8
|
+
end
|
9
|
+
|
10
|
+
def node_index
|
11
|
+
# not provided by Gitlab CI
|
12
|
+
end
|
13
|
+
|
14
|
+
def node_build_id
|
15
|
+
ENV['CI_JOB_ID'] || # Gitlab Release 9.0+
|
16
|
+
ENV['CI_BUILD_ID'] # Gitlab Release 8.x
|
17
|
+
end
|
18
|
+
|
19
|
+
def commit_hash
|
20
|
+
ENV['CI_COMMIT_SHA'] || # Gitlab Release 9.0+
|
21
|
+
ENV['CI_BUILD_REF'] # Gitlab Release 8.x
|
22
|
+
end
|
23
|
+
|
24
|
+
def branch
|
25
|
+
ENV['CI_COMMIT_REF_NAME'] || # Gitlab Release 9.0+
|
26
|
+
ENV['CI_BUILD_REF_NAME'] # Gitlab Release 8.x
|
27
|
+
end
|
28
|
+
|
29
|
+
def project_dir
|
30
|
+
ENV['CI_PROJECT_DIR']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/knapsack_pro/version.rb
CHANGED
data/lib/tasks/install.rake
CHANGED
@@ -93,6 +93,19 @@ def step_for_ci_circle(prompt, answers)
|
|
93
93
|
test:
|
94
94
|
override:} + str), color: :cyan)
|
95
95
|
|
96
|
+
puts
|
97
|
+
prompt.say "Please read this section about example for CircleCI 1.0 and CircleCI 2.0 platform:"
|
98
|
+
prompt.say "https://github.com/KnapsackPro/knapsack_pro-ruby#info-for-circleci-users"
|
99
|
+
|
100
|
+
puts
|
101
|
+
set_api_tokens_on_ci(prompt, answers)
|
102
|
+
end
|
103
|
+
|
104
|
+
def step_for_ci_gitlab(prompt, answers)
|
105
|
+
prompt.say "Step for Gitlab CI https://about.gitlab.com/features/gitlab-ci-cd/", color: :yellow
|
106
|
+
prompt.say "Update .gitlab-ci.yml in your project as in this example:"
|
107
|
+
prompt.say "https://github.com/KnapsackPro/knapsack_pro-ruby#info-for-gitlab-ci-users"
|
108
|
+
|
96
109
|
puts
|
97
110
|
set_api_tokens_on_ci(prompt, answers)
|
98
111
|
end
|
@@ -148,6 +161,10 @@ bundle exec rake knapsack_pro:#{tool}
|
|
148
161
|
}, color: :cyan
|
149
162
|
end
|
150
163
|
|
164
|
+
puts
|
165
|
+
prompt.say "Please read this section about example usage for Rails project with Docker and without it:"
|
166
|
+
prompt.say "https://github.com/KnapsackPro/knapsack_pro-ruby#info-for-buildkitecom-users"
|
167
|
+
|
151
168
|
puts
|
152
169
|
set_api_tokens_on_ci(prompt, answers)
|
153
170
|
end
|
@@ -291,6 +308,7 @@ namespace :knapsack_pro do
|
|
291
308
|
'https://buildkite.com' => :buildkite,
|
292
309
|
'https://semaphoreci.com' => :semaphore,
|
293
310
|
'https://snap-ci.com' => :snap_ci,
|
311
|
+
'Gitlab CI' => :gitlab,
|
294
312
|
'Jenkins' => :jenkins,
|
295
313
|
'other' => :other,
|
296
314
|
}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
describe KnapsackPro::Config::CI::GitlabCI do
|
2
|
+
let(:env) { {} }
|
3
|
+
|
4
|
+
before do
|
5
|
+
stub_const('ENV', env)
|
6
|
+
end
|
7
|
+
|
8
|
+
it { should be_kind_of KnapsackPro::Config::CI::Base }
|
9
|
+
|
10
|
+
describe '#node_total' do
|
11
|
+
subject { described_class.new.node_total }
|
12
|
+
|
13
|
+
it { should be nil }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#node_index' do
|
17
|
+
subject { described_class.new.node_index }
|
18
|
+
|
19
|
+
it { should be nil }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#node_build_id' do
|
23
|
+
subject { described_class.new.node_build_id }
|
24
|
+
|
25
|
+
context 'when Gitlab Release 9.0+ and environment exists' do
|
26
|
+
let(:env) { { 'CI_JOB_ID' => 7046507 } }
|
27
|
+
it { should eql 7046507 }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when Gitlab Release 8.x and environment exists' do
|
31
|
+
let(:env) { { 'CI_BUILD_ID' => 7046508 } }
|
32
|
+
it { should eql 7046508 }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when environment doesn't exist" do
|
36
|
+
it { should be nil }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#commit_hash' do
|
41
|
+
subject { described_class.new.commit_hash }
|
42
|
+
|
43
|
+
context 'when Gitlab Release 9.0+ and environment exists' do
|
44
|
+
let(:env) { { 'CI_COMMIT_SHA' => '4e0c4feec2267261fbcc060e82d7776e' } }
|
45
|
+
it { should eql '4e0c4feec2267261fbcc060e82d7776e' }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when Gitlab Release 8.x and environment exists' do
|
49
|
+
let(:env) { { 'CI_BUILD_REF' => 'f76c468e3e1d570f71f5822b1e48bb04' } }
|
50
|
+
it { should eql 'f76c468e3e1d570f71f5822b1e48bb04' }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when environment doesn't exist" do
|
54
|
+
it { should be nil }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#branch' do
|
59
|
+
subject { described_class.new.branch }
|
60
|
+
|
61
|
+
context 'when Gitlab Release 9.0+ and environment exists' do
|
62
|
+
let(:env) { { 'CI_COMMIT_REF_NAME' => 'master' } }
|
63
|
+
it { should eql 'master' }
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when Gitlab Release 8.x and environment exists' do
|
67
|
+
let(:env) { { 'CI_BUILD_REF_NAME' => 'master' } }
|
68
|
+
it { should eql 'master' }
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when environment doesn't exist" do
|
72
|
+
it { should be nil }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#project_dir' do
|
77
|
+
subject { described_class.new.project_dir }
|
78
|
+
|
79
|
+
context 'when environment exists' do
|
80
|
+
let(:env) { { 'CI_PROJECT_DIR' => '/home/user/knapsack_pro-ruby' } }
|
81
|
+
it { should eql '/home/user/knapsack_pro-ruby' }
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when environment doesn't exist" do
|
85
|
+
it { should be nil }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
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: 0.
|
4
|
+
version: 0.38.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArturT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -235,6 +235,7 @@ files:
|
|
235
235
|
- lib/knapsack_pro/config/ci/base.rb
|
236
236
|
- lib/knapsack_pro/config/ci/buildkite.rb
|
237
237
|
- lib/knapsack_pro/config/ci/circle.rb
|
238
|
+
- lib/knapsack_pro/config/ci/gitlab_ci.rb
|
238
239
|
- lib/knapsack_pro/config/ci/semaphore.rb
|
239
240
|
- lib/knapsack_pro/config/ci/snap_ci.rb
|
240
241
|
- lib/knapsack_pro/config/ci/travis.rb
|
@@ -303,6 +304,7 @@ files:
|
|
303
304
|
- spec/knapsack_pro/config/ci/base_spec.rb
|
304
305
|
- spec/knapsack_pro/config/ci/buildkite_spec.rb
|
305
306
|
- spec/knapsack_pro/config/ci/circle_spec.rb
|
307
|
+
- spec/knapsack_pro/config/ci/gitlab_ci_spec.rb
|
306
308
|
- spec/knapsack_pro/config/ci/semaphore_spec.rb
|
307
309
|
- spec/knapsack_pro/config/ci/snap_ci_spec.rb
|
308
310
|
- spec/knapsack_pro/config/ci/travis_spec.rb
|
@@ -397,6 +399,7 @@ test_files:
|
|
397
399
|
- spec/knapsack_pro/config/ci/base_spec.rb
|
398
400
|
- spec/knapsack_pro/config/ci/buildkite_spec.rb
|
399
401
|
- spec/knapsack_pro/config/ci/circle_spec.rb
|
402
|
+
- spec/knapsack_pro/config/ci/gitlab_ci_spec.rb
|
400
403
|
- spec/knapsack_pro/config/ci/semaphore_spec.rb
|
401
404
|
- spec/knapsack_pro/config/ci/snap_ci_spec.rb
|
402
405
|
- spec/knapsack_pro/config/ci/travis_spec.rb
|