Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
187 commits
Select commit Hold shift + click to select a range
80a5891
Add knapsack gem
enzofab91 Jul 20, 2023
d4672b1
Add total nodes to ci workflow
enzofab91 Jul 20, 2023
c0f6052
empty commit to run CI
enzofab91 Jul 20, 2023
62f8ea9
empty commit to run CI
enzofab91 Jul 20, 2023
18f2c6c
empty commit to run CI
enzofab91 Jul 20, 2023
a40547c
empty commit to run CI
enzofab91 Jul 20, 2023
691f400
Update CI setup
enzofab91 Jul 20, 2023
2e624f0
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
27a4dc0
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
fc2d158
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
0ebfcb9
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
51eb9f8
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
a23f5ec
split tests and linters
jpascual1994 Aug 7, 2023
b685aa8
Fix
enzofab91 Aug 8, 2023
57e4b7a
Remove advertisements and warning when running CI
enzofab91 Aug 8, 2023
316918a
move harcoded values to secrets with a default value
rodrieiz Aug 10, 2023
682e2ef
move I18n Health check to code:analysis
jpascual1994 Aug 10, 2023
b887c00
Merge pull request #403 from rootstrap/parallel-tests-and-linters
jpascual1994 Aug 11, 2023
bda5aca
try to set matrix strategy
rodrieiz Aug 11, 2023
fa62ac7
queue mode works?
rodrieiz Aug 11, 2023
8b6591e
vars
rodrieiz Aug 11, 2023
91d7b17
Merge branch 'release/improve-ci' into add_knapsack_gem
rodrieiz Aug 14, 2023
62e0105
add parallel gem
grosendo2006 Jul 25, 2023
9cdd3a7
Merge pull request #393 from rootstrap/add-parell-test
grosendo2006 Aug 15, 2023
c21414b
Merge branch 'release/improve-ci' into add_knapsack_gem
enzofab91 Aug 15, 2023
171f2ba
Merge pull request #390 from rootstrap/add_knapsack_gem
enzofab91 Aug 15, 2023
413a8c0
Add knapsack gem
enzofab91 Jul 20, 2023
e1bee9d
Add total nodes to ci workflow
enzofab91 Jul 20, 2023
2a8e950
empty commit to run CI
enzofab91 Jul 20, 2023
d9d162d
empty commit to run CI
enzofab91 Jul 20, 2023
a7488ad
empty commit to run CI
enzofab91 Jul 20, 2023
3701c41
empty commit to run CI
enzofab91 Jul 20, 2023
0189a64
Update CI setup
enzofab91 Jul 20, 2023
cef0b0a
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
203f6f6
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
00cd67e
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
c81d622
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
f530cc9
Move CI_NODE_TOTAL to secrets
enzofab91 Aug 1, 2023
bab4613
Fix
enzofab91 Aug 8, 2023
2196939
Remove advertisements and warning when running CI
enzofab91 Aug 8, 2023
5f3744c
move harcoded values to secrets with a default value
rodrieiz Aug 10, 2023
873b747
try to set matrix strategy
rodrieiz Aug 11, 2023
07aec0c
queue mode works?
rodrieiz Aug 11, 2023
bf4e1a9
vars
rodrieiz Aug 11, 2023
38a097c
split tests and linters
jpascual1994 Aug 7, 2023
23442ec
move I18n Health check to code:analysis
jpascual1994 Aug 10, 2023
abb1b68
add parallel gem
grosendo2006 Jul 25, 2023
d42f52a
Merge branch 'main' into release/improve-ci
lauperalti Aug 17, 2023
7887d38
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
enzofab91 Aug 17, 2023
d021a00
Merge branch 'release/improve-ci' of github.com:rootstrap/rails_api_b…
rodrieiz Aug 17, 2023
c77ab37
remove unnecesary database step
rodrieiz Aug 21, 2023
ada4054
update knapsack version
rodrieiz Aug 21, 2023
b19d693
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
lauperalti Aug 21, 2023
47a19a2
create a workflow to update knapsack report
rodrieiz Aug 21, 2023
5e30047
add database step
rodrieiz Aug 22, 2023
5b81a18
update pull request step
rodrieiz Aug 22, 2023
07b971e
ci
rodrieiz Aug 22, 2023
3df258b
Merge pull request #416 from rootstrap/fix_ci_linter_job
rodrieiz Aug 22, 2023
7049c86
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
lauperalti Aug 22, 2023
c6f6fe4
improvements
rodrieiz Aug 22, 2023
9e8bac5
fix parallel coverage
jpascual1994 Aug 22, 2023
1aee50d
Merge parallel with knapsack
enzofab91 Aug 22, 2023
7d3024d
Merge parallel with knapsack
enzofab91 Aug 22, 2023
46b7079
no path
lauperalti Aug 22, 2023
93f1c3a
Merge parallel with knapsack
enzofab91 Aug 22, 2023
3470661
fix parallel coverage
jpascual1994 Aug 22, 2023
b6bcd7d
Merge branch 'fix-coverage' of https://github.com/rootstrap/rails_api…
lauperalti Aug 22, 2023
9ddc256
fix parallel coverage
jpascual1994 Aug 22, 2023
a78cabe
Merge parallel with knapsack
enzofab91 Aug 22, 2023
6ad4d8e
Merge parallel with knapsack
enzofab91 Aug 22, 2023
701c17c
Merge branch 'fix-coverage' of https://github.com/rootstrap/rails_api…
lauperalti Aug 22, 2023
719fac8
Merge parallel with knapsack
enzofab91 Aug 22, 2023
9d31955
Merge parallel with knapsack
enzofab91 Aug 22, 2023
25022bd
name codeclimate
lauperalti Aug 22, 2023
250250d
remove filenames
rodrieiz Aug 22, 2023
fdb9f03
Merge parallel with knapsack
enzofab91 Aug 22, 2023
f361830
Merge branch 'fix-coverage' of https://github.com/rootstrap/rails_api…
lauperalti Aug 22, 2023
28a711d
Merge parallel with knapsack
enzofab91 Aug 22, 2023
e4ab033
remove filenames
rodrieiz Aug 22, 2023
cd8dd16
Add install dependencies
enzofab91 Aug 22, 2023
91c9c66
Merge branch 'fix-coverage' of github.com:rootstrap/rails_api_base in…
rodrieiz Aug 22, 2023
237ddb2
Add install dependencies
enzofab91 Aug 22, 2023
56400bb
Add parallel database creation
enzofab91 Aug 22, 2023
7a4be73
Add parallel database creation
enzofab91 Aug 22, 2023
72b5223
Add parallel database creation
enzofab91 Aug 22, 2023
d1600f0
Add parallel database creation
enzofab91 Aug 22, 2023
27aa44e
Add parallel database creation
enzofab91 Aug 22, 2023
49196c5
Trying to run parallel in CI
enzofab91 Aug 22, 2023
3b4d2c7
Trying to run parallel in CI
enzofab91 Aug 22, 2023
067ac44
Trying to run parallel in CI
enzofab91 Aug 22, 2023
66bd3f8
Trying to run parallel in CI
enzofab91 Aug 22, 2023
75991cd
Trying to run parallel in CI
enzofab91 Aug 22, 2023
8f70777
Test
enzofab91 Aug 23, 2023
801aa83
Test
enzofab91 Aug 23, 2023
6aa80e8
Test
enzofab91 Aug 23, 2023
3b7d460
Test
enzofab91 Aug 23, 2023
2a6b967
Test
enzofab91 Aug 23, 2023
954436a
Run tests in parallel
enzofab91 Aug 23, 2023
ce2e925
Run tests in parallel
enzofab91 Aug 23, 2023
c7c2a18
Run tests in parallel
enzofab91 Aug 23, 2023
4c84c0c
Run tests in parallel
enzofab91 Aug 23, 2023
40b6571
Run tests in parallel
enzofab91 Aug 23, 2023
abc0a20
Run tests in parallel
enzofab91 Aug 23, 2023
26f2ce7
Run tests in parallel
enzofab91 Aug 23, 2023
1cc3172
Run tests in parallel
enzofab91 Aug 23, 2023
4892402
Run tests in parallel
enzofab91 Aug 23, 2023
57e8814
Run tests in parallel
enzofab91 Aug 23, 2023
5c78dff
Run tests in parallel
enzofab91 Aug 23, 2023
742ad39
Run tests in parallel
enzofab91 Aug 23, 2023
29dcf73
Run tests in parallel
enzofab91 Aug 23, 2023
4e88a61
Run tests in parallel
enzofab91 Aug 23, 2023
fe67770
Run tests in parallel
enzofab91 Aug 23, 2023
7f15cde
Run tests in parallel
enzofab91 Aug 23, 2023
f462bbd
Run tests in parallel
enzofab91 Aug 23, 2023
a6c27ab
Run tests in parallel
enzofab91 Aug 23, 2023
bf434c6
Run tests in parallel
enzofab91 Aug 23, 2023
d6d477d
Run tests in parallel
enzofab91 Aug 23, 2023
ddc7456
Run tests in parallel
enzofab91 Aug 23, 2023
e3faa92
Run tests in parallel
enzofab91 Aug 23, 2023
6bf433b
Test
enzofab91 Aug 23, 2023
ef7cf20
Test
enzofab91 Aug 23, 2023
cecd0f4
Test
enzofab91 Aug 23, 2023
828230b
Test
enzofab91 Aug 23, 2023
a38870c
Test
enzofab91 Aug 23, 2023
eb0ad37
Test
enzofab91 Aug 23, 2023
2237462
test
enzofab91 Aug 23, 2023
0fcee6b
testing
enzofab91 Aug 23, 2023
fcc66ac
test
enzofab91 Aug 23, 2023
f2c0573
test
enzofab91 Aug 23, 2023
c0106b5
test
enzofab91 Aug 23, 2023
6d6c559
test
enzofab91 Aug 23, 2023
c5d5701
test
enzofab91 Aug 23, 2023
85f8f9f
test
enzofab91 Aug 23, 2023
64bf47b
test
enzofab91 Aug 23, 2023
25f43ed
test
enzofab91 Aug 23, 2023
fe64f3c
test
enzofab91 Aug 23, 2023
7970ce1
chmod +x
rodrieiz Aug 23, 2023
73c5100
try again
rodrieiz Aug 23, 2023
4267f6f
Ignore test to see if duplicated key passes
enzofab91 Aug 25, 2023
250f7e5
test
enzofab91 Aug 25, 2023
2ddd2de
Remove log
enzofab91 Aug 25, 2023
8d9343f
Remove verbose
enzofab91 Aug 28, 2023
d729325
Merge pull request #425 from rootstrap/merge_knapsack_and_parallel
enzofab91 Aug 28, 2023
6749b66
Merge branch 'release/improve-ci' into fix-coverage
lauperalti Aug 28, 2023
fa7138c
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
lauperalti Aug 28, 2023
80b0da8
Merge branch 'main' into release/improve-ci
grosendo2006 Aug 28, 2023
adc46f1
Move before-build as documentation example
lauperalti Aug 28, 2023
f93f454
test
rodrieiz Aug 29, 2023
7717e10
Trigger Build
rodrieiz Aug 29, 2023
720356f
Merge pull request #426 from rootstrap/fix-coverage
rodrieiz Aug 30, 2023
40e6155
Merge branch 'release/improve-ci' into generate_knapsack_report_perio…
rodrieiz Aug 22, 2023
789e0f3
Merge pull request #424 from rootstrap/generate_knapsack_report_perio…
rodrieiz Aug 30, 2023
d1cc89d
Merge branch 'release/improve-ci' of https://github.com/rootstrap/rai…
lauperalti Aug 30, 2023
6b5fa81
Merge branch 'main' into release/improve-ci
lauperalti Aug 30, 2023
0801d96
Update update_knapsack_report.yml
jpascual1994 Aug 30, 2023
ac31b70
exclud code analysis
jpascual1994 Aug 30, 2023
29d3e33
Update ci.yml
santib Aug 30, 2023
b64de93
Update .codeclimate.yml
jpascual1994 Aug 30, 2023
8a90173
Update .codeclimate.yml
santib Aug 30, 2023
9a5c6ed
test
jpascual1994 Aug 30, 2023
af2dfc3
Update rails_helper.rb
jpascual1994 Aug 30, 2023
fb74784
Update .codeclimate.yml
jpascual1994 Aug 30, 2023
5b189db
Update rails_helper.rb
jpascual1994 Aug 30, 2023
3816085
Fix typo
jpascual1994 Aug 31, 2023
fbaad57
remove unnecessary env
enzofab91 Aug 31, 2023
d244d87
revert previous unncesary changes
rodrieiz Aug 31, 2023
ce9f84d
some review comments
rodrieiz Sep 4, 2023
94b93fa
remove unnecessary env
enzofab91 Sep 6, 2023
c9608ec
CR fixes
enzofab91 Sep 6, 2023
c6b2063
CR fixes
enzofab91 Sep 7, 2023
59317d0
Update cpu quantity info
enzofab91 Sep 7, 2023
d0d4799
Update cpu quantity info
enzofab91 Sep 7, 2023
13448df
Text change
enzofab91 Sep 7, 2023
7c654ef
update ci knapsack workflow
rodrieiz Sep 7, 2023
d23cc89
Merge branch 'main' into release/improve-ci
rodrieiz Sep 7, 2023
acc8fa7
remove unnecessary env
enzofab91 Sep 6, 2023
c1f8862
CR fixes
enzofab91 Sep 6, 2023
32f1f3e
CR fixes
enzofab91 Sep 7, 2023
9bdbc00
Update cpu quantity info
enzofab91 Sep 7, 2023
631014f
Update cpu quantity info
enzofab91 Sep 7, 2023
d9dacce
Text change
enzofab91 Sep 7, 2023
8f7745b
fix review comments
rodrieiz Sep 7, 2023
a5ff9d1
remove var
rodrieiz Sep 7, 2023
155cee1
Merge branch 'parallel_ci_docs' of https://github.com/rootstrap/rails…
enzofab91 Sep 7, 2023
01f4e7d
Merge pull request #439 from rootstrap/parallel_ci_docs
rodrieiz Sep 8, 2023
eae899d
Update docs/ci.md
enzofab91 Sep 8, 2023
2b1d77f
Update docs/ci.md
enzofab91 Sep 8, 2023
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
80 changes: 66 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@ name: CI

on: [push]

env:
RAILS_ENV: test
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

jobs:
build:
linters:
name: Linters
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run Code Analysis
run: |
bundle exec rake code:analysis
tests:
name: Tests
runs-on: ubuntu-latest

services:
db:
image: postgres:9.4
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
Expand All @@ -19,10 +37,17 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5

env:
RAILS_ENV: test
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

strategy:
fail-fast: false
matrix:
# Set N number of parallel jobs you want to run tests on.
# Use higher number if you have slow tests to split them on more parallel jobs.
# Remember to update ci_node_index below to 0..N-1
ci_node_total: [1]
# 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]

steps:
- name: Checkout code
Expand All @@ -35,21 +60,25 @@ jobs:
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
./cc-test-reporter before-build
- name: Setup Database
run: bundle exec rails db:create db:migrate
run: |
bundle exec rake parallel:load_schema
- name: Check for untracked changes in schema.rb
uses: rootstrap/check_untracked_changes@v1
with:
path: "./db/schema.rb"
- name: I18n Health
run: bundle exec i18n-tasks health
- name: Run Code Analysis
- name: Get CPU info
id: cpu_info
run: |
bundle exec rake code:analysis
echo "cpu_cores=$(nproc)" >> $GITHUB_ENV
- name: Run Tests
env:
KNAPSACK_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
PARALLEL_TESTS_CONCURRENCY: ${{ env.cpu_cores }}
run: |
bundle exec rspec
bundle exec parallel_rspec -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests'
- name: Check for missing annotations
run: bundle exec annotate
- name: Check for untracked changes in app and spec directories
Expand All @@ -58,4 +87,27 @@ jobs:
path: "./app/ ./spec/"
- name: Report to CodeClimate
run: |
./cc-test-reporter after-build --exit-code 0
./cc-test-reporter format-coverage --output "coverage/coverage.${{ matrix.ci_node_index }}.json"
- name: Upload partial converage
uses: actions/upload-artifact@v2
with:
name: coverage
path: "coverage/coverage.${{ matrix.ci_node_index }}.json"
coverage:
name: Coverage
runs-on: ubuntu-latest
needs: tests
steps:
- name: Setup Code Climate test-reporter
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
- name: download coverage reports
uses: actions/download-artifact@v2
with:
name: coverage
path: coverage/coverage.*.json
- name: report coverage
run: |
./cc-test-reporter sum-coverage coverage/**/*.json
./cc-test-reporter upload-coverage
63 changes: 63 additions & 0 deletions .github/workflows/update_knapsack_report.yml
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.
# 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
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.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ group :development, :test do
gem 'annotate', '~> 3.2', '>= 3.0.3'
gem 'dotenv-rails', '~> 2.7.6'
gem 'factory_bot_rails', '~> 6.2'
gem 'knapsack', '~> 4.0'
gem 'parallel_tests', '~> 4.2'
gem 'pry-byebug', '~> 3.9', platform: :mri
gem 'pry-rails', '~> 0.3.9'
gem 'rspec_api_documentation', '~> 6.1.0'
Expand Down
12 changes: 10 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ GEM
aws-sigv4 (~> 1.6)
aws-sigv4 (1.6.0)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.1.1)
bcrypt (3.1.18)
better_errors (2.10.1)
erubi (>= 1.0.0)
Expand Down Expand Up @@ -248,6 +249,8 @@ GEM
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
knapsack (4.0.0)
rake
kwalify (0.7.2)
language_server-protocol (3.17.0.3)
launchy (2.5.0)
Expand Down Expand Up @@ -293,7 +296,9 @@ GEM
oj (3.16.1)
orm_adapter (0.5.0)
pagy (4.11.0)
parallel (1.23.0)
parallel (1.22.1)
parallel_tests (4.2.1)
parallel
parser (3.2.2.3)
ast (~> 2.4.1)
racc
Expand Down Expand Up @@ -408,7 +413,8 @@ GEM
activesupport (>= 3.0.0)
mustache (~> 1.0, >= 0.99.4)
rspec (~> 3.0)
rubocop (1.55.0)
rubocop (1.56.0)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down Expand Up @@ -524,11 +530,13 @@ DEPENDENCIES
flipper-ui (~> 0.28.0)
i18n-tasks (~> 1.0.12)
jbuilder (~> 2.10)
knapsack (~> 4.0)
letter_opener (~> 1.7)
listen (~> 3.8)
lograge (~> 0.13)
oj (~> 3.16)
pagy (~> 4.0)
parallel_tests (~> 4.2)
pg (~> 1.5)
pg_query (~> 4.2.1)
prosopite (~> 1.3.2)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ To illustrate, `bin/rails console` will run the console in the docker container
- [Faker](https://github.com/stympy/faker) for generating test data
- [Flipper](https://github.com/jnunemaker/flipper) for feature flag support
- [Jbuilder](https://github.com/rails/jbuilder) for json views
- [Knapsack](https://github.com/KnapsackPro/knapsack) for generating CI time report and splitting into nodes
- [Letter Opener](https://github.com/ryanb/letter_opener) for previewing a mail in the browser
- [Oj](https://github.com/ohler55/oj) for optimized json
- [Pagy](https://github.com/ddnexus/pagy) for pagination
- [Parallel Tests](https://github.com/grosser/parallel_tests) for split CI in several cores
- [Prosopite](https://github.com/charkost/prosopite) to detect N+1 queries
- [Pry](https://github.com/pry/pry) for enhancing the ruby shell
- [Puma](https://github.com/puma/puma) for the server
Expand All @@ -105,6 +107,7 @@ To illustrate, `bin/rails console` will run the console in the docker container
- Set your [frontend URL](https://github.com/cyu/rack-cors#origin) in `config/initializers/rack_cors.rb`
- Set your mail sender in `config/initializers/devise.rb`
- Config your timezone accordingly in `application.rb`.
- Config CI in parallel execution. See [docs](docs/ci.md).

## Api Docs

Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
require_relative 'config/application'

Rails.application.load_tasks

Knapsack.load_tasks if defined?(Knapsack)
18 changes: 18 additions & 0 deletions bin/parallel_tests
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
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ development:

test:
<<: *default
database: rails_api_base_test
database: rails_api_base_test<%= ENV['TEST_ENV_NUMBER'] %>

# For production is recommended to set DATABASE_URL env variable.
# It will take precedence over the config defined here.
Expand Down
44 changes: 44 additions & 0 deletions docs/ci.md
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.
31 changes: 31 additions & 0 deletions knapsack_rspec_report.json
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
}
1 change: 1 addition & 0 deletions lib/tasks/code_analysis.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace :code do
sh 'bundle exec rubocop .'
sh 'bundle exec reek .'
sh 'bundle exec rails_best_practices .'
sh 'bundle exec i18n-tasks health'
end
end
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
add_filter 'app/admin'
add_filter 'config'
add_filter 'spec'
add_filter 'lib/tasks/code_analysis.rake'
end

require File.expand_path('../config/environment', __dir__)
Expand Down
Loading