Skip to content
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

Improve CI run time #8348

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ jobs:
test-ruby:
name: Test Ruby
uses: ./.github/workflows/minitest.yml

test-ruby-parallel:
name: Test Ruby
uses: ./.github/workflows/minitest-parallel.yml

integration-tests-parallel:
name: Integration tests
uses: ./.github/workflows/integration-tests-parallel.yml

integration-tests:
name: Integration tests
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/integration-tests-parallel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Run integration tests

on: workflow_call

jobs:
run-parallel-integration-tests:
name: Run integration tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node_rake_task: ["cucumber:ok", "cucumber:preview_design_system"]
steps:
- name: Setup MySQL
id: setup-mysql
uses: alphagov/govuk-infrastructure/.github/actions/setup-mysql@main

- name: Setup Redis
uses: alphagov/govuk-infrastructure/.github/actions/setup-redis@main

- name: Install additional system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends ghostscript
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Setup Node
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main

- name: Precompile assets
uses: alphagov/govuk-infrastructure/.github/actions/precompile-rails-assets@main

- name: Initialize database
env:
RAILS_ENV: test
TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }}
run: bundle exec rails db:setup

- name: Run cucumber
env:
RAILS_ENV: test
TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }}
run: bundle exec rails ${{ matrix.node_rake_task }}

- name: Upload screenshots
uses: actions/upload-artifact@v3
if: failure()
with:
name: capybara-screenshots
path: tmp/capybara/capybara-*.png
79 changes: 79 additions & 0 deletions .github/workflows/minitest-parallel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Run Minitest

on:
workflow_call:
inputs:
ref:
description: 'The branch, tag or SHA to checkout'
required: false
type: string
publishingApiRef:
description: 'The branch, tag or SHA to checkout Publishing API'
required: false
default: 'main'
type: string

jobs:
run-minitest:
name: Run Minitest
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ci_node_total: [4]
ci_node_index: [0, 1, 2, 3]
steps:
- name: Setup MySQL
id: setup-mysql
uses: alphagov/govuk-infrastructure/.github/actions/setup-mysql@main

- name: Setup Redis
uses: alphagov/govuk-infrastructure/.github/actions/setup-redis@main

- name: Install additional system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends ghostscript

- name: Checkout repository
uses: actions/checkout@v4
with:
repository: alphagov/whitehall
ref: ${{ inputs.ref || github.ref }}

- name: Checkout Publishing API (for Content Schemas)
uses: actions/checkout@v4
with:
repository: alphagov/publishing-api
ref: ${{ inputs.publishingApiRef }}
path: vendor/publishing-api

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Setup Node
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main

- name: Precompile assets
uses: alphagov/govuk-infrastructure/.github/actions/precompile-rails-assets@main

- name: Initialize database
env:
RAILS_ENV: test
TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }}
run: bundle exec rails db:setup

- name: Make bin/minitest-ci executable
run: chmod +x ./bin/minitest-ci

- name: Run Minitest
env:
RAILS_ENV: test
GOVUK_CONTENT_SCHEMAS_PATH: vendor/publishing-api/content_schemas
TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }}
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
run: |
./bin/minitest-ci
11 changes: 11 additions & 0 deletions bin/minitest-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby

tests = Dir["test/**/*_test.rb"].
sort.
shuffle(random: Random.new(ENV['GITHUB_SHA'].to_i(16))).
select.
with_index do |el, i|
i % ENV["CI_NODE_TOTAL"].to_i == ENV["CI_NODE_INDEX"].to_i
end

exec "bundle exec rails test #{tests.join(" ")}"