Trophy for viewing five approaches #12725
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
jobs: | |
setup_env: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 | |
with: | |
sparse-checkout: | | |
.dockerimages.json | |
sparse-checkout-cone-mode: false | |
- name: Define Docker images | |
run: | | |
echo "localstack_image=$(jq -r '.localstack' .dockerimages.json)" >> "$GITHUB_ENV" | |
echo "opensearch_image=$(jq -r '.opensearch' .dockerimages.json)" >> "$GITHUB_ENV" | |
outputs: | |
localstack_image: ${{ env.localstack_image }} | |
opensearch_image: ${{ env.opensearch_image }} | |
################## | |
##### RUBOCOP #### | |
################## | |
rubocop: | |
if: github.repository == 'exercism/website' | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
steps: | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 | |
with: | |
ruby-version: .ruby-version | |
- name: Install gems | |
run: | | |
# Extract the exact versions of the rubocop gems from Gemfile.lock | |
rubocop_version=$(sed -n -E 's/^ rubocop \((.+)\)/\1/p' Gemfile.lock) | |
rubocop_minitest_version=$(sed -n -E 's/^ rubocop-minitest \((.+)\)/\1/p' Gemfile.lock) | |
rubocop_performance_version=$(sed -n -E 's/^ rubocop-performance \((.+)\)/\1/p' Gemfile.lock) | |
rubocop_rails_version=$(sed -n -E 's/^ rubocop-rails \((.+)\)/\1/p' Gemfile.lock) | |
activesupport_version=$(sed -n -E 's/^ activesupport \((.+)\)/\1/p' Gemfile.lock) | |
gem install activesupport -v $activesupport_version | |
gem install rubocop -v $rubocop_version | |
gem install rubocop-minitest -v $rubocop_minitest_version | |
gem install rubocop-performance -v $rubocop_performance_version | |
gem install rubocop-rails -v $rubocop_rails_version | |
- name: Run Rubocop | |
run: rubocop --except Metrics | |
################### | |
##### JS TESTS #### | |
################### | |
js-tests: | |
if: github.repository == 'exercism/website' | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
steps: | |
### | |
# Checkout using GitHub's checkout action | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | |
### | |
# Caching using GitHub's caching action | |
# https://github.com/actions/cache/blob/main/examples.md#node---yarn | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | |
- name: Cache yarn | |
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
### | |
# Install yarn dependencies | |
- name: Install dependencies | |
run: yarn install | |
### | |
# Run the tests | |
- name: Run JS tests | |
run: yarn test | |
##################### | |
##### RUBY TESTS #### | |
##################### | |
ruby-test-files: | |
if: github.repository == 'exercism/website' | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
outputs: | |
matrix: ${{ steps.test-files.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | |
- id: test-files | |
env: | |
FILES_PER_BATCH: 50 | |
run: | | |
tests=$(find test -name '*_test.rb' -not -path 'test/system/*' | xargs -n ${{ env.FILES_PER_BATCH }} | xargs -I {} echo '"{}"' | tr '\n' ',') | |
echo "matrix={\"tests\":[${tests}]}" >> $GITHUB_OUTPUT | |
ruby-tests: | |
if: github.repository == 'exercism/website' | |
needs: | |
- ruby-test-files | |
- setup_env | |
strategy: | |
fail-fast: false | |
max-parallel: 15 | |
matrix: ${{ fromJson(needs.ruby-test-files.outputs.matrix) }} | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
services: | |
mysql: | |
image: mysql:5.7 | |
env: | |
MYSQL_USER: exercism | |
MYSQL_PASSWORD: exercism | |
MYSQL_DATABASE: exercism_test | |
MYSQL_ROOT_PASSWORD: password | |
ports: | |
- 3306 | |
#options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10 | |
redis: | |
image: redis | |
ports: | |
- 6379:6379 | |
options: >- | |
--health-cmd "redis-cli ping" | |
--health-interval 1s | |
--health-timeout 2s | |
--health-retries 10 | |
aws: | |
image: ${{ needs.setup_env.outputs.localstack_image }} | |
ports: | |
- 4566 | |
opensearch: | |
image: ${{ needs.setup_env.outputs.opensearch_image }} | |
env: | |
discovery.type: single-node | |
ports: | |
- 9200 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 | |
with: | |
ruby-version: .ruby-version | |
bundler-cache: true | |
- name: Update package lists | |
run: sudo apt-get update | |
- name: Install packages | |
run: sudo apt-get install graphicsmagick libvips | |
### | |
# Caching using GitHub's caching action | |
# https://github.com/actions/cache/blob/main/examples.md#node---yarn | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | |
- name: Cache yarn | |
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install yarn dependencies | |
run: yarn install | |
- name: Setup Exercism services | |
env: | |
EXERCISM_ENV: test | |
EXERCISM_CI: true | |
AWS_PORT: ${{ job.services.aws.ports['4566'] }} | |
MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }} | |
run: | | |
bundle exec setup_exercism_config | |
bundle exec setup_exercism_local_aws | |
### | |
# Precompile JS | |
- name: Precompile JS | |
env: | |
RAILS_ENV: test | |
NODE_ENV: development | |
EXERCISM_CI: true | |
AWS_PORT: ${{ job.services.aws.ports['4566'] }} | |
MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }} | |
run: | | |
bundle exec rails r bin/monitor-manifest | |
bundle exec rails test:prepare | |
### | |
# Wait for everything to be ready | |
- name: Wait for open search to become ready | |
env: | |
OPENSEARCH_HOST: https://127.0.0.1:${{ job.services.opensearch.ports['9200'] }} | |
run: ./bin/wait_for_opensearch | |
### | |
# Run the tests | |
- name: Run Ruby tests | |
env: | |
RAILS_ENV: test | |
EXERCISM_CI: true | |
AWS_PORT: ${{ job.services.aws.ports['4566'] }} | |
MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }} | |
OPENSEARCH_PORT: ${{ job.services.opensearch.ports['9200'] }} | |
OPENSEARCH_HOST: https://127.0.0.1:${{ job.services.opensearch.ports['9200'] }} | |
OPENSEARCH_VERIFY_SSL: false | |
run: | | |
bundle exec rails test:zeitwerk | |
bundle exec rails test ${{ matrix.tests }} | |
ruby-tests-completed: | |
runs-on: ubuntu-22.04 | |
needs: ruby-tests | |
steps: | |
- run: echo "Ruby tests completed" | |
####################### | |
##### SYSTEM TESTS #### | |
####################### | |
system-test-files: | |
if: github.repository == 'exercism/website' | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
outputs: | |
matrix: ${{ steps.test-files.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | |
- id: test-files | |
env: | |
FILES_PER_BATCH: 12 | |
run: | | |
tests=$(find test/system -name *_test.rb | xargs -n ${{ env.FILES_PER_BATCH }} | xargs -I {} echo '"{}"' | tr '\n' ',') | |
echo "matrix={\"tests\":[${tests}]}" >> $GITHUB_OUTPUT | |
system-tests: | |
if: github.repository == 'exercism/website' | |
needs: | |
- system-test-files | |
- setup_env | |
strategy: | |
fail-fast: false | |
max-parallel: 15 | |
matrix: ${{ fromJson(needs.system-test-files.outputs.matrix) }} | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
services: | |
mysql: | |
image: mysql:5.7 | |
env: | |
MYSQL_USER: exercism | |
MYSQL_PASSWORD: exercism | |
MYSQL_DATABASE: exercism_test | |
MYSQL_ROOT_PASSWORD: password | |
ports: | |
- 3306 | |
redis: | |
image: redis | |
ports: | |
- 6379:6379 | |
options: >- | |
--health-cmd "redis-cli ping" | |
--health-interval 1s | |
--health-timeout 2s | |
--health-retries 10 | |
aws: | |
image: ${{ needs.setup_env.outputs.localstack_image }} | |
ports: | |
- 4566 | |
opensearch: | |
image: ${{ needs.setup_env.outputs.opensearch_image }} | |
env: | |
discovery.type: single-node | |
ports: | |
- 9200 | |
steps: | |
### | |
# Checkout using GitHub's checkout action | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | |
### | |
# Setup Ruby - this needs to match the version in the Gemfile | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 | |
with: | |
ruby-version: .ruby-version | |
bundler-cache: true | |
- name: Update package lists | |
run: sudo apt-get update | |
- name: Install packages | |
run: sudo apt-get install libvips | |
### | |
# Caching using GitHub's caching action | |
# https://github.com/actions/cache/blob/main/examples.md#node---yarn | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | |
- name: Cache yarn | |
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install yarn dependencies | |
run: yarn install | |
- name: Setup Exercism services | |
env: | |
EXERCISM_ENV: test | |
EXERCISM_CI: true | |
AWS_PORT: ${{ job.services.aws.ports['4566'] }} | |
MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }} | |
run: | | |
bundle exec setup_exercism_config | |
bundle exec setup_exercism_local_aws | |
### | |
# Precompile JS | |
- name: Precompile JS | |
env: | |
RAILS_ENV: test | |
NODE_ENV: development | |
EXERCISM_CI: true | |
AWS_PORT: ${{ job.services.aws.ports['4566'] }} | |
MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }} | |
run: | | |
bundle exec rails r bin/monitor-manifest | |
bundle exec rails test:prepare | |
### | |
# Wait for everything to be ready | |
- name: Wait for open search to become ready | |
env: | |
OPENSEARCH_HOST: https://127.0.0.1:${{ job.services.opensearch.ports['9200'] }} | |
run: ./bin/wait_for_opensearch | |
### | |
# Run the tests | |
- name: Run Ruby system tests | |
env: | |
RAILS_ENV: test | |
EXERCISM_CI: true | |
AWS_PORT: ${{ job.services.aws.ports['4566'] }} | |
MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }} | |
OPENSEARCH_PORT: ${{ job.services.opensearch.ports['9200'] }} | |
OPENSEARCH_HOST: https://127.0.0.1:${{ job.services.opensearch.ports['9200'] }} | |
OPENSEARCH_VERIFY_SSL: false | |
run: bundle exec rails test ${{ matrix.tests }} | |
system-tests-completed: | |
runs-on: ubuntu-22.04 | |
needs: system-tests | |
steps: | |
- run: echo "System tests completed" | |
###################### | |
##### ASSET TESTS #### | |
###################### | |
asset-tests: | |
if: github.repository == 'exercism/website' | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
steps: | |
### | |
# Checkout using GitHub's checkout action | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | |
### | |
# Setup Ruby - this needs to match the version in the Gemfile | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 | |
with: | |
ruby-version: .ruby-version | |
bundler-cache: true | |
### | |
# Caching using GitHub's caching action | |
# https://github.com/actions/cache/blob/main/examples.md#node---yarn | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | |
- name: Cache yarn | |
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
### | |
# Install bundler and yarn dependencies | |
- name: Install dependencies | |
env: | |
EXERCISM_ENV: test | |
EXERCISM_CI: true | |
AWS_PORT: ${{ job.services.aws.ports['4566'] }} | |
MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }} | |
OPENSEARCH_PORT: ${{ job.services.opensearch.ports['9200'] }} | |
run: | | |
yarn install | |
- name: Run asset tests | |
env: | |
RAILS_ENV: test | |
EXERCISM_CI: true | |
run: bundle exec rails r bin/monitor-manifest | |
bundle exec rails test:prepare |