From d6c216840e1c3f398700aaeeca5934f52591deed Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 12 Apr 2021 14:30:01 +1000 Subject: [PATCH 1/4] Use matrix to split jobs This demonstrates how you can split the tests across multiple jobs without repeating the job configuration. This has a lot of potential to DRY our config. --- .github/workflows/build.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34434d92a7..c88dc71f8f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,6 +28,11 @@ jobs: POSTGRES_DB: open_food_network_test POSTGRES_USER: ofn POSTGRES_PASSWORD: f00d + strategy: + matrix: + specs: + - "spec/controllers" + - "spec/serializers" steps: - uses: actions/checkout@v2 @@ -52,7 +57,7 @@ jobs: bundle exec rake db:schema:load RAILS_ENV=test - name: Run controller tests - run: bundle exec rspec --profile -- spec/controllers spec/serializers + run: bundle exec rspec --profile -- ${{ matrix.specs }} test-models: runs-on: ubuntu-18.04 From a4db3b675d8b6f8ac8491d257e59c4755fbc842a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 28 Sep 2021 13:27:03 +1000 Subject: [PATCH 2/4] DRY actions config with matrix syntax This uses the matrix syntax for all rspec calls. It is easier to maintain than the previous list of GH Actions workflows. The execution of the rspec rake task is still in its own job because it doesn't fit in the same pattern. The JS tests are also executed in that job. --- .github/workflows/build.yml | 226 ++---------------------------------- 1 file changed, 11 insertions(+), 215 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c88dc71f8f..ca08649e82 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ env: RAILS_ENV: test jobs: - test-controllers-and-serializers: + rspec: runs-on: ubuntu-18.04 services: postgres: @@ -32,7 +32,16 @@ jobs: matrix: specs: - "spec/controllers" + - "spec/models" + - "spec/features/admin/[a-o0-9]*_spec.rb" + - "spec/features/admin/[p-z]*_spec.rb" + - "spec/features/admin/*/*_spec.rb" + - "spec/features/consumer" + - "spec/lib" + - "spec/migrations" - "spec/serializers" + - "spec/system" + - "engines/*/spec" steps: - uses: actions/checkout@v2 @@ -59,171 +68,7 @@ jobs: - name: Run controller tests run: bundle exec rspec --profile -- ${{ matrix.specs }} - test-models: - runs-on: ubuntu-18.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@v2 - - - 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@v2 - with: - node-version: '14.15.5' - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - - name: Set up application.yml - run: cp config/application.yml.example config/application.yml - - - name: Set up database - run: | - bundle exec rake db:create RAILS_ENV=test - bundle exec rake db:schema:load RAILS_ENV=test - - - name: Run tests - run: bundle exec rspec --profile -- spec/models - - test-admin-features-1: - runs-on: ubuntu-18.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@v2 - - - 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@v2 - with: - node-version: '14.15.5' - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - - name: Set up application.yml - run: cp config/application.yml.example config/application.yml - - - name: Set up database - run: | - bundle exec rake db:create RAILS_ENV=test - bundle exec rake db:schema:load RAILS_ENV=test - - - name: Run admin feature tests - run: bundle exec rspec --profile -- spec/features/admin/[a-o0-9]*_spec.rb - - test-admin-features-2: - runs-on: ubuntu-18.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@v2 - - - 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@v2 - with: - node-version: '14.15.5' - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - - name: Set up application.yml - run: cp config/application.yml.example config/application.yml - - - name: Set up database - run: | - bundle exec rake db:create RAILS_ENV=test - bundle exec rake db:schema:load RAILS_ENV=test - - - name: Run admin feature tests - run: bundle exec rspec --profile -- spec/features/admin/[p-z]*_spec.rb - - test-consumer-features: - runs-on: ubuntu-18.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@v2 - - - 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@v2 - with: - node-version: '14.15.5' - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - - name: Set up application.yml - run: cp config/application.yml.example config/application.yml - - - name: Set up database - run: | - bundle exec rake db:create RAILS_ENV=test - bundle exec rake db:schema:load RAILS_ENV=test - - - name: Run consumer feature tests - run: bundle exec rspec --profile -- spec/features/consumer - - test-engines-etc: + test-the-rest: runs-on: ubuntu-18.04 services: postgres: @@ -267,54 +112,5 @@ jobs: - name: Run jest tests run: yarn jest - # Migration tests need to be run in a separate task. - # See: https://github.com/openfoodfoundation/openfoodnetwork/pull/6924#issuecomment-813056525 - - name: Run migration tests - run: bundle exec rspec --pattern "spec/{migrations}/**/*_spec.rb" - - - name: Run system tests - run: bundle exec rspec --profile -- spec/system - - name: Run all other tests run: bundle exec rake ofn:specs:run:excluding_folders["models,controllers,serializers,features,lib,migrations,system"] - - test-the-rest: - runs-on: ubuntu-18.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@v2 - - - 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@v2 - with: - node-version: '14.15.5' - - - name: Install JS dependencies - run: yarn install --frozen-lockfile - - - name: Set up application.yml - run: cp config/application.yml.example config/application.yml - - - name: Set up database - run: | - bundle exec rake db:create RAILS_ENV=test - bundle exec rake db:schema:load RAILS_ENV=test - - - name: Run admin feature folders, engines, lib - run: bundle exec rspec --profile --pattern "engines/*/spec/{,/*/**}/*_spec.rb,spec/features/admin/*/*_spec.rb,spec/lib/{,/*/**}/*_spec.rb" From 9ccb744ef31d93289ce0e3da2464bbab71bef1b0 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 28 Sep 2021 13:34:31 +1000 Subject: [PATCH 3/4] Remove superfluous env parameter It's already defined globally. --- .github/workflows/build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca08649e82..8b1d612cb0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,8 +62,8 @@ jobs: - name: Set up database run: | - bundle exec rake db:create RAILS_ENV=test - bundle exec rake db:schema:load RAILS_ENV=test + bundle exec rake db:create + bundle exec rake db:schema:load - name: Run controller tests run: bundle exec rspec --profile -- ${{ matrix.specs }} @@ -103,11 +103,11 @@ jobs: - name: Set up database run: | - bundle exec rake db:create RAILS_ENV=test - bundle exec rake db:schema:load RAILS_ENV=test + bundle exec rake db:create + bundle exec rake db:schema:load - name: Run JS tests - run: RAILS_ENV=test bundle exec rake karma:run + run: bundle exec rake karma:run - name: Run jest tests run: yarn jest From 61333a958e91f87bebb1b41c29ffec8fce0776f2 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 18 Jun 2021 17:31:57 +1000 Subject: [PATCH 4/4] Continue all jobs when one failed It's nice to see the whole result to then work on all failures, especially when there are flaky specs. --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b1d612cb0..f636dbbfa3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,7 @@ jobs: - "spec/serializers" - "spec/system" - "engines/*/spec" + fail-fast: false steps: - uses: actions/checkout@v2