name: Playwright Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Install Playwright
run: npx playwright install --with-deps
- name: Run Playwright Tests
shell: bash
env:
TESTDINO_TOKEN: ${{ secrets.TESTDINO_TOKEN }}
SHARD_INDEX: ${{ matrix.shardIndex }}
SHARD_TOTAL: ${{ matrix.shardTotal }}
run: |
echo "GitHub run attempt: ${{ github.run_attempt }}"
# Case 1: Re-run failed jobs → run only failed tests
if [[ "${{ github.run_attempt }}" -gt 1 ]]; then
echo "Detected re-run. Executing only last failed tests via TestDino."
npx tdpw last-failed --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} > last-failed-flags.txt
EXTRA_PW_FLAGS="$(cat last-failed-flags.txt)"
if [[ -z "$EXTRA_PW_FLAGS" ]]; then
echo "No failed tests found. Exiting."
exit 0
fi
echo "Running failed tests without sharding:"
echo "$EXTRA_PW_FLAGS"
# IMPORTANT: preserve quotes
eval "npx playwright test $EXTRA_PW_FLAGS"
exit 0
fi
# Case 2: Normal execution (first run)
echo "Running all Playwright tests"
npx playwright test \
--shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
- name: Cache rerun metadata
if: always()
run: npx tdpw cache --token="${{ secrets.TESTDINO_TOKEN }}"
- name: Upload test reports
if: always()
run: npx tdpw upload ./playwright-report --token="${{ secrets.TESTDINO_TOKEN }}" --upload-full-json