ユーザーアイコン

mizuko

約1か月前

0
0

GitHub Actions の matrix strategy でテストを並列実行する

Next.js
GithubActions

テストの速度改善のため、Github Actionsでdocker composeを使いつつテストを並列で実行する。

jobs: test: runs-on: ubuntu-22.04 timeout-minutes: 15 strategy: matrix: shard: [1, 2, 3, 4] fail-fast: false steps: ~ ~ - name: Setup database run: docker compose up mysql -d - name: Run tests (Shard ${{ matrix.shard }}) working-directory: ./hoge env: DATABASE_NAME: hoge DATABASE_PORT: 3501 SHARD_ID: ${{ matrix.shard }} SHARD_TOTAL: ${{ strategy.job-total }} run: npm run test:shard

package.jsonには以下を定義しておく

"test:shard": "jest --shard=$SHARD_ID/$SHARD_TOTAL",

速度は1/4ほどに改善された。