Skip to content

Commit

Permalink
Merge pull request #2586 from hitobito/specs-in-parallel
Browse files Browse the repository at this point in the history
Run core specs in parallel
  • Loading branch information
carlobeltrame committed Apr 29, 2024
2 parents 4d57825 + f99654e commit b584e2f
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 60 deletions.
77 changes: 77 additions & 0 deletions .github/actions/core-ci-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: 'Setup steps for core CI'
description: 'DRY yaml setup setup steps which are used multiple times in the core CI workflow'

inputs:
migrations:
description: Unless set to false, migrations will be run as part of the setup.
default: true

runs:
using: composite
steps:
- name: 'Set up Ruby'
uses: ruby/setup-ruby@v1
env:
ImageOS: ubuntu20

- name: Read .tool-versions
uses: marocchino/tool-versions-action@v1
id: readToolVersions

- name: Set up Node.js ${{ steps.readToolVersions.outputs.nodejs }}
uses: actions/setup-node@v4
with:
node-version: ${{ steps.readToolVersions.outputs.nodejs }}

- name: 'Setup OS'
run: |
sudo apt-get -qq update
sudo apt-get install sphinxsearch
echo "ruby version: $(ruby -v)"
echo "bundle version: $(bundle -v)"
echo "node version: $(node -v)"
echo "yarn version: $(yarn -v)"
shell: bash

- name: 'create cache key'
run: cp Gemfile.lock Gemfile.lock.backup
shell: bash

- uses: actions/cache@v4
with:
path: vendor/bundle
key: ${{ runner.os }}-ruby-bundle-${{ hashFiles('**/Gemfile.lock.backup') }}
restore-keys: |
${{ runner.os }}-ruby-bundle-
- name: 'Bundle install'
run: |
bundle install --jobs 4 --retry 3 --path vendor/bundle
shell: bash

- name: 'Make changes to Gemfile.lock transparent'
run: git diff Gemfile.lock || true
shell: bash

- uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node_modules-
- name: 'Yarn install'
run: |
yarn install --frozen-lockfile
shell: bash

- name: 'Run Webpacker'
run: |
bundle exec rake webpacker:compile
shell: bash

- name: 'Run db migrations'
if: inputs.migrations
run: |
bundle exec rake db:migrate
shell: bash
156 changes: 96 additions & 60 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,23 @@ on:
- '**.md'

jobs:
build:
rubocop:
runs-on: 'ubuntu-20.04'

steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: 'Prepare'
uses: ./.github/actions/core-ci-setup
with:
migrations: false

- name: 'Rubocop'
run: |
bundle exec rake rubocop
main-specs:
runs-on: 'ubuntu-20.04'
env:
HEADLESS: true
Expand Down Expand Up @@ -49,76 +65,96 @@ jobs:
- name: 'Checkout'
uses: actions/checkout@v4

- name: 'Set up Ruby'
uses: ruby/setup-ruby@v1
env:
ImageOS: ubuntu20

- name: Read .tool-versions
uses: marocchino/tool-versions-action@v1
id: readToolVersions

- name: Set up Node.js ${{ steps.readToolVersions.outputs.nodejs }}
uses: actions/setup-node@v4
with:
node-version: ${{ steps.readToolVersions.outputs.nodejs }}
- name: 'Prepare'
uses: ./.github/actions/core-ci-setup

- name: 'Setup OS'
- name: 'Main Specs without features'
run: |
sudo apt-get -qq update
sudo apt-get install sphinxsearch
echo "ruby version: $(ruby -v)"
echo "bundle version: $(bundle -v)"
echo "node version: $(node -v)"
echo "yarn version: $(yarn -v)"
- name: 'create cache key'
run: cp Gemfile.lock Gemfile.lock.backup

- uses: actions/cache@v4
with:
path: vendor/bundle
key: ${{ runner.os }}-ruby-bundle-${{ hashFiles('**/Gemfile.lock.backup') }}
restore-keys: |
${{ runner.os }}-ruby-bundle-
bundle exec rake ci:setup:env spec:without_features
- name: 'Bundle install'
run: |
bundle install --jobs 4 --retry 3 --path vendor/bundle
sphinx-specs:
runs-on: 'ubuntu-20.04'
env:
HEADLESS: true
RAILS_DB_ADAPTER: mysql2
RAILS_DB_HOST: 127.0.0.1
RAILS_DB_PORT: 33066
RAILS_DB_USERNAME: hitobito
RAILS_DB_PASSWORD: hitobito
RAILS_DB_NAME: hitobito_test
RAILS_TEST_DB_NAME: hitobito_test
TZ: Europe/Berlin
RAILS_USE_TEST_GROUPS: true

- name: 'Make changes to Gemfile.lock transparent'
run: git diff Gemfile.lock || true
services:
mysql:
image: 'mysql:5.7'
env:
MYSQL_USER: 'hitobito'
MYSQL_PASSWORD: 'hitobito'
MYSQL_DATABASE: 'hitobito_test'
MYSQL_ROOT_PASSWORD: 'root'
ports:
- '33066:3306'
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 10s
--health-retries 10
memcached:
image: 'memcached'
ports: [ '11211:11211' ]

- uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node_modules-
steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: 'Yarn install'
run: |
yarn install --frozen-lockfile
- name: 'Prepare'
uses: ./.github/actions/core-ci-setup

- name: 'Run Webpacker'
- name: 'Sphinx'
run: |
bundle exec rake webpacker:compile
bundle exec rake ci:setup:env spec:sphinx
- name: 'Rubocop'
run: |
bundle exec rake rubocop
feature-specs:
runs-on: 'ubuntu-20.04'
env:
HEADLESS: true
RAILS_DB_ADAPTER: mysql2
RAILS_DB_HOST: 127.0.0.1
RAILS_DB_PORT: 33066
RAILS_DB_USERNAME: hitobito
RAILS_DB_PASSWORD: hitobito
RAILS_DB_NAME: hitobito_test
RAILS_TEST_DB_NAME: hitobito_test
TZ: Europe/Berlin
RAILS_USE_TEST_GROUPS: true

- name: 'Run db migrations'
run: |
bundle exec rake db:migrate
services:
mysql:
image: 'mysql:5.7'
env:
MYSQL_USER: 'hitobito'
MYSQL_PASSWORD: 'hitobito'
MYSQL_DATABASE: 'hitobito_test'
MYSQL_ROOT_PASSWORD: 'root'
ports:
- '33066:3306'
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 10s
--health-retries 10
memcached:
image: 'memcached'
ports: [ '11211:11211' ]

- name: 'Main Specs without features'
run: |
bundle exec rake ci:setup:env spec:without_features
steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: 'Sphinx'
run: |
bundle exec rake ci:setup:env spec:sphinx
- name: 'Prepare'
uses: ./.github/actions/core-ci-setup

- name: 'Features'
run: |
Expand All @@ -134,7 +170,7 @@ jobs:
notify_statuscope:
uses: ./.github/workflows/notify-statuscope.yml
needs: [ build ]
needs: [ rubocop, main-specs, sphinx-specs, feature-specs ]
if: ( success() || failure() ) && ( github.ref_name == 'master' )
with:
repository: 'hitobito'
Expand Down

0 comments on commit b584e2f

Please sign in to comment.