Techioz Blog

GithubアクションでのParallel_testsの使用方法

概要

github アクションでParallel_tests を使用してテスト スイートを実行しようとしていますが、適切な解決策が見つかりませんでした。 公式ドキュメントには 1 つありますが、これは gitlab 用です。

https://translate.google.com/translate?hl=ja&sl=en&tl=ja&u=https://github.com/grosser/parallel_tests/wiki/Distributed-Parallel-Tests-on-CI-systems

助けていただければ幸いです、ありがとう!

解決策

.github/workflows/tests.yml にドロップできるサンプル ワークフローを次に示します。

name: Rails Tests

on: push

env:
  PGHOST: localhost
  PGUSER: postgres
  RAILS_ENV: test

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: true
      matrix:
        # Set N number of parallel jobs you want to run
        # Remember to update ci_node_index below to 0..N-1
        ci_node_total: [6]
        # set N-1 indexes for parallel jobs
        # When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
        ci_node_index: [0, 1, 2, 3, 4, 5]

    services:
      postgres:
        image: postgres:11.5
        ports: ["5432:5432"]
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
      redis:
        image: redis:5
        ports: ["6379:6379"]

    steps:
    - uses: actions/checkout@v1

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

    - name: Set node version (from .tool-versions)
      run: echo "NODE_VERSION=$(cat .tool-versions | grep nodejs | sed 's/^nodejs //')" >> $GITHUB_ENV

    - uses: actions/setup-node@v2
      with:
        node-version: ${{ env.NODE_VERSION }}

    - uses: bahmutov/npm-install@v1

    - name: Install PostgreSQL client
      run: |
        sudo apt-get -yqq install libpq-dev postgresql-client

    - name: Test Prep
      env:
        CI_NODE_INDEX: ${{ matrix.ci_node_index }}
      run: |
        bundle exec rake parallel:create["1"] parallel:load_schema["1"]

    - name: Run tests
      env:
        RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
        CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
        CI_NODE_INDEX: ${{ matrix.ci_node_index }}
      run : |
        bundle exec parallel_test spec/ -n $CI_NODE_TOTAL --only-group $CI_NODE_INDEX --type rspec