knapsack_pro 1.13.0 → 1.14.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 +8 -0
- data/README.md +107 -0
- data/knapsack_pro.gemspec +2 -2
- data/lib/knapsack_pro.rb +1 -0
- data/lib/knapsack_pro/config/ci/github_actions.rb +34 -0
- data/lib/knapsack_pro/version.rb +1 -1
- data/spec/knapsack_pro/config/ci/github_actions_spec.rb +84 -0
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9d0dccb9e9eb3866b7a27653dafa2fff75cc46bef7c1ed45741e1ce6ddff8cb
|
4
|
+
data.tar.gz: aa1d8861fe22cf070b271153e64f73cadacc7781e13d98eeead1da0070a2b117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1aa79fcdb37b38e263ac3fc06ff44d5c2c78d7f75b60428a16edeb5ec766ce1b9fbbe518ef22d14be608ba604b270093d2f3b5db77a83ac8fcfde7d6ffa11a34
|
7
|
+
data.tar.gz: 26fb92a07819d8d21fefe462fef1236e6ba6baa1672ce6edefd6d2e6c6cfcd2e8b8bec81c3371700ba07697e683313aeb66eeb5e74246340982fcc5685f37ba6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 1.14.0
|
4
|
+
|
5
|
+
* Add support for GitHub Actions
|
6
|
+
|
7
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/90
|
8
|
+
|
9
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v1.13.0...v1.14.0
|
10
|
+
|
3
11
|
### 1.13.0
|
4
12
|
|
5
13
|
* Add support for job index and job count for parallelism in Semaphore 2.0
|
data/README.md
CHANGED
@@ -112,6 +112,7 @@ You can see list of questions for common problems and tips in below [Table of Co
|
|
112
112
|
- [Info for snap-ci.com users](#info-for-snap-cicom-users)
|
113
113
|
- [Info for cirrus-ci.org users](#info-for-cirrus-ciorg-users)
|
114
114
|
- [Info for Jenkins users](#info-for-jenkins-users)
|
115
|
+
- [Info for GitHub Actions users](#info-for-github-actions-users)
|
115
116
|
- [FAQ](#faq)
|
116
117
|
- [Common problems](#common-problems)
|
117
118
|
- [Why I see API error commit_hash parameter is required?](#why-i-see-api-error-commit_hash-parameter-is-required)
|
@@ -987,7 +988,21 @@ blocks:
|
|
987
988
|
- name: Run tests with Knapsack Pro
|
988
989
|
parallelism: 2
|
989
990
|
commands:
|
991
|
+
# Step for RSpec in Queue Mode
|
990
992
|
- bundle exec rake knapsack_pro:queue:rspec
|
993
|
+
# Step for Cucumber in Queue Mode
|
994
|
+
- bundle exec rake knapsack_pro:queue:cucumber
|
995
|
+
|
996
|
+
# Step for RSpec in Regular Mode
|
997
|
+
- bundle exec rake knapsack_pro:rspec
|
998
|
+
# Step for Cucumber in Regular Mode
|
999
|
+
- bundle exec rake knapsack_pro:cucumber
|
1000
|
+
# Step for Minitest in Regular Mode
|
1001
|
+
- bundle exec rake knapsack_pro:minitest
|
1002
|
+
# Step for test-unit in Regular Mode
|
1003
|
+
- bundle exec rake knapsack_pro:test_unit
|
1004
|
+
# Step for Spinach in Regular Mode
|
1005
|
+
- bundle exec rake knapsack_pro:spinach
|
991
1006
|
```
|
992
1007
|
|
993
1008
|
##### Semaphore 1.0
|
@@ -1394,6 +1409,98 @@ Here is [list of environment variables per test runner](#set-api-key-token).
|
|
1394
1409
|
Above example shows how to run cucumber tests in regular mode and later the rspec tests in queue mode to autobalance build.
|
1395
1410
|
If you are going to relay on rspec to autobalance build when cucumber tests were not perfectly distributed you should be aware about [possible edge case if your rspec test suite is very short](#why-my-tests-are-executed-twice-in-queue-mode-why-ci-node-runs-whole-test-suite-again).
|
1396
1411
|
|
1412
|
+
#### Info for GitHub Actions users
|
1413
|
+
|
1414
|
+
knapsack_pro gem supports environment variables provided by GitHub Actions to run your tests. You will have to define a few things in `.github/workflows/main.yaml` config file.
|
1415
|
+
|
1416
|
+
* You need to set API token like `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` in GitHub settings -> Secrets for your repository. [Creating and using secrets in GitHub Actions](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables).
|
1417
|
+
* You should create as many parallel jobs as you need with [`matrix` property](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix). If your test suite is slow you should use more parallel jobs. See comment in below config.
|
1418
|
+
|
1419
|
+
Below you can find full GitHub Actions config for Ruby on Rails project.
|
1420
|
+
|
1421
|
+
```yaml
|
1422
|
+
name: Main
|
1423
|
+
|
1424
|
+
on: [push]
|
1425
|
+
|
1426
|
+
jobs:
|
1427
|
+
vm-job:
|
1428
|
+
runs-on: ubuntu-latest
|
1429
|
+
|
1430
|
+
# If you need DB like PostgreSQL then define service below.
|
1431
|
+
# Example for Redis can be found here:
|
1432
|
+
# https://github.com/actions/example-services/tree/master/.github/workflows
|
1433
|
+
services:
|
1434
|
+
postgres:
|
1435
|
+
image: postgres:10.8
|
1436
|
+
env:
|
1437
|
+
POSTGRES_USER: postgres
|
1438
|
+
POSTGRES_PASSWORD: ""
|
1439
|
+
POSTGRES_DB: postgres
|
1440
|
+
ports:
|
1441
|
+
# will assign a random free host port
|
1442
|
+
- 5432/tcp
|
1443
|
+
# needed because the postgres container does not provide a healthcheck
|
1444
|
+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
1445
|
+
|
1446
|
+
strategy:
|
1447
|
+
matrix:
|
1448
|
+
# Set N number of parallel jobs you want to run tests on.
|
1449
|
+
# Use higher number if you have slow tests to split them on more parallel jobs.
|
1450
|
+
# Remember to update ci_node_index below to 0..N-1
|
1451
|
+
ci_node_total: [2]
|
1452
|
+
# set N-1 indexes for parallel jobs
|
1453
|
+
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
|
1454
|
+
ci_node_index: [0, 1]
|
1455
|
+
|
1456
|
+
steps:
|
1457
|
+
- uses: actions/checkout@v1
|
1458
|
+
|
1459
|
+
- name: Set up Ruby 2.6
|
1460
|
+
uses: actions/setup-ruby@v1
|
1461
|
+
with:
|
1462
|
+
ruby-version: 2.6.3
|
1463
|
+
|
1464
|
+
# required to compile pg ruby gem
|
1465
|
+
- name: install PostgreSQL client
|
1466
|
+
run: sudo apt-get install libpq-dev
|
1467
|
+
|
1468
|
+
- name: Build and create DB
|
1469
|
+
env:
|
1470
|
+
# use localhost for the host here because we have specified a container for the job.
|
1471
|
+
# If we were running the job on the VM this would be postgres
|
1472
|
+
PGHOST: localhost
|
1473
|
+
PGUSER: postgres
|
1474
|
+
PGPORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
|
1475
|
+
RAILS_ENV: test
|
1476
|
+
run: |
|
1477
|
+
gem install bundler
|
1478
|
+
bundle install --jobs 4 --retry 3
|
1479
|
+
bin/rails db:setup
|
1480
|
+
|
1481
|
+
- name: Run tests
|
1482
|
+
env:
|
1483
|
+
PGHOST: localhost
|
1484
|
+
PGUSER: postgres
|
1485
|
+
PGPORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
|
1486
|
+
RAILS_ENV: test
|
1487
|
+
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}
|
1488
|
+
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
|
1489
|
+
KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
|
1490
|
+
run: |
|
1491
|
+
# run tests in Knapsack Pro Regular Mode
|
1492
|
+
bundle exec rake knapsack_pro:rspec
|
1493
|
+
bundle exec rake knapsack_pro:cucumber
|
1494
|
+
bundle exec rake knapsack_pro:minitest
|
1495
|
+
bundle exec rake knapsack_pro:test_unit
|
1496
|
+
bundle exec rake knapsack_pro:spinach
|
1497
|
+
|
1498
|
+
# you can use Knapsack Pro in Queue Mode once recorded first CI build with Regular Mode
|
1499
|
+
bundle exec rake knapsack_pro:queue:rspec
|
1500
|
+
bundle exec rake knapsack_pro:queue:cucumber
|
1501
|
+
bundle exec rake knapsack_pro:queue:minitest
|
1502
|
+
```
|
1503
|
+
|
1397
1504
|
## FAQ
|
1398
1505
|
|
1399
1506
|
### Common problems
|
data/knapsack_pro.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = KnapsackPro::VERSION
|
9
9
|
spec.authors = ['ArturT']
|
10
10
|
spec.email = ['arturtrzop@gmail.com']
|
11
|
-
spec.summary = %q{Knapsack Pro splits tests across CI nodes and
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Knapsack Pro splits tests across parallel CI nodes and ensures each parallel job finish work at a similar time.}
|
12
|
+
spec.description = %q{Run tests in parallel across CI server nodes based on tests execution time. Split tests in a dynamic way to ensure parallel jobs are done at a similar time. Thanks to that your CI build time is as fast as possible. It works with many CI providers.}
|
13
13
|
spec.homepage = 'https://knapsackpro.com'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.metadata = {
|
data/lib/knapsack_pro.rb
CHANGED
@@ -22,6 +22,7 @@ require_relative 'knapsack_pro/config/ci/travis'
|
|
22
22
|
require_relative 'knapsack_pro/config/ci/snap_ci'
|
23
23
|
require_relative 'knapsack_pro/config/ci/solano_ci'
|
24
24
|
require_relative 'knapsack_pro/config/ci/codeship'
|
25
|
+
require_relative 'knapsack_pro/config/ci/github_actions'
|
25
26
|
require_relative 'knapsack_pro/config/ci/heroku'
|
26
27
|
require_relative 'knapsack_pro/config/env'
|
27
28
|
require_relative 'knapsack_pro/config/env_generator'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# https://help.github.com/en/articles/virtual-environments-for-github-actions#environment-variables
|
2
|
+
module KnapsackPro
|
3
|
+
module Config
|
4
|
+
module CI
|
5
|
+
class GithubActions < 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
|
+
# not provided
|
16
|
+
end
|
17
|
+
|
18
|
+
def commit_hash
|
19
|
+
ENV['GITHUB_SHA']
|
20
|
+
end
|
21
|
+
|
22
|
+
def branch
|
23
|
+
# GITHUB_REF - The branch or tag ref that triggered the workflow. For example, refs/heads/feature-branch-1.
|
24
|
+
# If neither a branch or tag is available for the event type, the variable will not exist.
|
25
|
+
ENV['GITHUB_REF'] || ENV['GITHUB_SHA']
|
26
|
+
end
|
27
|
+
|
28
|
+
def project_dir
|
29
|
+
ENV['GITHUB_WORKSPACE']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/knapsack_pro/version.rb
CHANGED
@@ -0,0 +1,84 @@
|
|
1
|
+
describe KnapsackPro::Config::CI::GithubActions 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
|
+
it { should be nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#commit_hash' do
|
29
|
+
subject { described_class.new.commit_hash }
|
30
|
+
|
31
|
+
context 'when environment exists' do
|
32
|
+
let(:env) { { 'GITHUB_SHA' => '2e13512fc230d6f9ebf4923352718e4d' } }
|
33
|
+
it { should eql '2e13512fc230d6f9ebf4923352718e4d' }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when environment doesn't exist" do
|
37
|
+
it { should be nil }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#branch' do
|
42
|
+
subject { described_class.new.branch }
|
43
|
+
|
44
|
+
context 'when environment exists' do
|
45
|
+
context 'when GITHUB_REF has value' do
|
46
|
+
let(:env) do
|
47
|
+
{
|
48
|
+
'GITHUB_REF' => 'master',
|
49
|
+
'GITHUB_SHA' => '2e13512fc230d6f9ebf4923352718e4d',
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
it { should eql 'master' }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when GITHUB_REF is not set' do
|
57
|
+
let(:env) do
|
58
|
+
{
|
59
|
+
'GITHUB_SHA' => '2e13512fc230d6f9ebf4923352718e4d',
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
it { should eql '2e13512fc230d6f9ebf4923352718e4d' }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when environment doesn't exist" do
|
68
|
+
it { should be nil }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#project_dir' do
|
73
|
+
subject { described_class.new.project_dir }
|
74
|
+
|
75
|
+
context 'when environment exists' do
|
76
|
+
let(:env) { { 'GITHUB_WORKSPACE' => '/home/runner/work/my-repo-name/my-repo-name' } }
|
77
|
+
it { should eql '/home/runner/work/my-repo-name/my-repo-name' }
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when environment doesn't exist" do
|
81
|
+
it { should be nil }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
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
|
+
version: 1.14.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-
|
11
|
+
date: 2019-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -198,8 +198,10 @@ dependencies:
|
|
198
198
|
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: 0.1.0
|
201
|
-
description:
|
202
|
-
|
201
|
+
description: Run tests in parallel across CI server nodes based on tests execution
|
202
|
+
time. Split tests in a dynamic way to ensure parallel jobs are done at a similar
|
203
|
+
time. Thanks to that your CI build time is as fast as possible. It works with many
|
204
|
+
CI providers.
|
203
205
|
email:
|
204
206
|
- arturtrzop@gmail.com
|
205
207
|
executables:
|
@@ -239,6 +241,7 @@ files:
|
|
239
241
|
- lib/knapsack_pro/config/ci/circle.rb
|
240
242
|
- lib/knapsack_pro/config/ci/cirrus_ci.rb
|
241
243
|
- lib/knapsack_pro/config/ci/codeship.rb
|
244
|
+
- lib/knapsack_pro/config/ci/github_actions.rb
|
242
245
|
- lib/knapsack_pro/config/ci/gitlab_ci.rb
|
243
246
|
- lib/knapsack_pro/config/ci/heroku.rb
|
244
247
|
- lib/knapsack_pro/config/ci/semaphore.rb
|
@@ -323,6 +326,7 @@ files:
|
|
323
326
|
- spec/knapsack_pro/config/ci/circle_spec.rb
|
324
327
|
- spec/knapsack_pro/config/ci/cirrus_ci_spec.rb
|
325
328
|
- spec/knapsack_pro/config/ci/codeship_spec.rb
|
329
|
+
- spec/knapsack_pro/config/ci/github_actions_spec.rb
|
326
330
|
- spec/knapsack_pro/config/ci/gitlab_ci_spec.rb
|
327
331
|
- spec/knapsack_pro/config/ci/heroku_spec.rb
|
328
332
|
- spec/knapsack_pro/config/ci/semaphore2_spec.rb
|
@@ -404,8 +408,8 @@ requirements: []
|
|
404
408
|
rubygems_version: 3.0.3
|
405
409
|
signing_key:
|
406
410
|
specification_version: 4
|
407
|
-
summary: Knapsack Pro splits tests across CI nodes and
|
408
|
-
|
411
|
+
summary: Knapsack Pro splits tests across parallel CI nodes and ensures each parallel
|
412
|
+
job finish work at a similar time.
|
409
413
|
test_files:
|
410
414
|
- spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/invalid_test_suite_token.yml
|
411
415
|
- spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/success.yml
|
@@ -434,6 +438,7 @@ test_files:
|
|
434
438
|
- spec/knapsack_pro/config/ci/circle_spec.rb
|
435
439
|
- spec/knapsack_pro/config/ci/cirrus_ci_spec.rb
|
436
440
|
- spec/knapsack_pro/config/ci/codeship_spec.rb
|
441
|
+
- spec/knapsack_pro/config/ci/github_actions_spec.rb
|
437
442
|
- spec/knapsack_pro/config/ci/gitlab_ci_spec.rb
|
438
443
|
- spec/knapsack_pro/config/ci/heroku_spec.rb
|
439
444
|
- spec/knapsack_pro/config/ci/semaphore2_spec.rb
|