This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Playwright Tests | |
| on: | |
| push: | |
| branches: [main, 'feat/browserstack'] | |
| permissions: | |
| contents: read | |
| jobs: | |
| prepare: | |
| name: Prepare Companion build | |
| timeout-minutes: 10 | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.matrix.outputs.matrix }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.node-version' | |
| - name: Prepare | |
| id: prepare | |
| run: | | |
| corepack enable | |
| # try and avoid timeout errors | |
| yarn config set httpTimeout 100000 | |
| yarn --immutable | |
| yarn dist:mini | |
| - name: Upload companion build | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: companion-dist | |
| path: dist | |
| - name: Build matrix JSON from browserstack.yml | |
| id: matrix | |
| run: | | |
| # Create a JSON matrix that GH Actions can consume, reading platforms from playwright/browserstack.yml | |
| python - <<'PY' | |
| import yaml, json, sys | |
| path = 'playwright/browserstack.yml' | |
| with open(path) as f: | |
| data = yaml.safe_load(f) | |
| platforms = data.get('platforms', []) | |
| if not platforms: | |
| print('::error::No platforms found in browserstack.yml') | |
| sys.exit(1) | |
| matrix = { 'include': [] } | |
| for p in platforms: | |
| # build a human-friendly name for the matrix entry | |
| os = p.get('os') or p.get('deviceName') or '' | |
| osVersion = p.get('osVersion') or '' | |
| browserName = p.get('browserName') or '' | |
| browserVersion = p.get('browserVersion') or '' | |
| name = f"{os}@{osVersion} - {browserName}@{browserVersion}" | |
| matrix['include'].append({'platform': json.dumps(p), 'name': name}) | |
| print('::set-output name=matrix::' + json.dumps(matrix)) | |
| PY | |
| test: | |
| needs: prepare | |
| name: Playwright ${{ matrix.name }} | |
| timeout-minutes: 60 | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{fromJson(needs.prepare.outputs.matrix)}} | |
| max-parallel: 3 | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.node-version' | |
| - name: Prepare | |
| id: prepare | |
| run: | | |
| corepack enable | |
| # try and avoid timeout errors | |
| yarn config set httpTimeout 100000 | |
| yarn --immutable | |
| - name: Download companion build | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: companion-dist | |
| - name: 'BrowserStack Env Setup' | |
| uses: 'browserstack/github-actions/[email protected]' | |
| with: | |
| username: ${{ secrets.BROWSERSTACK_USERNAME }} | |
| access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} | |
| - name: Prepare single-platform browserstack.yml | |
| run: | | |
| mkdir -p playwright | |
| python - <<'PY' | |
| import json, yaml, sys | |
| entry = json.loads('''${{ matrix.platform }}''') | |
| cfg = yaml.safe_load(open('playwright/browserstack.yml')) | |
| cfg['platforms'] = [entry] | |
| with open('playwright/browserstack.yml', 'w') as f: | |
| yaml.safe_dump(cfg, f) | |
| print('Wrote single-platform playwright/browserstack.yml') | |
| PY | |
| - name: Spawn Companion | |
| run: | | |
| # Start Companion from the downloaded build | |
| node dist/main.js --machine-id ci_browserstack --log-level debug & | |
| export COMPANION_PID=$! | |
| yarn wait-on http://localhost:8000 --timeout 30000 --delay 5000 | |
| - name: Run Playwright tests | |
| run: | | |
| cd playwright | |
| # Ensure single worker to avoid parallelism inside the runner | |
| yarn test:ci --workers=1 | |
| - uses: actions/upload-artifact@v4 | |
| if: ${{ !cancelled() }} | |
| with: | |
| name: playwright-report | |
| path: playwright-report/ | |
| retention-days: 30 |