From 96c915cb1c5ff525f64f042231761604282c5c07 Mon Sep 17 00:00:00 2001 From: ArturT Date: Wed, 8 Nov 2017 21:27:46 +0100 Subject: [PATCH 1/5] Add support for Heroku environment variables. --- lib/knapsack_pro.rb | 1 + lib/knapsack_pro/config/ci/heroku.rb | 31 +++++++++ spec/knapsack_pro/config/ci/heroku_spec.rb | 73 ++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 lib/knapsack_pro/config/ci/heroku.rb create mode 100644 spec/knapsack_pro/config/ci/heroku_spec.rb diff --git a/lib/knapsack_pro.rb b/lib/knapsack_pro.rb index c32db3f0..b2394165 100644 --- a/lib/knapsack_pro.rb +++ b/lib/knapsack_pro.rb @@ -19,6 +19,7 @@ require_relative 'knapsack_pro/config/ci/travis' require_relative 'knapsack_pro/config/ci/snap_ci' require_relative 'knapsack_pro/config/ci/codeship' +require_relative 'knapsack_pro/config/ci/heroku' require_relative 'knapsack_pro/config/env' require_relative 'knapsack_pro/config/env_generator' require_relative 'knapsack_pro/client/api/action' diff --git a/lib/knapsack_pro/config/ci/heroku.rb b/lib/knapsack_pro/config/ci/heroku.rb new file mode 100644 index 00000000..9b6f6725 --- /dev/null +++ b/lib/knapsack_pro/config/ci/heroku.rb @@ -0,0 +1,31 @@ +module KnapsackPro + module Config + module CI + class Heroku < Base + def node_total + # not provided + end + + def node_index + # not provided + end + + def node_build_id + ENV['HEROKU_TEST_RUN_ID'] + end + + def commit_hash + ENV['HEROKU_TEST_RUN_COMMIT_VERSION'] + end + + def branch + ENV['HEROKU_TEST_RUN_BRANCH'] + end + + def project_dir + '/app' if node_build_id + end + end + end + end +end diff --git a/spec/knapsack_pro/config/ci/heroku_spec.rb b/spec/knapsack_pro/config/ci/heroku_spec.rb new file mode 100644 index 00000000..52ceb636 --- /dev/null +++ b/spec/knapsack_pro/config/ci/heroku_spec.rb @@ -0,0 +1,73 @@ +describe KnapsackPro::Config::CI::Heroku do + let(:env) { {} } + + before do + stub_const('ENV', env) + end + + it { should be_kind_of KnapsackPro::Config::CI::Base } + + describe '#node_total' do + subject { described_class.new.node_total } + + it { should be nil } + end + + describe '#node_index' do + subject { described_class.new.node_index } + + it { should be nil } + end + + describe '#node_build_id' do + subject { described_class.new.node_build_id } + + context 'when environment exists' do + let(:env) { { 'HEROKU_TEST_RUN_ID' => 1234 } } + it { should eql 1234 } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end + + describe '#commit_hash' do + subject { described_class.new.commit_hash } + + context 'when environment exists' do + let(:env) { { 'HEROKU_TEST_RUN_COMMIT_VERSION' => 'abbaec3ee5d334fd658da35646b42bc5' } } + it { should eql 'abbaec3ee5d334fd658da35646b42bc5' } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end + + describe '#branch' do + subject { described_class.new.branch } + + context 'when environment exists' do + let(:env) { { 'HEROKU_TEST_RUN_BRANCH' => 'master' } } + it { should eql 'master' } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end + + describe '#project_dir' do + subject { described_class.new.project_dir } + + context 'when environment exists' do + let(:env) { { 'HEROKU_TEST_RUN_ID' => 1234 } } + it { should eq '/app' } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end +end From b76ce0c1f34c88ce9f3cdb03644ea46a42203468 Mon Sep 17 00:00:00 2001 From: ArturT Date: Wed, 8 Nov 2017 21:29:29 +0100 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e671a084..5a5f0392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ * TODO +### 0.53.0 + +* Add support for Heroku CI environment variables. + + https://github.com/KnapsackPro/knapsack_pro-ruby/pull/55 + +https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.52.0...v0.53.0 + ### 0.52.0 * Add support for Cucumber 3. From 052a541865e657030e58daf30dfa853d279ae67b Mon Sep 17 00:00:00 2001 From: ArturT Date: Fri, 10 Nov 2017 10:28:59 +0100 Subject: [PATCH 3/5] Add Heroku support for CI_NODE_TOTAL and CI_NODE_INDEX --- lib/knapsack_pro/config/ci/heroku.rb | 4 ++-- spec/knapsack_pro/config/ci/heroku_spec.rb | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/knapsack_pro/config/ci/heroku.rb b/lib/knapsack_pro/config/ci/heroku.rb index 9b6f6725..732d8ea0 100644 --- a/lib/knapsack_pro/config/ci/heroku.rb +++ b/lib/knapsack_pro/config/ci/heroku.rb @@ -3,11 +3,11 @@ module Config module CI class Heroku < Base def node_total - # not provided + ENV['CI_NODE_TOTAL'] end def node_index - # not provided + ENV['CI_NODE_INDEX'] end def node_build_id diff --git a/spec/knapsack_pro/config/ci/heroku_spec.rb b/spec/knapsack_pro/config/ci/heroku_spec.rb index 52ceb636..209378f4 100644 --- a/spec/knapsack_pro/config/ci/heroku_spec.rb +++ b/spec/knapsack_pro/config/ci/heroku_spec.rb @@ -10,13 +10,27 @@ describe '#node_total' do subject { described_class.new.node_total } - it { should be nil } + context 'when environment exists' do + let(:env) { { 'CI_NODE_TOTAL' => 4 } } + it { should eql 4 } + end + + context "when environment doesn't exist" do + it { should be nil } + end end describe '#node_index' do subject { described_class.new.node_index } - it { should be nil } + context 'when environment exists' do + let(:env) { { 'CI_NODE_INDEX' => 3 } } + it { should eql 3 } + end + + context "when environment doesn't exist" do + it { should be nil } + end end describe '#node_build_id' do From 061464a54b9d4d6aeff5075b97f96717d8cb07df Mon Sep 17 00:00:00 2001 From: ArturT Date: Fri, 10 Nov 2017 13:42:29 +0100 Subject: [PATCH 4/5] Add info how to configure Heroku CI --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index 9fd23755..e59fbb53 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ The knapsack_pro has also [queue mode](#queue-mode) to get an optimal test suite - [Info for buildkite.com users](#info-for-buildkitecom-users) - [Info for Gitlab CI users](#info-for-gitlab-ci-users) - [Info for codeship.com users](#info-for-codeshipcom-users) + - [Info for Heroku CI users](#info-for-heroku-ci-users) - [Info for snap-ci.com users](#info-for-snap-cicom-users) - [Info for Jenkins users](#info-for-jenkins-users) - [FAQ](#faq) @@ -900,6 +901,42 @@ KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=1 bundle exec rake knaps Remember to add API tokens like `KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER` and `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` to `Environment` page of your project settings in Codeship. +#### Info for Heroku CI users + +You can parallelize your tests on Heroku CI by configuring `app.json`. + +You can set how many parallel dynos with tests you want to run with `quantity` value. +Use `test` key to run knapsack_pro gem. + +You need to specify also the environment variable with API token for Knapsack Pro. +For any sensitive environment variables (like Knapsack Pro API token) that you do not want in your `app.json` manifest, you can add them to your pipeline’s Heroku CI settings. + +``` +# app.json +{ + "environments": { + "test": { + "formation": { + "test": { + "quantity": 2 + } + }, + "addons": [ + "heroku-postgresql" + ], + "scripts": { + "test": "bundle exec rake knapsack_pro:rspec" + }, + "env": { + "KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC": "rspec-token" + } + } + } +} +``` + +You can learn more about [Heroku CI](https://devcenter.heroku.com/articles/heroku-ci) and about the [Heroku CI parallelization](https://devcenter.heroku.com/articles/heroku-ci-parallel-test-runs). + #### Info for snap-ci.com users 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: From 5091cef65db20d8be36398bb82051172ef28f169 Mon Sep 17 00:00:00 2001 From: ArturT Date: Sat, 11 Nov 2017 17:00:42 +0100 Subject: [PATCH 5/5] Add info how to enabled parallelization on Heroku CI --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e59fbb53..58be3f2a 100644 --- a/README.md +++ b/README.md @@ -911,6 +911,8 @@ Use `test` key to run knapsack_pro gem. You need to specify also the environment variable with API token for Knapsack Pro. For any sensitive environment variables (like Knapsack Pro API token) that you do not want in your `app.json` manifest, you can add them to your pipeline’s Heroku CI settings. +Note the [Heroku CI Parallel Test Runs](https://devcenter.heroku.com/articles/heroku-ci-parallel-test-runs) are in Beta and you may need to ask Heroku support to enabled it for your project. + ``` # app.json { @@ -935,7 +937,7 @@ For any sensitive environment variables (like Knapsack Pro API token) that you d } ``` -You can learn more about [Heroku CI](https://devcenter.heroku.com/articles/heroku-ci) and about the [Heroku CI parallelization](https://devcenter.heroku.com/articles/heroku-ci-parallel-test-runs). +You can learn more about [Heroku CI](https://devcenter.heroku.com/articles/heroku-ci). #### Info for snap-ci.com users