Skip to content

Commit bce2093

Browse files
3v0k4ArturT
andauthored
chore: document knapsack to knapsack_pro
Co-authored-by: Artur Trzop <[email protected]>
1 parent 71356e9 commit bce2093

File tree

4 files changed

+114
-26
lines changed

4 files changed

+114
-26
lines changed

.github/assets/knapsack-diamonds.png

17.2 KB
Loading

MIGRATE_TO_KNAPSACK_PRO.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Migration steps: from Knapsack to Knapsack Pro
2+
3+
Follow these steps to migrate from `knapsack` to `knapsack_pro` in 10 minutes.
4+
5+
Commands are provided to help you with each step.
6+
7+
> [!TIP]
8+
> On Linux, you need to remove the `''` part from the `sed` commands. Also, you can ignore the `sed: no input files` warning that is printed when there's no substitution to perform.
9+
10+
## Steps
11+
12+
- [ ] Remove the `knapsack` gem:
13+
```bash
14+
bundle remove knapsack
15+
```
16+
17+
- [ ] Remove `Knapsack.load_tasks` from the `Rakefile` if present:
18+
```bash
19+
sed -i '' '/Knapsack\.load_tasks/d' Rakefile
20+
```
21+
22+
- [ ] Replace `require "knapsack"` with `require "knapsack_pro"`:
23+
```bash
24+
grep --files-with-matches --recursive "require.*knapsack" . | xargs sed -i '' "s/'knapsack'/'knapsack_pro'/g"
25+
grep --files-with-matches --recursive "require.*knapsack" . | xargs sed -i '' 's/"knapsack"/"knapsack_pro"/g'
26+
```
27+
28+
- [ ] Remove the following code from the test runner configuration:
29+
```diff
30+
- Knapsack.tracker.config({
31+
- enable_time_offset_warning: true,
32+
- time_offset_in_seconds: 30
33+
- })
34+
35+
- Knapsack.report.config({
36+
- test_file_pattern: 'spec/**{,/*/**}/*_spec.rb', # ⬅️ Take note of this one for later
37+
- report_path: 'knapsack_custom_report.json'
38+
- })
39+
```
40+
41+
- [ ] Replace `Knapsack` with `KnapsackPro`:
42+
```bash
43+
grep --files-with-matches --recursive "Knapsack\." . | xargs sed -i '' 's/Knapsack\./KnapsackPro./g'
44+
grep --files-with-matches --recursive "Knapsack::" . | xargs sed -i '' 's/Knapsack::/KnapsackPro::/g'
45+
```
46+
47+
- [ ] Rename `KnapsackPro::Adapters::RspecAdapter` to `KnapsackPro::Adapters::RSpecAdapter`:
48+
```bash
49+
grep --files-with-matches --recursive "KnapsackPro::Adapters::RspecAdapter" . | xargs sed -i '' 's/RspecAdapter/RSpecAdapter/g'
50+
```
51+
52+
- [ ] Remove any line that mentions `KNAPSACK_GENERATE_REPORT` or `KNAPSACK_REPORT_PATH`:
53+
```bash
54+
grep --files-with-matches --recursive "KNAPSACK_GENERATE_REPORT" . | xargs sed -i '' '/KNAPSACK_GENERATE_REPORT/d'
55+
grep --files-with-matches --recursive "KNAPSACK_REPORT_PATH" . | xargs sed -i '' '/KNAPSACK_REPORT_PATH/d'
56+
```
57+
58+
- [ ] Rename ENVs from `KNAPSACK_X` to `KNAPSACK_PRO_X`:
59+
```bash
60+
grep --files-with-matches --recursive "KNAPSACK_" . | xargs sed -i '' 's/KNAPSACK_/KNAPSACK_PRO_/g'
61+
```
62+
63+
- [ ] Remove all the reports:
64+
```bash
65+
rm knapsack_*_report.json
66+
```
67+
68+
- [ ] [Configure Knapsack Pro](https://docs.knapsackpro.com/knapsack_pro-ruby/guide/)
69+
70+
- [ ] Ensure all the CI commands are updated:
71+
```bash
72+
grep --files-with-matches --recursive "knapsack:spinach" . | xargs sed -i '' 's/knapsack:spinach/knapsack_pro:spinach/g'
73+
grep --files-with-matches --recursive "knapsack:" . | xargs sed -i '' 's/knapsack:/knapsack_pro:queue:/g'
74+
grep --files-with-matches --recursive "CI_NODE_TOTAL" . | xargs sed -i '' 's/CI_NODE_TOTAL/KNAPSACK_PRO_CI_NODE_TOTAL/g'
75+
grep --files-with-matches --recursive "CI_NODE_INDEX" . | xargs sed -i '' 's/CI_NODE_INDEX/KNAPSACK_PRO_CI_NODE_INDEX/g'
76+
```
77+
78+
- [ ] If you removed `test_file_pattern` when deleting `Knapsack.report.config`, use [`KNAPSACK_PRO_TEST_FILE_PATTERN`](https://docs.knapsackpro.com/ruby/reference/#knapsack_pro_test_file_pattern) instead

README.md

+34-26
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
1-
# knapsack gem
1+
# Knapsack
22

3-
Knapsack splits tests evenly across parallel CI nodes to run fast CI build and save you time.
3+
<p align="center">
4+
<a href="https://knapsackpro.com?utm_source=github&utm_medium=readme&utm_campaign=knapsack_gem&utm_content=hero_logo">
5+
<img alt="Knapsack" src="./.github/assets/knapsack-diamonds.png" width="300" height="300" style="max-width: 100%;" />
6+
</a>
7+
</p>
48

5-
| | knapsack gem | knapsack_pro gem |
6-
| -------------------------------------------- | ------------ | ---------------- |
7-
| __Is free__ | ✓ Yes | ✓ Yes, [free plan](https://knapsackpro.com?utm_source=github&utm_medium=readme&utm_campaign=knapsack_gem&utm_content=free_plan) |
8-
| __Regular Mode - a static tests split__ | ✓ Yes | ✓ Yes |
9-
| __Queue Mode - a dynamic tests split__ <br>([ensures all CI nodes finish work at the same time](https://docs.knapsackpro.com/2020/how-to-speed-up-ruby-and-javascript-tests-with-ci-parallelisation)) | No | ✓ Yes |
10-
| __Auto [split slow RSpec test file](https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it) between parallel CI nodes__ <br>(a single test file can be auto split by test examples between parallel jobs) | No | ✓ Yes |
11-
| Tracking tests timing per commit, branch | No | ✓ Yes |
12-
| Support for other programming languages | No | ✓ Yes |
13-
| Support for CI providers | limited | ✓ Yes |
14-
| __Installation README__ | [Install README](http://docs.knapsackpro.com/ruby/knapsack) | [Install README](https://docs.knapsackpro.com) |
9+
<h3 align="center">Speed up your tests</h3>
10+
<p align="center">Run your 1-hour test suite in 2 minutes with optimal parallelisation on your existing CI infrastructure</p>
1511

16-
[Features of knapsack vs knapsack_pro Ruby gem](https://knapsackpro.com/features/ruby_knapsack_pro_vs_knapsack?utm_source=github&utm_medium=readme&utm_campaign=knapsack_gem&utm_content=ruby_knapsack_pro_vs_knapsack)
12+
---
1713

18-
# Do you use Heroku?
14+
<div align="center">
15+
<a href="https://rubygems.org/gems/knapsack">
16+
<img alt="Gem Version" src="https://badge.fury.io/rb/knapsack.svg" />
17+
</a>
18+
</div>
1919

20-
Do you know Knapsack Pro Ruby gem is available as Heroku add-on? It works with your current CI server.
21-
https://elements.heroku.com/addons/knapsack-pro
20+
<br />
21+
<br />
2222

23-
Knapsack Pro has Queue Mode that will split Ruby & JS tests in a dynamic way across parallel CI nodes to ensure each parallel job takes a similar time. Thanks to that there is no bottleneck in your CI pipelines.
23+
Knapsack wraps your current test runner and works with your existing CI infrastructure to split tests optimally.
2424

25-
__See introduction how the Knapsack Pro add-on works__
26-
https://youtu.be/rmXES2N0_QU
25+
It comes in two flavors, `knapsack` and `knapsack_pro`:
2726

28-
You may also find useful article how to run parallel dynos on Heroku CI to complete tests faster
29-
https://docs.knapsackpro.com/2019/how-to-run-tests-faster-on-heroku-ci-with-parallel-dynos
27+
| | `knapsack` | `knapsack_pro` |
28+
| ------------------------------- | ---------- | --------------------------------------- |
29+
| Free ||[Free plan](https://knapsackpro.com?utm_source=github&utm_medium=readme&utm_campaign=knapsack_gem&utm_content=free_plan) |
30+
| Static split |||
31+
| [Dynamic split](https://docs.knapsackpro.com/overview/#queue-mode-dynamic-split) |||
32+
| [Split by test examples](https://docs.knapsackpro.com/ruby/split-by-test-examples/) |||
33+
| Graphs, metrics, and stats |||
34+
| Programming languages | 🤞 (Ruby) | ✅ (Ruby, Cypress, Jest, SDK/API) |
35+
| CI providers | 🤞 Limited | ✅ (All) |
36+
| [Heroku add-on](https://elements.heroku.com/addons/knapsack-pro) |||
37+
| Additional features || 🤘 ([Overview](https://docs.knapsackpro.com/overview/)) |
38+
| | [Install](http://docs.knapsackpro.com/ruby/knapsack) | [Install](https://docs.knapsackpro.com) |
3039

31-
## Do you know
40+
[`knapsack` vs `knapsack_pro` full comparison](https://knapsackpro.com/features/ruby_knapsack_pro_vs_knapsack?utm_source=github&utm_medium=readme&utm_campaign=knapsack_gem&utm_content=ruby_knapsack_pro_vs_knapsack)
3241

33-
* Knapsack Pro is risk-free integration! Knapsack Pro runs tests in Fallback Mode if your CI servers can't reach our API for any reason.
34-
* We don't need access to your repository. Knapsack Pro is just wrapper around test runner like RSpec, Cucumber, Minitest etc.
35-
* Hundreds of developers use Knapsack Pro every day to run fast CI builds.
36-
* It works with other programming languages.
42+
# Migrate from `knapsack` to `knapsack_pro`
43+
44+
If you are already using `knapsack` and want to give `knapsack_pro` a try, here's [how to migrate in 10 minutes](./MIGRATE_TO_KNAPSACK_PRO.md).

spec/knapsack/adapters/rspec_adapter_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'ostruct'
2+
13
describe Knapsack::Adapters::RSpecAdapter do
24
context do
35
before { expect(::RSpec).to receive(:configure) }

0 commit comments

Comments
 (0)