-
Notifications
You must be signed in to change notification settings - Fork 132
Release/improve ci #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Release/improve ci #412
Changes from all commits
Commits
Show all changes
187 commits
Select commit
Hold shift + click to select a range
80a5891
Add knapsack gem
enzofab91 d4672b1
Add total nodes to ci workflow
enzofab91 c0f6052
empty commit to run CI
enzofab91 62f8ea9
empty commit to run CI
enzofab91 18f2c6c
empty commit to run CI
enzofab91 a40547c
empty commit to run CI
enzofab91 691f400
Update CI setup
enzofab91 2e624f0
Move CI_NODE_TOTAL to secrets
enzofab91 27a4dc0
Move CI_NODE_TOTAL to secrets
enzofab91 fc2d158
Move CI_NODE_TOTAL to secrets
enzofab91 0ebfcb9
Move CI_NODE_TOTAL to secrets
enzofab91 51eb9f8
Move CI_NODE_TOTAL to secrets
enzofab91 a23f5ec
split tests and linters
jpascual1994 b685aa8
Fix
enzofab91 57e4b7a
Remove advertisements and warning when running CI
enzofab91 316918a
move harcoded values to secrets with a default value
rodrieiz 682e2ef
move I18n Health check to code:analysis
jpascual1994 b887c00
Merge pull request #403 from rootstrap/parallel-tests-and-linters
jpascual1994 bda5aca
try to set matrix strategy
rodrieiz fa62ac7
queue mode works?
rodrieiz 8b6591e
vars
rodrieiz 91d7b17
Merge branch 'release/improve-ci' into add_knapsack_gem
rodrieiz 62e0105
add parallel gem
grosendo2006 9cdd3a7
Merge pull request #393 from rootstrap/add-parell-test
grosendo2006 c21414b
Merge branch 'release/improve-ci' into add_knapsack_gem
enzofab91 171f2ba
Merge pull request #390 from rootstrap/add_knapsack_gem
enzofab91 413a8c0
Add knapsack gem
enzofab91 e1bee9d
Add total nodes to ci workflow
enzofab91 2a8e950
empty commit to run CI
enzofab91 d9d162d
empty commit to run CI
enzofab91 a7488ad
empty commit to run CI
enzofab91 3701c41
empty commit to run CI
enzofab91 0189a64
Update CI setup
enzofab91 cef0b0a
Move CI_NODE_TOTAL to secrets
enzofab91 203f6f6
Move CI_NODE_TOTAL to secrets
enzofab91 00cd67e
Move CI_NODE_TOTAL to secrets
enzofab91 c81d622
Move CI_NODE_TOTAL to secrets
enzofab91 f530cc9
Move CI_NODE_TOTAL to secrets
enzofab91 bab4613
Fix
enzofab91 2196939
Remove advertisements and warning when running CI
enzofab91 5f3744c
move harcoded values to secrets with a default value
rodrieiz 873b747
try to set matrix strategy
rodrieiz 07aec0c
queue mode works?
rodrieiz bf4e1a9
vars
rodrieiz 38a097c
split tests and linters
jpascual1994 23442ec
move I18n Health check to code:analysis
jpascual1994 abb1b68
add parallel gem
grosendo2006 d42f52a
Merge branch 'main' into release/improve-ci
lauperalti 7887d38
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
enzofab91 d021a00
Merge branch 'release/improve-ci' of github.com:rootstrap/rails_api_b…
rodrieiz c77ab37
remove unnecesary database step
rodrieiz ada4054
update knapsack version
rodrieiz b19d693
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
lauperalti 47a19a2
create a workflow to update knapsack report
rodrieiz 5e30047
add database step
rodrieiz 5b81a18
update pull request step
rodrieiz 07b971e
ci
rodrieiz 3df258b
Merge pull request #416 from rootstrap/fix_ci_linter_job
rodrieiz 7049c86
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
lauperalti c6f6fe4
improvements
rodrieiz 9e8bac5
fix parallel coverage
jpascual1994 1aee50d
Merge parallel with knapsack
enzofab91 7d3024d
Merge parallel with knapsack
enzofab91 46b7079
no path
lauperalti 93f1c3a
Merge parallel with knapsack
enzofab91 3470661
fix parallel coverage
jpascual1994 b6bcd7d
Merge branch 'fix-coverage' of https://github.com/rootstrap/rails_api…
lauperalti 9ddc256
fix parallel coverage
jpascual1994 a78cabe
Merge parallel with knapsack
enzofab91 6ad4d8e
Merge parallel with knapsack
enzofab91 701c17c
Merge branch 'fix-coverage' of https://github.com/rootstrap/rails_api…
lauperalti 719fac8
Merge parallel with knapsack
enzofab91 9d31955
Merge parallel with knapsack
enzofab91 25022bd
name codeclimate
lauperalti 250250d
remove filenames
rodrieiz fdb9f03
Merge parallel with knapsack
enzofab91 f361830
Merge branch 'fix-coverage' of https://github.com/rootstrap/rails_api…
lauperalti 28a711d
Merge parallel with knapsack
enzofab91 e4ab033
remove filenames
rodrieiz cd8dd16
Add install dependencies
enzofab91 91c9c66
Merge branch 'fix-coverage' of github.com:rootstrap/rails_api_base in…
rodrieiz 237ddb2
Add install dependencies
enzofab91 56400bb
Add parallel database creation
enzofab91 7a4be73
Add parallel database creation
enzofab91 72b5223
Add parallel database creation
enzofab91 d1600f0
Add parallel database creation
enzofab91 27aa44e
Add parallel database creation
enzofab91 49196c5
Trying to run parallel in CI
enzofab91 3b4d2c7
Trying to run parallel in CI
enzofab91 067ac44
Trying to run parallel in CI
enzofab91 66bd3f8
Trying to run parallel in CI
enzofab91 75991cd
Trying to run parallel in CI
enzofab91 8f70777
Test
enzofab91 801aa83
Test
enzofab91 6aa80e8
Test
enzofab91 3b7d460
Test
enzofab91 2a6b967
Test
enzofab91 954436a
Run tests in parallel
enzofab91 ce2e925
Run tests in parallel
enzofab91 c7c2a18
Run tests in parallel
enzofab91 4c84c0c
Run tests in parallel
enzofab91 40b6571
Run tests in parallel
enzofab91 abc0a20
Run tests in parallel
enzofab91 26f2ce7
Run tests in parallel
enzofab91 1cc3172
Run tests in parallel
enzofab91 4892402
Run tests in parallel
enzofab91 57e8814
Run tests in parallel
enzofab91 5c78dff
Run tests in parallel
enzofab91 742ad39
Run tests in parallel
enzofab91 29dcf73
Run tests in parallel
enzofab91 4e88a61
Run tests in parallel
enzofab91 fe67770
Run tests in parallel
enzofab91 7f15cde
Run tests in parallel
enzofab91 f462bbd
Run tests in parallel
enzofab91 a6c27ab
Run tests in parallel
enzofab91 bf434c6
Run tests in parallel
enzofab91 d6d477d
Run tests in parallel
enzofab91 ddc7456
Run tests in parallel
enzofab91 e3faa92
Run tests in parallel
enzofab91 6bf433b
Test
enzofab91 ef7cf20
Test
enzofab91 cecd0f4
Test
enzofab91 828230b
Test
enzofab91 a38870c
Test
enzofab91 eb0ad37
Test
enzofab91 2237462
test
enzofab91 0fcee6b
testing
enzofab91 fcc66ac
test
enzofab91 f2c0573
test
enzofab91 c0106b5
test
enzofab91 6d6c559
test
enzofab91 c5d5701
test
enzofab91 85f8f9f
test
enzofab91 64bf47b
test
enzofab91 25f43ed
test
enzofab91 fe64f3c
test
enzofab91 7970ce1
chmod +x
rodrieiz 73c5100
try again
rodrieiz 4267f6f
Ignore test to see if duplicated key passes
enzofab91 250f7e5
test
enzofab91 2ddd2de
Remove log
enzofab91 8d9343f
Remove verbose
enzofab91 d729325
Merge pull request #425 from rootstrap/merge_knapsack_and_parallel
enzofab91 6749b66
Merge branch 'release/improve-ci' into fix-coverage
lauperalti fa7138c
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
lauperalti 80b0da8
Merge branch 'main' into release/improve-ci
grosendo2006 adc46f1
Move before-build as documentation example
lauperalti f93f454
test
rodrieiz 7717e10
Trigger Build
rodrieiz 720356f
Merge pull request #426 from rootstrap/fix-coverage
rodrieiz 40e6155
Merge branch 'release/improve-ci' into generate_knapsack_report_perio…
rodrieiz 789e0f3
Merge pull request #424 from rootstrap/generate_knapsack_report_perio…
rodrieiz d1cc89d
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
lauperalti 6b5fa81
Merge branch 'main' into release/improve-ci
lauperalti 0801d96
Update update_knapsack_report.yml
jpascual1994 ac31b70
exclud code analysis
jpascual1994 29d3e33
Update ci.yml
santib b64de93
Update .codeclimate.yml
jpascual1994 8a90173
Update .codeclimate.yml
santib 9a5c6ed
test
jpascual1994 af2dfc3
Update rails_helper.rb
jpascual1994 fb74784
Update .codeclimate.yml
jpascual1994 5b189db
Update rails_helper.rb
jpascual1994 3816085
Fix typo
jpascual1994 fbaad57
remove unnecessary env
enzofab91 d244d87
revert previous unncesary changes
rodrieiz ce9f84d
some review comments
rodrieiz 94b93fa
remove unnecessary env
enzofab91 c9608ec
CR fixes
enzofab91 c6b2063
CR fixes
enzofab91 59317d0
Update cpu quantity info
enzofab91 d0d4799
Update cpu quantity info
enzofab91 13448df
Text change
enzofab91 7c654ef
update ci knapsack workflow
rodrieiz d23cc89
Merge branch 'main' into release/improve-ci
rodrieiz acc8fa7
remove unnecessary env
enzofab91 c1f8862
CR fixes
enzofab91 32f1f3e
CR fixes
enzofab91 9bdbc00
Update cpu quantity info
enzofab91 631014f
Update cpu quantity info
enzofab91 d9dacce
Text change
enzofab91 8f7745b
fix review comments
rodrieiz a5ff9d1
remove var
rodrieiz 155cee1
Merge branch 'parallel_ci_docs' of https://github.com/rootstrap/rails…
enzofab91 01f4e7d
Merge pull request #439 from rootstrap/parallel_ci_docs
rodrieiz eae899d
Update docs/ci.md
enzofab91 2b1d77f
Update docs/ci.md
enzofab91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Update Knapsack Report | ||
|
||
# This workflow should be scheduled at certain intervals | ||
on: | ||
schedule: | ||
- cron: '0 5 31 2 *' | ||
# The above cron does not run. Replace with the wanted periodicity. | ||
rodrieiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# For example, the following configuration would schedule it every 3 months | ||
# - cron: '0 0 1 */3 *' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
db: | ||
image: postgres:15 | ||
env: | ||
POSTGRES_USER: postgres | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
ports: | ||
- 5432:5432 | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
|
||
env: | ||
RAILS_ENV: test | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Ruby 3.1 | ||
uses: actions/setup-ruby@v1 | ||
with: | ||
ruby-version: 3.1 | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Setup Database | ||
run: bundle exec rails db:create db:migrate | ||
- name: Update Knapsack Report | ||
run: KNAPSACK_GENERATE_REPORT=true bundle exec rspec | ||
- name: Commit files | ||
run: | | ||
git config --local user.email "action@github.com" | ||
git config --local user.name "GitHub Action" | ||
git add knapsack_rspec_report.json | ||
git commit -m "Update knapsack_rspec_report.json" | ||
- name: Push changes | ||
run: git push origin HEAD:update-knapsack-report | ||
- name: Initialize Pull Request | ||
jpascual1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uses: rootstrap/create-pull-request@v3 | ||
with: | ||
pull_request_token: ${{ secrets.GITHUB_TOKEN }} | ||
head: update-knapsack-report | ||
base: main | ||
title: 'Update Knapsack report' | ||
maintainer_can_modify: true | ||
draft: false | ||
body: > | ||
This is an automated PR. Knapsack uses the report file to distribute tests across different nodes | ||
so that they all have similar execution times. It's advisable to update the report periodically, | ||
especially if many test files have been added, for better distribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ | |
require_relative 'config/application' | ||
|
||
Rails.application.load_tasks | ||
|
||
Knapsack.load_tasks if defined?(Knapsack) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# This file should be in bin/parallel_tests | ||
|
||
# updates CI node total based on parallel_tests concurrency | ||
KNAPSACK_CI_NODE_TOTAL=$(( $PARALLEL_TESTS_CONCURRENCY * $KNAPSACK_CI_NODE_TOTAL )) | ||
|
||
if [ "$TEST_ENV_NUMBER" == "" ]; then | ||
PARALLEL_TESTS_CONCURRENCY_INDEX=0 | ||
else | ||
PARALLEL_TESTS_CONCURRENCY_INDEX=$(( $TEST_ENV_NUMBER - 1 )) | ||
fi | ||
|
||
KNAPSACK_CI_NODE_INDEX=$(( $PARALLEL_TESTS_CONCURRENCY_INDEX + ($PARALLEL_TESTS_CONCURRENCY * $KNAPSACK_CI_NODE_INDEX) )) | ||
|
||
# logs info about ENVs to ensure everything works | ||
echo KNAPSACK_CI_NODE_TOTAL=$KNAPSACK_CI_NODE_TOTAL KNAPSACK_CI_NODE_INDEX=$KNAPSACK_CI_NODE_INDEX PARALLEL_TESTS_CONCURRENCY=$PARALLEL_TESTS_CONCURRENCY | ||
|
||
CI_NODE_TOTAL=$KNAPSACK_CI_NODE_TOTAL CI_NODE_INDEX=$KNAPSACK_CI_NODE_INDEX bundle exec rake knapsack:rspec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# CI | ||
|
||
## Parallelization with Parallel Tests & Knapsack | ||
Knapsack and Parallel Tests gems allow us to run tests in several nodes at the same time, benefiting us in the execution time. Knapsack parallelizes them at node level while Parallel Tests does it at CPU level. | ||
|
||
Knapsack splits tests based on an execution time report. In case there are files that were not added in the report, they will all run on the same node and may overload it, so it is strongly recommended to update the report frequently. | ||
|
||
## Configuration | ||
In case you want to use this you will need the script that splits spec files called `parallel_tests`, which sets up the configuration, assuming you have `n_nodes * cpu_cores_quantity`. | ||
|
||
On Github Actions you can add any nodes you want using matrix strategy, setting up some variables: | ||
|
||
```sh | ||
ci_node_total: [4] | ||
# set N-1 indexes for parallel jobs | ||
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc | ||
ci_node_index: [0, 1, 2, 3] | ||
``` | ||
|
||
CPU cores quantity on every node are obtained automatically from Github Actions config `echo "cpu_cores=$(nproc)" >> $GITHUB_ENV`. | ||
|
||
If you want to update it manually you can do it by updating this variable: | ||
`PARALLEL_TESTS_CONCURRENCY: 2` | ||
|
||
To update tests on local machine you can execute `KNAPSACK_CI_NODE_TOTAL=4 KNAPSACK_CI_NODE_INDEX=1 PARALLEL_TESTS_CONCURRENCY=2 bundle exec parallel_rspec -n 2 -e './bin/parallel_tests'`. This will run subset of tests files corresponding to second node. | ||
|
||
## Generating report | ||
Knapsack report needs to be updated frequently to balance execution time among nodes. This can be done manually by executing: | ||
`KNAPSACK_GENERATE_REPORT=true bundle exec rspec` | ||
|
||
It is also recommended to generate the report in the CI for a better precision. For this you have available a workflow in Github Actions that triggers the report generation and creates a pull request automatically. This workflow can be scheduled in the frequency you want or even can be manually triggered. | ||
|
||
To schedule the cron task you have to do it in `.github/workflows/update_knapsack_report.yml:6` | ||
It is now scheduled for February 31 so will never run. | ||
|
||
```sh | ||
- cron: '0 5 31 2 *' | ||
# The above cron does not run. Replace with the wanted periodicity. | ||
``` | ||
## Coverage | ||
When splitting tests in different nodes, each report covers only a part of the code files being tested. | ||
For this reason a job in the CI is added to sums coverages from all nodes to be used by SimpleCov. This job will be executed after all nodes have finished and will send the final report to CodeClimate. | ||
|
||
For the case of CPU cores we do not need to add extra configuration since the report of each node contains the info of all the cores that have been splited. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"spec/policies/admin/page_policy_spec.rb": 0.038240999972913414, | ||
"spec/routing/sessions_routing_spec.rb": 0.006703999999444932, | ||
"spec/requests/api/v1/users/create_spec.rb": 0.5093869999982417, | ||
"spec/acceptance/settings_spec.rb": 0.17437299998709932, | ||
"spec/acceptance/sessions_spec.rb": 0.5090029999846593, | ||
"spec/acceptance/status_spec.rb": 0.009465000010095537, | ||
"spec/requests/api/v1/sessions/destroy_spec.rb": 0.2923869999940507, | ||
"spec/policies/admin/user_policy_spec.rb": 0.020087999990209937, | ||
"spec/routing/registrations_routing_spec.rb": 0.001361000002361834, | ||
"spec/policies/admin/application_policy_spec.rb": 0.011096000031102449, | ||
"spec/policies/admin_user_policy_spec.rb": 0.009194999991450459, | ||
"spec/routing/user_routing_spec.rb": 0.0026309999520890415, | ||
"spec/requests/api/v1/passwords/update_spec.rb": 0.4883949999930337, | ||
"spec/requests/api/v1/feature_flags_spec.rb": 0.040616000012960285, | ||
"spec/requests/api/v1/settings_spec.rb": 0.0425929999910295, | ||
"spec/requests/api/v1/passwords/create_spec.rb": 0.15221400000154972, | ||
"spec/acceptance/users_spec.rb": 0.5729850000352599, | ||
"spec/policies/user_policy_spec.rb": 0.015309000038541853, | ||
"spec/requests/api/v1/users/update_spec.rb": 0.9842829999979585, | ||
"spec/requests/api/v1/status_spec.rb": 0.01666500000283122, | ||
"spec/policies/application_policy_spec.rb": 0.008917000028304756, | ||
"spec/policies/admin/admin_user_policy_spec.rb": 0.005394000036176294, | ||
"spec/requests/api/v1/sessions/create_spec.rb": 0.49404099996900186, | ||
"spec/decorators/user_decorator_spec.rb": 0.005971000005956739, | ||
"spec/requests/api/v1/passwords/edit_spec.rb": 0.08089700003620237, | ||
"spec/acceptance/passwords_spec.rb": 0.6197870000032708, | ||
"spec/models/user_spec.rb": 0.09392800001660362, | ||
"spec/mailers/application_mailer_spec.rb": 0.0020680000307038426, | ||
"spec/requests/api/v1/users/show_spec.rb": 0.5047900000354275 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.