如何在 github actions 中使用parallel_tests

ano*_*ous 4 ruby ruby-on-rails github-actions parallel-tests

我试图在我的 github 操作中使用parallel_tests 来运行我的测试套件,但我无法找到合适的解决方案。官方文档有一个,但它是针对 gitlab 的:

https://github.com/grosser/parallel_tests/wiki/Distributed-Parallel-Tests-on-CI-systems

任何帮助将不胜感激,谢谢!

Ben*_*tis 5

这是您可以放入的示例工作流程.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
Run Code Online (Sandbox Code Playgroud)