knapsack_pro 1.4.0 → 1.5.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: 9207f8f421d46b1760bb1f73849d061d570f92b0f25d6f562786d707404d9de6
4
- data.tar.gz: d76fa0771d644dcc45b41a471d4196bbe1fd76ec4663a5316d73f60e7f587f42
3
+ metadata.gz: 406093c37a1985ce7cf5b2c89f625a226c4d42d8c4554eaac9037901fcfc3707
4
+ data.tar.gz: b299828d599720303c5203caee6bebe3d5b96e122fbf878924ac00c6cf4b6db2
5
5
  SHA512:
6
- metadata.gz: 106bba52089e1f8984ae7b7c0f136d6c66a0196fbbccb070d103ed331fc07d5d63a0618e55e6ec04bbe0531b29f2ba9d3d7306e5d039ccb5a76343688363a922
7
- data.tar.gz: 3ef0616787f95bbfe59b4837b96947f397c7307f7ae61824fc28126a90c10f252b6d5844153755337baab963cb7ef53b86c05021847fda2725401335730db808
6
+ metadata.gz: aa7533794502874dee1c1275197166f99a5cb8ff63e3e37736fc4c2d66586af7a53088ca4a3a194f54a50a94d62c071253f421255a608bf9250cb5a9521bd3ef
7
+ data.tar.gz: 59b4abd2a72a5f979aa0dbde8cab8a62f1e8c06f37415bba258649ae6c9d7e373cdbe131514e7ad2f7b6870b8251a3c25ae50c37fd1847650e1761802ce39378
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ### 1.5.0
4
+
5
+ * Add support for Semaphore CI 2.0
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/77
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v1.4.0...v1.5.0
10
+
3
11
  ### 1.4.0
4
12
 
5
13
  * Use .test domain for development mode
data/README.md CHANGED
@@ -98,7 +98,9 @@ You can see list of questions for common problems and tips in below [Table of Co
98
98
  - [Info for CircleCI users](#info-for-circleci-users)
99
99
  - [CircleCI and knapsack_pro Queue Mode](#circleci-and-knapsack_pro-queue-mode)
100
100
  - [Info for Travis users](#info-for-travis-users)
101
- - [Info for semaphoreapp.com users](#info-for-semaphoreappcom-users)
101
+ - [Info for semaphoreci.com users](#info-for-semaphorecicom-users)
102
+ - [Semaphore 2.0](#semaphore-20)
103
+ - [Semaphore 1.0](#semaphore-10)
102
104
  - [Info for buildkite.com users](#info-for-buildkitecom-users)
103
105
  - [Info for GitLab CI users](#info-for-gitlab-ci-users)
104
106
  - [GitLab CI `>= 11.5`](#gitlab-ci--115)
@@ -121,6 +123,7 @@ You can see list of questions for common problems and tips in below [Table of Co
121
123
  - [Queue Mode problems](#queue-mode-problems)
122
124
  - [Why when I use Queue Mode for RSpec then my tests fail?](#why-when-i-use-queue-mode-for-rspec-then-my-tests-fail)
123
125
  - [Why when I use Queue Mode for RSpec then FactoryBot/FactoryGirl tests fail?](#why-when-i-use-queue-mode-for-rspec-then-factorybotfactorygirl-tests-fail)
126
+ - [Why when I use Queue Mode for RSpec then my rake tasks are run twice?](#why-when-i-use-queue-mode-for-rspec-then-my-rake-tasks-are-run-twice)
124
127
  - [Why when I use Queue Mode for RSpec then I see error `superclass mismatch for class`?](#why-when-i-use-queue-mode-for-rspec-then-i-see-error-superclass-mismatch-for-class)
125
128
  - [Why I don't see collected time execution data for my build in user dashboard?](#why-i-dont-see-collected-time-execution-data-for-my-build-in-user-dashboard)
126
129
  - [Why all test files have 0.1s time execution for my CI build in user dashboard?](#why-all-test-files-have-01s-time-execution-for-my-ci-build-in-user-dashboard)
@@ -582,9 +585,11 @@ Note this is for knapack_pro regular mode only.
582
585
 
583
586
  This is only for maintainer of knapsack_pro gem. Not for the end users.
584
587
 
585
- `KNAPSACK_PRO_ENDPOINT` - Default value is `https://api.knapsackpro.com` which is endpoint for [Knapsack Pro API](http://docs.knapsackpro.com).
588
+ * `KNAPSACK_PRO_ENDPOINT` - Default value is `https://api.knapsackpro.com` which is endpoint for [Knapsack Pro API](http://docs.knapsackpro.com).
586
589
 
587
- `KNAPSACK_PRO_MODE` - Default value is `production`. When mode is `development` then endpoint is `http://api.knapsackpro.test:3000`. When mode is `test` then endpoint is `http://api-staging.knapsackpro.com`.
590
+ * `KNAPSACK_PRO_MODE` - Default value is `production` and then endpoint is `https://api.knapsackpro.com`.
591
+ * When mode is `development` then endpoint is `http://api.knapsackpro.test:3000`.
592
+ * When mode is `test` then endpoint is `https://api-staging.knapsackpro.com`.
588
593
 
589
594
  ### Passing arguments to rake task
590
595
 
@@ -865,7 +870,104 @@ Such configuration will generate matrix with 2 following ENV rows:
865
870
 
866
871
  More info about global and matrix ENV configuration in [travis docs](https://docs.travis-ci.com/user/customizing-the-build/#build-matrix).
867
872
 
868
- #### Info for semaphoreapp.com users
873
+ #### Info for semaphoreci.com users
874
+
875
+ ##### Semaphore 2.0
876
+
877
+ knapack_pro gem supports environment variables provided by Semaphore CI 2.0 to run your tests. You will have to define a few things in `.semaphore/semaphore.yml` config file.
878
+
879
+ * You need to set `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC`. If you don't want to commit secrets in yml file then you can [follow this guide](https://docs.semaphoreci.com/article/66-environment-variables-and-secrets).
880
+ * You need to create as many jobs with unique names (Node 0 - Knapsack Pro, Node 1 - Knapsack Pro etc) as many parallel jobs you want to run. If your test suite is long you should use more parallel jobs.
881
+ * If you have 2 parallel jobs you need to set `KNAPSACK_PRO_CI_NODE_TOTAL=2` for each job.
882
+ * You need to set job index starting from 0 like `KNAPSACK_PRO_CI_NODE_INDEX=0` for Node 0.
883
+
884
+ Below you can find full Semaphore CI 2.0 config for Rails project.
885
+
886
+ ```yaml
887
+ # .semaphore/semaphore.yml
888
+ # Use the latest stable version of Semaphore 2.0 YML syntax:
889
+ version: v1.0
890
+
891
+ # Name your pipeline. In case you connect multiple pipelines with promotions,
892
+ # the name will help you differentiate between, for example, a CI build phase
893
+ # and delivery phases.
894
+ name: Demo Rails 5 app
895
+
896
+ # An agent defines the environment in which your code runs.
897
+ # It is a combination of one of available machine types and operating
898
+ # system images.
899
+ # See https://docs.semaphoreci.com/article/20-machine-types
900
+ # and https://docs.semaphoreci.com/article/32-ubuntu-1804-image
901
+ agent:
902
+ machine:
903
+ type: e1-standard-2
904
+ os_image: ubuntu1804
905
+
906
+ # Blocks are the heart of a pipeline and are executed sequentially.
907
+ # Each block has a task that defines one or more jobs. Jobs define the
908
+ # commands to execute.
909
+ # See https://docs.semaphoreci.com/article/62-concepts
910
+ blocks:
911
+ - name: Setup
912
+ task:
913
+ env_vars:
914
+ - name: RAILS_ENV
915
+ value: test
916
+ jobs:
917
+ - name: bundle
918
+ commands:
919
+ # Checkout code from Git repository. This step is mandatory if the
920
+ # job is to work with your code.
921
+ # Optionally you may use --use-cache flag to avoid roundtrip to
922
+ # remote repository.
923
+ # See https://docs.semaphoreci.com/article/54-toolbox-reference#libcheckout
924
+ - checkout
925
+ # Restore dependencies from cache.
926
+ # Read about caching: https://docs.semaphoreci.com/article/54-toolbox-reference#cache
927
+ - cache restore gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock),gems-$SEMAPHORE_GIT_BRANCH-,gems-master-
928
+ # Set Ruby version:
929
+ - sem-version ruby 2.6.1
930
+ - bundle install --jobs=4 --retry=3 --path vendor/bundle
931
+ # Store the latest version of dependencies in cache,
932
+ # to be used in next blocks and future workflows:
933
+ - cache store gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock) vendor/bundle
934
+
935
+ - name: RSpec tests
936
+ task:
937
+ env_vars:
938
+ - name: RAILS_ENV
939
+ value: test
940
+ - name: PGHOST
941
+ value: 127.0.0.1
942
+ - name: PGUSER
943
+ value: postgres
944
+ - name: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC
945
+ value: your_api_token_here
946
+ # This block runs two jobs in parallel and they both share common
947
+ # setup steps. We can group them in a prologue.
948
+ # See https://docs.semaphoreci.com/article/50-pipeline-yaml#prologue
949
+ prologue:
950
+ commands:
951
+ - checkout
952
+ - cache restore gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock),gems-$SEMAPHORE_GIT_BRANCH-,gems-master-
953
+ # Start Postgres database service.
954
+ # See https://docs.semaphoreci.com/article/54-toolbox-reference#sem-service
955
+ - sem-service start postgres
956
+ - sem-version ruby 2.6.1
957
+ - bundle install --jobs=4 --retry=3 --path vendor/bundle
958
+ - bundle exec rake db:setup
959
+
960
+ jobs:
961
+ - name: Node 0 - Knapsack Pro
962
+ commands:
963
+ - KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:queue:rspec
964
+
965
+ - name: Node 1 - Knapsack Pro
966
+ commands:
967
+ - KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=1 bundle exec rake knapsack_pro:queue:rspec
968
+ ```
969
+
970
+ ##### Semaphore 1.0
869
971
 
870
972
  Knapsack Pro supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_CURRENT_THREAD`. The only thing you need to do is set up knapsack_pro rspec/cucumber/minitest/test_unit command for as many threads as you need. Here is an example:
871
973
 
@@ -1346,6 +1448,25 @@ FactoryBot.define do
1346
1448
  end
1347
1449
  ```
1348
1450
 
1451
+ ##### Why when I use Queue Mode for RSpec then my rake tasks are run twice?
1452
+
1453
+ Why rake tasks are being ran twice in Queue Mode? If you have tests for your rake task then you want to ensure you clear the rake task before loading it inside of test file.
1454
+ In Queue Mode the rake task could be already loaded and loading it again in test file may result in running the task twice.
1455
+
1456
+ ```ruby
1457
+ before do
1458
+ # Clear rake task from memory if it was already loaded.
1459
+ # This ensures rake task is loaded only once in knapsack_pro Queue Mode.
1460
+ Rake::Task[task_name].clear if Rake::Task.task_defined?(task_name)
1461
+
1462
+ # loaad rake task only once here
1463
+ Rake.application.rake_require("tasks/dummy")
1464
+ Rake::Task.define_task(:environment)
1465
+ end
1466
+ ```
1467
+
1468
+ Here is the full [example how to test rake task along with dummy rake task](https://github.com/KnapsackPro/rails-app-with-knapsack_pro/commit/9f068e900deb3554bd72633e8d61c1cc7f740306) from our example rails project.
1469
+
1349
1470
  ##### Why when I use Queue Mode for RSpec then I see error `superclass mismatch for class`?
1350
1471
 
1351
1472
  You may see error like:
@@ -2022,7 +2143,9 @@ To ensure everything works you can check output for each CI node.
2022
2143
 
2023
2144
  Flaky (nondeterministic) tests, are tests that exhibit both a passing and a failing result with the same code.
2024
2145
 
2025
- You can use [only failures option in RSpec](https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures) to rerun failed tests.
2146
+ I recommend to use [rspec-retry](https://github.com/NoRedInk/rspec-retry) gem that can retry failing test. It can be useful for randomly failing features specs. For instance you can configure it to retry 3 times features test before marking it as failing.
2147
+
2148
+ Alternative way is to use built into [RSpec only failures option](https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures) to rerun failed tests.
2026
2149
 
2027
2150
  Please add to your RSpec configuration:
2028
2151
 
@@ -2146,7 +2269,7 @@ The test file pattern and exclude pattern support any glob pattern handled by [`
2146
2269
 
2147
2270
  #### How to use CodeClimate with knapsack_pro?
2148
2271
 
2149
- You can check CodeClimate docs about [parallel and multiple test suites](https://docs.codeclimate.com/docs/configuring-test-coverage#section-parallel-and-multiple-test-suites).
2272
+ You can check CodeClimate docs about [parallel tests](https://docs.codeclimate.com/docs/configuring-test-coverage#section-parallel-tests) and [multiple test suites](https://docs.codeclimate.com/docs/configuring-test-coverage#section-multiple-test-suites).
2150
2273
 
2151
2274
  #### How to run knapsack_pro only on a few parallel CI nodes instead of all?
2152
2275
 
data/lib/knapsack_pro.rb CHANGED
@@ -16,6 +16,7 @@ require_relative 'knapsack_pro/config/ci/circle'
16
16
  require_relative 'knapsack_pro/config/ci/cirrus_ci'
17
17
  require_relative 'knapsack_pro/config/ci/gitlab_ci'
18
18
  require_relative 'knapsack_pro/config/ci/semaphore'
19
+ require_relative 'knapsack_pro/config/ci/semaphore2'
19
20
  require_relative 'knapsack_pro/config/ci/buildkite'
20
21
  require_relative 'knapsack_pro/config/ci/travis'
21
22
  require_relative 'knapsack_pro/config/ci/snap_ci'
@@ -0,0 +1,34 @@
1
+ # https://docs.semaphoreci.com/article/12-environment-variables
2
+ module KnapsackPro
3
+ module Config
4
+ module CI
5
+ class Semaphore2 < Base
6
+ def node_total
7
+ # not provided
8
+ end
9
+
10
+ def node_index
11
+ # not provided
12
+ end
13
+
14
+ def node_build_id
15
+ ENV['SEMAPHORE_WORKFLOW_ID']
16
+ end
17
+
18
+ def commit_hash
19
+ ENV['SEMAPHORE_GIT_SHA']
20
+ end
21
+
22
+ def branch
23
+ ENV['SEMAPHORE_GIT_BRANCH']
24
+ end
25
+
26
+ def project_dir
27
+ if ENV['HOME'] && ENV['SEMAPHORE_GIT_DIR']
28
+ "#{ENV['HOME']}/#{ENV['SEMAPHORE_GIT_DIR']}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -0,0 +1,96 @@
1
+ describe KnapsackPro::Config::CI::Semaphore2 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 environment exists' do
26
+ let(:env) { { 'SEMAPHORE_WORKFLOW_ID' => 123 } }
27
+ it { should eql 123 }
28
+ end
29
+
30
+ context "when environment doesn't exist" do
31
+ it { should be nil }
32
+ end
33
+ end
34
+
35
+ describe '#commit_hash' do
36
+ subject { described_class.new.commit_hash }
37
+
38
+ context 'when environment exists' do
39
+ let(:env) { { 'SEMAPHORE_GIT_SHA' => '4323320992a21b1169e3ac5b7789d379597738e6' } }
40
+ it { should eql '4323320992a21b1169e3ac5b7789d379597738e6' }
41
+ end
42
+
43
+ context "when environment doesn't exist" do
44
+ it { should be nil }
45
+ end
46
+ end
47
+
48
+ describe '#branch' do
49
+ subject { described_class.new.branch }
50
+
51
+ context 'when environment exists' do
52
+ let(:env) { { 'SEMAPHORE_GIT_BRANCH' => 'master' } }
53
+ it { should eql 'master' }
54
+ end
55
+
56
+ context "when environment doesn't exist" do
57
+ it { should be nil }
58
+ end
59
+ end
60
+
61
+ describe '#project_dir' do
62
+ subject { described_class.new.project_dir }
63
+
64
+ context 'when HOME and SEMAPHORE_GIT_DIR environments exist' do
65
+ let(:env) do
66
+ {
67
+ 'HOME' => '/home/semaphore',
68
+ 'SEMAPHORE_GIT_DIR' => 'project-name',
69
+ }
70
+ end
71
+ it { should eql '/home/semaphore/project-name' }
72
+ end
73
+
74
+ context 'when only HOME environment exists' do
75
+ let(:env) do
76
+ {
77
+ 'HOME' => '/home/semaphore',
78
+ }
79
+ end
80
+ it { should be nil }
81
+ end
82
+
83
+ context 'when only SEMAPHORE_GIT_DIR environment exists' do
84
+ let(:env) do
85
+ {
86
+ 'SEMAPHORE_GIT_DIR' => 'project-name'
87
+ }
88
+ end
89
+ it { should be nil }
90
+ end
91
+
92
+ context "when environments don't exist" do
93
+ it { should be nil }
94
+ end
95
+ end
96
+ 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: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-03 00:00:00.000000000 Z
11
+ date: 2019-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -242,6 +242,7 @@ files:
242
242
  - lib/knapsack_pro/config/ci/gitlab_ci.rb
243
243
  - lib/knapsack_pro/config/ci/heroku.rb
244
244
  - lib/knapsack_pro/config/ci/semaphore.rb
245
+ - lib/knapsack_pro/config/ci/semaphore2.rb
245
246
  - lib/knapsack_pro/config/ci/snap_ci.rb
246
247
  - lib/knapsack_pro/config/ci/solano_ci.rb
247
248
  - lib/knapsack_pro/config/ci/travis.rb
@@ -322,6 +323,7 @@ files:
322
323
  - spec/knapsack_pro/config/ci/codeship_spec.rb
323
324
  - spec/knapsack_pro/config/ci/gitlab_ci_spec.rb
324
325
  - spec/knapsack_pro/config/ci/heroku_spec.rb
326
+ - spec/knapsack_pro/config/ci/semaphore2_spec.rb
325
327
  - spec/knapsack_pro/config/ci/semaphore_spec.rb
326
328
  - spec/knapsack_pro/config/ci/snap_ci_spec.rb
327
329
  - spec/knapsack_pro/config/ci/solano_ci_spec.rb
@@ -431,6 +433,7 @@ test_files:
431
433
  - spec/knapsack_pro/config/ci/codeship_spec.rb
432
434
  - spec/knapsack_pro/config/ci/gitlab_ci_spec.rb
433
435
  - spec/knapsack_pro/config/ci/heroku_spec.rb
436
+ - spec/knapsack_pro/config/ci/semaphore2_spec.rb
434
437
  - spec/knapsack_pro/config/ci/semaphore_spec.rb
435
438
  - spec/knapsack_pro/config/ci/snap_ci_spec.rb
436
439
  - spec/knapsack_pro/config/ci/solano_ci_spec.rb