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. diff --git a/README.md b/README.md index 9fd23755..58be3f2a 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,44 @@ 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. + +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 +{ + "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). + #### 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: 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..732d8ea0 --- /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 + ENV['CI_NODE_TOTAL'] + end + + def node_index + ENV['CI_NODE_INDEX'] + 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..209378f4 --- /dev/null +++ b/spec/knapsack_pro/config/ci/heroku_spec.rb @@ -0,0 +1,87 @@ +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 } + + 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 } + + 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 + 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