From dc30633bc302fafc49f758ba18c8f2bfd0a2cda3 Mon Sep 17 00:00:00 2001 From: taroj1205 Date: Sun, 22 Jun 2025 18:01:36 +1200 Subject: [PATCH] feat(ci): enhance Playwright test sharding and caching --- .github/workflows/ci-pipeline.yml | 18 ++++++------------ package.json | 4 ++++ turbo.json | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index 70d5ca4..af6dc5c 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -179,14 +179,10 @@ jobs: retention-days: 1 playwright: - name: Playwright Tests (Shard ${{ matrix.shard }}) + name: Playwright Tests needs: [check_changes, setup, build] if: ${{ needs.check_changes.outputs.exists == 'true' }} runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - shard: [1, 2, 3, 4] steps: - uses: actions/checkout@v4 with: @@ -202,10 +198,8 @@ jobs: uses: actions/cache@v4 with: path: .turbo - key: ${{ runner.os }}-turbo-playwright-shard-${{ matrix.shard }}-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-turbo-playwright-shard-${{ matrix.shard }}- - ${{ runner.os }}-turbo-playwright- + key: ${{ runner.os }}-turbo-playwright-${{ github.sha }} + restore-keys: ${{ runner.os }}-turbo-playwright- - name: Restore Astro Cache uses: actions/cache@v4 @@ -252,15 +246,15 @@ jobs: - name: Install Playwright Browsers run: pnpm exec playwright install --with-deps - - name: Run Playwright Tests (Shard ${{ matrix.shard }}/4) - run: pnpm exec turbo run test:playwright -- --shard=${{ matrix.shard }}/4 + - name: Run Playwright Tests (4 Shards) + run: pnpm exec turbo run test:playwright:shard1 test:playwright:shard2 test:playwright:shard3 test:playwright:shard4 timeout-minutes: 10 - name: Upload Playwright Report uses: actions/upload-artifact@v4 if: always() with: - name: playwright-report-shard-${{ matrix.shard }} + name: playwright-report path: playwright-report/ retention-days: 7 diff --git a/package.json b/package.json index 7f693c1..e0230c1 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,10 @@ "test": "vitest run", "test:coverage": "vitest --coverage", "test:playwright": "playwright test --reporter=list", + "test:playwright:shard1": "playwright test --reporter=list --shard=1/4", + "test:playwright:shard2": "playwright test --reporter=list --shard=2/4", + "test:playwright:shard3": "playwright test --reporter=list --shard=3/4", + "test:playwright:shard4": "playwright test --reporter=list --shard=4/4", "prepare": "lefthook install" }, "dependencies": { diff --git a/turbo.json b/turbo.json index fa8f070..b42fcbd 100644 --- a/turbo.json +++ b/turbo.json @@ -34,6 +34,26 @@ "cache": true, "inputs": ["**/*.{ts,tsx,js,jsx,astro}"], "outputs": ["playwright-report/**", "test-results/**"] + }, + "test:playwright:shard1": { + "cache": true, + "inputs": ["**/*.{ts,tsx,js,jsx,astro}"], + "outputs": ["playwright-report/**", "test-results/**"] + }, + "test:playwright:shard2": { + "cache": true, + "inputs": ["**/*.{ts,tsx,js,jsx,astro}"], + "outputs": ["playwright-report/**", "test-results/**"] + }, + "test:playwright:shard3": { + "cache": true, + "inputs": ["**/*.{ts,tsx,js,jsx,astro}"], + "outputs": ["playwright-report/**", "test-results/**"] + }, + "test:playwright:shard4": { + "cache": true, + "inputs": ["**/*.{ts,tsx,js,jsx,astro}"], + "outputs": ["playwright-report/**", "test-results/**"] } }, "ui": "tui"