Parallel tests with GitHub Actions
source link: https://kittygiraudel.com/2023/01/01/parallel-tests-with-github-actions/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Parallel tests with GitHub ActionsSkip to main content
January 1st, 2023 · ~1 minutes
First post of the year! I’ve been spending quite some time on my Advent of Code repository in December and decided I wanted to run the tests in a GitHub workflow. A short and sweet post about it.
The test suite is pretty slow though, since Advent of Code involves some brute-forcing exercises which take a long time to run. So the idea is to parallelize the tests so they don’t take as long.
I have 8 different folders: one folder per year since 2015. We can use a matrix to create multiple job runs in parallel.
strategy:
fail-fast: false
matrix:
year: [2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]
Then in our step, we can access the name of the job (and the name of our folder) and pass it to our npm test
command (which uses Jest, or Mocha or Ava or whatever under the hood).
- name: Run tests
run: npm test -- ${{ matrix.year }}
That’s it, happy new year! ✨ You can check the code for the whole GitHub Workflow if you want.
name: Tests
on: [push]
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
year: [2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Unlock input files
uses: sliteteam/[email protected]
env:
GIT_CRYPT_KEY: $
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 18
cache: npm
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test -- $
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK