Skip to content

Commit 0ebd968

Browse files
committed
wip: matrix
1 parent f7122dd commit 0ebd968

File tree

1 file changed

+83
-38
lines changed

1 file changed

+83
-38
lines changed

.github/workflows/playwright.yml

Lines changed: 83 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ permissions:
88
contents: read
99

1010
jobs:
11-
test:
12-
timeout-minutes: 60
11+
prepare:
12+
timeout-minutes: 10
1313
runs-on: ubuntu-latest
14-
14+
outputs:
15+
matrix: ${{ steps.matrix.outputs.matrix }}
1516
steps:
1617
- uses: actions/checkout@v5
1718
with:
@@ -23,6 +24,7 @@ jobs:
2324
node-version-file: '.node-version'
2425

2526
- name: Prepare
27+
id: prepare
2628
run: |
2729
corepack enable
2830
@@ -33,54 +35,97 @@ jobs:
3335
3436
yarn dist:mini
3537
36-
- name: Spawn Companion
38+
- name: Upload companion build
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: companion-dist
42+
path: dist
43+
44+
- name: Build matrix JSON from browserstack.yml
45+
id: matrix
3746
run: |
38-
# Start Companion in the background
39-
node companion/dist/main.js --machine-id ci_browserstack --log-level debug &
40-
export COMPANION_PID=$!
47+
# Create a JSON matrix that GH Actions can consume, reading platforms from playwright/browserstack.yml
48+
python - <<'PY'
49+
import yaml, json, sys
50+
path = 'playwright/browserstack.yml'
51+
with open(path) as f:
52+
data = yaml.safe_load(f)
53+
platforms = data.get('platforms', [])
54+
if not platforms:
55+
print('::error::No platforms found in browserstack.yml')
56+
sys.exit(1)
57+
# encode each platform as a compact JSON object to be used as matrix.include
58+
matrix = { 'include': [] }
59+
for p in platforms:
60+
matrix['include'].append({'platform': json.dumps(p)})
61+
print('::set-output name=matrix::' + json.dumps(matrix))
62+
PY
4163
42-
yarn wait-on http://localhost:8000 --timeout 30000 --delay 5000
64+
test:
65+
needs: prepare
66+
timeout-minutes: 60
67+
runs-on: ubuntu-latest
68+
strategy:
69+
fail-fast: false
70+
matrix: ${{fromJson(needs.prepare.outputs.matrix)}}
71+
max-parallel: 3
72+
steps:
73+
- uses: actions/checkout@v5
74+
with:
75+
fetch-depth: 0
76+
persist-credentials: false
77+
- name: Use Node.js
78+
uses: actions/setup-node@v4
79+
with:
80+
node-version-file: '.node-version'
81+
82+
- name: Prepare
83+
id: prepare
84+
run: |
85+
corepack enable
86+
87+
# try and avoid timeout errors
88+
yarn config set httpTimeout 100000
89+
90+
yarn --immutable
91+
92+
- name: Download companion build
93+
uses: actions/download-artifact@v4
94+
with:
95+
name: companion-dist
4396

4497
- name: 'BrowserStack Env Setup'
4598
uses: 'browserstack/github-actions/[email protected]'
4699
with:
47100
username: ${{ secrets.BROWSERSTACK_USERNAME }}
48101
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
49-
# build-name: BUILD_INFO
50-
# project-name: REPO_NAME
51102

52-
- name: Run Playwright tests
103+
- name: Prepare single-platform browserstack.yml
53104
run: |
54-
cd playwright
55-
yarn test:ci
56-
57-
SRC=browserstack.yml
58-
TMP=.tmp-browserstack.yml
105+
mkdir -p playwright
106+
python - <<'PY'
107+
import json, yaml, sys
108+
entry = json.loads('''${{ matrix.platform }}''')
109+
cfg = yaml.safe_load(open('playwright/browserstack.yml'))
110+
cfg['platforms'] = [entry]
111+
with open('playwright/browserstack.yml', 'w') as f:
112+
yaml.safe_dump(cfg, f)
113+
print('Wrote single-platform playwright/browserstack.yml')
114+
PY
59115
60-
count=$(yq eval '.platforms | length' "$SRC")
61-
if [ "$count" -eq 0 ]; then
62-
echo "No platforms found in $SRC"
63-
exit 1
64-
fi
65-
66-
mv $SRC $TMP
67-
68-
for i in $(seq 0 $((count - 1))); do
69-
echo "=== Running platform #$((i+1))/$count ==="
70-
# produce a temp config that contains only the i-th platform and a shared build identifier
71-
yq eval \
72-
'.platforms = [ .platforms['"$i"'] ] |
73-
"$TMP" > "$SRC"
74-
75-
# Run the BrowserStack runner for that single-platform config.
76-
yarn test:ci
116+
- name: Spawn Companion
117+
run: |
118+
# Start Companion from the downloaded build
119+
node companion/dist/main.js --machine-id ci_browserstack --log-level debug &
120+
export COMPANION_PID=$!
77121
78-
# If you control test worker concurrency via Playwright instead:
79-
# cd playwright
80-
# yarn test:ci --workers=1
122+
yarn wait-on http://localhost:8000 --timeout 30000 --delay 5000
81123
82-
echo "=== Finished platform #$((i+1)) ==="
83-
done
124+
- name: Run Playwright tests
125+
run: |
126+
cd playwright
127+
# Ensure single worker to avoid parallelism inside the runner
128+
yarn test:ci --workers=1
84129
85130
- uses: actions/upload-artifact@v4
86131
if: ${{ !cancelled() }}

0 commit comments

Comments
 (0)