Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/knapsack_pro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
31 changes: 31 additions & 0 deletions lib/knapsack_pro/config/ci/heroku.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the project directory is always in /app directory on Heroku CI.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is as far as I know, and .git is not present.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikescar Ok. Actually, we don't need to care about project_dir when Heroku provides branch and git commit via ENV vars. I use project_dir only when I need to detect branch/git hash because they are not available via ENV for CI provider. In case of Heroku they expose branch/git hash so we should be good. The knapsack_pro won't use project_dir.

end
end
end
end
end
87 changes: 87 additions & 0 deletions spec/knapsack_pro/config/ci/heroku_spec.rb
Original file line number Diff line number Diff line change
@@ -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