CircleCI start running steps in parallel after number of steps

4.3k Views Asked by At

I have a config.yaml for my CirleCI workflow.

I use PHPUnit to run my tests but I would like to start running these in parallel using Circle to speed up the deploy process.

So BuildJob looks like this:

jobs:
  #  build-job
  build-job:
    <<: *defaults  
    resource_class: large
    steps:
      - checkout
      - run: sudo apt install -y libsqlite3-dev zlib1g-dev libpng-dev libxml2-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo docker-php-ext-install gd
      - run: sudo docker-php-ext-install soap
      - run: sudo docker-php-ext-install bcmath
      - run: sudo composer self-update
      - restore_cache:
          keys:
            - composer-v1-{{ checksum "composer.lock" }}
            - composer-v1-
      - run: composer install -n --prefer-dist
      - save_cache:
          key: composer-v1-{{ checksum "composer.lock" }}
          paths:
            - vendor
      - restore_cache:
          keys:
            - node-v1-{{ checksum "package.json" }}
            - node-v1-
      - run: 
          name: Create sqlite db
          command: touch database/database.sqlite
      - run: 
          name: Run tests
          command: ./vendor/bin/phpunit -d memory_limit=512M
      - persist_to_workspace:
          root: ~/laravel
          paths: .

So I know I need to add parallelism: 4 into there before the steps to run them in parallel, as documented here but I need the steps up to Run tests in order. Then I will have multiple run tests steps to hit each folder of tests.

Is there anyway to achieve this?

1

There are 1 best solutions below

4
On BEST ANSWER

The usual approach of using the CircleCI CLI command circleci tests split to split the tests up for parallel containers does not work with phpunit, according to this discussion (https://discuss.circleci.com/t/how-to-execute-phpunit-tests-in-parallel/25622). However, as @matfax is saying, can you run the tests in several logical groups? Something like

./vendor/bin/phpunit tests/ThisGroup
./vendor/bin/phpunit tests/ThatGroup

If so, you could then run each of those commands in a parallel job within a CircleCI workflow.