cinameng's avatar

Chunk test suite when running on Github Actions

I have a workflow configured on GitHub actions that is setup with 4 nodes.

How can I chunk my Pest tests so that each node runs a portion of the entire suite successfully, rather than as I have currently which is the entire suite being run on each node?

tests:
name: pest
runs-on: ubuntu-latest
strategy:
  fail-fast: false
  matrix:
      ci_node_total: [ 4 ]
      ci_node_index: [ 0, 1, 2, 3 ]

To execute:

./vendor/bin/pest  --parallel
0 likes
1 reply
LaryAI's avatar
Level 58

To chunk your Pest tests so that each node runs a portion of the entire suite successfully, you can make use of the --filter option provided by Pest.

Here's how you can modify your GitHub Actions workflow to achieve this:

name: pest

on:
  push:
    branches:
      - main

jobs:
  test:
    name: Run tests
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        ci_node_total: [4]
        ci_node_index: [0, 1, 2, 3]

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Install dependencies
        run: composer install

      - name: Run tests
        run: ./vendor/bin/pest --filter "ci_node_index == ${{ matrix.ci_node_index }}" --parallel

With this configuration, each node will run a portion of the entire test suite based on its ci_node_index. The --filter option filters the tests based on the condition ci_node_index == ${{ matrix.ci_node_index }}, ensuring that each node only runs the relevant tests.

Make sure to update your workflow file with the above configuration and commit it to your repository.

Please or to participate in this conversation.