From 7c53c25aaf6492c1bfa258bedd25e0a8511fb5d9 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 29 Apr 2024 16:10:48 +1000 Subject: [PATCH 1/7] Skip Ruby setup for non-Ruby tests Conversely, these tests are JS-only. --- .github/workflows/build.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 846f781c71..242efd2540 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -476,16 +476,6 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Setup redis - uses: supercharge/redis-github-action@1.4.0 - with: - redis-version: 6 - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - uses: actions/setup-node@v3 with: node-version-file: .node-version @@ -493,10 +483,6 @@ jobs: - name: Install JS dependencies run: yarn install --frozen-lockfile - - name: Set up database - run: | - bundle exec rake db:create - bundle exec rake db:schema:load - name: Run JS tests run: bundle exec rake karma:run From 6eaf0a00a0d77fea7635ce58a85c89e58b654f88 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 29 Apr 2024 16:25:57 +1000 Subject: [PATCH 2/7] Revert. Rails is required for the Karma rake script But surely we could convert it to a shell or node script. Maybe next time.. --- .github/workflows/build.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 242efd2540..d8f8a348f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -476,6 +476,12 @@ jobs: steps: - uses: actions/checkout@v3 + # Rails is required for the Karma rake script + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - uses: actions/setup-node@v3 with: node-version-file: .node-version From ce36b81f15d8f6c3ee2b0998ee1f3f495afd6b33 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 29 Apr 2024 16:14:55 +1000 Subject: [PATCH 3/7] Run multiple rake tasks in one process It saves the second unnecessary Rails boot-up (multiple seconds). --- .github/workflows/build.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d8f8a348f0..a378ce53ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,8 +64,7 @@ jobs: - name: Set up database run: | - bundle exec rake db:create - bundle exec rake db:schema:load + bundle exec rake db:create db:schema:load - name: Run tests env: @@ -132,8 +131,7 @@ jobs: - name: Set up database run: | - bundle exec rake db:create - bundle exec rake db:schema:load + bundle exec rake db:create db:schema:load - name: Run tests @@ -201,8 +199,7 @@ jobs: - name: Set up database run: | - bundle exec rake db:create - bundle exec rake db:schema:load + bundle exec rake db:create db:schema:load - name: Run tests @@ -279,8 +276,7 @@ jobs: - name: Set up database run: | - bundle exec rake db:create - bundle exec rake db:schema:load + bundle exec rake db:create db:schema:load - name: Run tests @@ -357,8 +353,7 @@ jobs: - name: Set up database run: | - bundle exec rake db:create - bundle exec rake db:schema:load + bundle exec rake db:create db:schema:load - name: Run tests @@ -435,8 +430,7 @@ jobs: - name: Set up database run: | - bundle exec rake db:create - bundle exec rake db:schema:load + bundle exec rake db:create db:schema:load - name: Run tests From 1a55ae2035717f52c2b1c88e25b6a2cee2c46655 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 29 Apr 2024 16:08:40 +1000 Subject: [PATCH 4/7] Skip JS setup for non-JS tests These tests don't run in the browser, therefore shouldn't need JavaScript at all. --- .github/workflows/build.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a378ce53ca..8227c72557 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,13 +55,6 @@ jobs: with: bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - uses: actions/setup-node@v3 - with: - node-version-file: .node-version - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - name: Set up database run: | bundle exec rake db:create db:schema:load @@ -122,19 +115,11 @@ jobs: with: bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - uses: actions/setup-node@v3 - with: - node-version-file: .node-version - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - name: Set up database run: | bundle exec rake db:create db:schema:load - name: Run tests - env: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: 09476e2ce491c12083df62768667c674 KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }} @@ -148,7 +133,6 @@ jobs: # https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it #KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/models/**/*_spec.rb}" - run: | bundle exec rake knapsack_pro:rspec @@ -344,13 +328,6 @@ jobs: with: bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - uses: actions/setup-node@v3 - with: - node-version-file: .node-version - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - name: Set up database run: | bundle exec rake db:create db:schema:load @@ -421,19 +398,11 @@ jobs: with: bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - uses: actions/setup-node@v3 - with: - node-version-file: .node-version - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - name: Set up database run: | bundle exec rake db:create db:schema:load - name: Run tests - env: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: e3b8800198d2d89b70c7edbdd85f8fd8 KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }} @@ -447,8 +416,6 @@ jobs: # https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it #KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN: "{engines/**/*_spec.rb,spec/models/**/*_spec.rb,spec/controllers/**/*_spec.rb,spec/serializers/**/*_spec.rb,spec/lib/**/*_spec.rb,spec/migrations/**/*_spec.rb,spec/system/**/*_spec.rb}" - - run: | bundle exec rake knapsack_pro:rspec From 55ece0553c0f8466e86a16efcbd02a6beb005bb0 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 29 Apr 2024 16:24:58 +1000 Subject: [PATCH 5/7] Revert. JS is still required for most specs But models can still run without. Half of the controller runs also succeeded, so we could potentially separate those ones out. Hmm, yes only 7 of them. It would save 20s, or 16% of controller CI runtimesi which are 2min. let's try.. --- .github/workflows/build.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8227c72557..1b553c7b74 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,6 +55,14 @@ jobs: with: bundler-cache: true # runs 'bundle install' and caches installed gems automatically + # JS is required in order for webpacker to compile, in order to render templates containing image urls + - uses: actions/setup-node@v3 + with: + node-version-file: .node-version + + - name: Install JS dependencies + run: yarn install --frozen-lockfile + - name: Set up database run: | bundle exec rake db:create db:schema:load @@ -328,6 +336,14 @@ jobs: with: bundler-cache: true # runs 'bundle install' and caches installed gems automatically + # JS is required in order for webpacker to compile, in order to render templates linking to mail.css + - uses: actions/setup-node@v3 + with: + node-version-file: .node-version + + - name: Install JS dependencies + run: yarn install --frozen-lockfile + - name: Set up database run: | bundle exec rake db:create db:schema:load @@ -398,6 +414,14 @@ jobs: with: bundler-cache: true # runs 'bundle install' and caches installed gems automatically + # JS is required in order for webpacker to compile, in order to render templates linking to mail.css + - uses: actions/setup-node@v3 + with: + node-version-file: .node-version + + - name: Install JS dependencies + run: yarn install --frozen-lockfile + - name: Set up database run: | bundle exec rake db:create db:schema:load From aeae16a1b438cbf1ddd7220511629fc2cc2d4ed7 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 29 Apr 2024 16:47:10 +1000 Subject: [PATCH 6/7] Separate controllers requiring webpack for testing --- .github/workflows/build.yml | 61 +++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b553c7b74..95f9178b80 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,10 +38,10 @@ jobs: # [n] - where the n is a number of parallel jobs you want to run your tests on. # Use a higher number if you have slow tests to split them between more parallel jobs. # Remember to update the value of the `ci_node_index` below to (0..n-1). - ci_node_total: [8] + ci_node_total: [7] # Indexes for parallel jobs (starting from zero). # E.g. use [0, 1] for 2 parallel jobs, [0, 1, 2] for 3 parallel jobs, etc. - ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7] + ci_node_index: [0, 1, 2, 3, 4, 5, 6] steps: - uses: actions/checkout@v3 @@ -55,14 +55,6 @@ jobs: with: bundler-cache: true # runs 'bundle install' and caches installed gems automatically - # JS is required in order for webpacker to compile, in order to render templates containing image urls - - uses: actions/setup-node@v3 - with: - node-version-file: .node-version - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - name: Set up database run: | bundle exec rake db:create db:schema:load @@ -81,10 +73,59 @@ jobs: # https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it #KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/controllers/**/*_spec.rb}" + KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN: "user_passwords_controller_spec|orders_controller_spec|mail_methods_controller_spec|groups_controller_spec|shops_controller_spec|payments_controller_spec" run: | git show --no-patch # the commit being tested (which is often a merge due to actions/checkout@v3) bundle exec rake knapsack_pro:rspec + # Controllers that render views with css or image links will need webpack + controllers_incl_webpack: + runs-on: ubuntu-22.04 + services: + postgres: + image: postgres:10 + ports: ["5432:5432"] + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_DB: open_food_network_test + POSTGRES_USER: ofn + POSTGRES_PASSWORD: f00d + steps: + - uses: actions/checkout@v3 + + - name: Setup redis + uses: supercharge/redis-github-action@1.4.0 + with: + redis-version: 6 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + + - uses: actions/setup-node@v3 + with: + node-version-file: .node-version + + - name: Install JS dependencies + run: yarn install --frozen-lockfile + + - name: Set up database + run: | + bundle exec rake db:create db:schema:load + + - name: Run tests + env: + # Copied from KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN above + INCLUDE_PATTERN: "user_passwords_controller_spec|orders_controller_spec|mail_methods_controller_spec|groups_controller_spec|shops_controller_spec|payments_controller_spec" + run: | + git show --no-patch # the commit being tested (which is often a merge due to actions/checkout@v3) + bundle exec rspec spec/controllers/**/*_spec.rb --pattern="$INCLUDE_PATTERN" + models: runs-on: ubuntu-22.04 services: From 7e951d4af22ebfc18f72f8c3b0d971e105cb8633 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 29 Apr 2024 17:12:38 +1000 Subject: [PATCH 7/7] Revert "Separate controllers requiring webpack for testing" Arrgh it's not so simple. It looks like both rspec and knapsack use glob for the pattern, so the pattern needs updating. Hmm that might not be too bad, but it makes it even less manageable. Considering the system specs are a much bigger bottleneck, I'm going to avoid spending more time here. --- .github/workflows/build.yml | 61 ++++++------------------------------- 1 file changed, 10 insertions(+), 51 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 95f9178b80..1b553c7b74 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,10 +38,10 @@ jobs: # [n] - where the n is a number of parallel jobs you want to run your tests on. # Use a higher number if you have slow tests to split them between more parallel jobs. # Remember to update the value of the `ci_node_index` below to (0..n-1). - ci_node_total: [7] + ci_node_total: [8] # Indexes for parallel jobs (starting from zero). # E.g. use [0, 1] for 2 parallel jobs, [0, 1, 2] for 3 parallel jobs, etc. - ci_node_index: [0, 1, 2, 3, 4, 5, 6] + ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7] steps: - uses: actions/checkout@v3 @@ -55,6 +55,14 @@ jobs: with: bundler-cache: true # runs 'bundle install' and caches installed gems automatically + # JS is required in order for webpacker to compile, in order to render templates containing image urls + - uses: actions/setup-node@v3 + with: + node-version-file: .node-version + + - name: Install JS dependencies + run: yarn install --frozen-lockfile + - name: Set up database run: | bundle exec rake db:create db:schema:load @@ -73,59 +81,10 @@ jobs: # https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it #KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/controllers/**/*_spec.rb}" - KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN: "user_passwords_controller_spec|orders_controller_spec|mail_methods_controller_spec|groups_controller_spec|shops_controller_spec|payments_controller_spec" run: | git show --no-patch # the commit being tested (which is often a merge due to actions/checkout@v3) bundle exec rake knapsack_pro:rspec - # Controllers that render views with css or image links will need webpack - controllers_incl_webpack: - runs-on: ubuntu-22.04 - services: - postgres: - image: postgres:10 - ports: ["5432:5432"] - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - env: - POSTGRES_DB: open_food_network_test - POSTGRES_USER: ofn - POSTGRES_PASSWORD: f00d - steps: - - uses: actions/checkout@v3 - - - name: Setup redis - uses: supercharge/redis-github-action@1.4.0 - with: - redis-version: 6 - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - - uses: actions/setup-node@v3 - with: - node-version-file: .node-version - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - - name: Set up database - run: | - bundle exec rake db:create db:schema:load - - - name: Run tests - env: - # Copied from KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN above - INCLUDE_PATTERN: "user_passwords_controller_spec|orders_controller_spec|mail_methods_controller_spec|groups_controller_spec|shops_controller_spec|payments_controller_spec" - run: | - git show --no-patch # the commit being tested (which is often a merge due to actions/checkout@v3) - bundle exec rspec spec/controllers/**/*_spec.rb --pattern="$INCLUDE_PATTERN" - models: runs-on: ubuntu-22.04 services: