Skip to content

Commit 69ceed8

Browse files
committed
chore: add playwright setup for github actions
1 parent 0acd4f3 commit 69ceed8

File tree

6 files changed

+64
-10
lines changed

6 files changed

+64
-10
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,33 @@ jobs:
141141
- name: Build codes
142142
run: npm run build
143143

144+
# https://github.com/vitejs/vite/blob/main/.github/workflows/ci.yml#L91
145+
# Install playwright's binary under custom directory to cache
146+
- name: (non-windows) Set Playwright path and Get playwright version
147+
if: runner.os != 'Windows'
148+
run: |
149+
echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/playwright-bin" >> $GITHUB_ENV
150+
PLAYWRIGHT_VERSION="$(bun run ./scripts/playwright-version.ts)"
151+
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
152+
- name: (windows) Set Playwright path and Get playwright version
153+
if: runner.os == 'Windows'
154+
run: |
155+
echo "PLAYWRIGHT_BROWSERS_PATH=$HOME\.cache\playwright-bin" >> $env:GITHUB_ENV
156+
PLAYWRIGHT_VERSION="$(bun run ./scripts/playwright-version.ts)"
157+
echo "PLAYWRIGHT_VERSION=$env:PLAYWRIGHT_VERSION" >> $env:GITHUB_ENV
158+
159+
- name: Cache Playwright's binary
160+
uses: actions/cache@v3
161+
with:
162+
key: ${{ runner.os }}-playwright-bin-v1-${{ env.PLAYWRIGHT_VERSION }}
163+
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
164+
restore-keys: |
165+
${{ runner.os }}-playwright-bin-v1-
166+
167+
- name: Install Playwright
168+
# does not need to explicitly set chromium after https://github.com/microsoft/playwright/issues/14862 is solved
169+
run: bun x playwright install chromium
170+
144171
- name: Run test
145172
run: ./scripts/e2e.sh
146173

bun.lockb

17 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"npm-run-all": "^4.1.5",
115115
"miniflare": "^3.20231016.0",
116116
"supertest": "^6.3.3",
117+
"playwright": "^1.38.1",
117118
"pkg-types": "^1.0.2",
118119
"typescript": "^5.2.2",
119120
"unbuild": "^2.0.0",

scripts/playwright-version.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { resolve } from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
import { readPackageJSON } from 'pkg-types'
4+
import { isExists } from './utils.ts'
5+
6+
const __dirname = fileURLToPath(new URL('.', import.meta.url))
7+
8+
async function main() {
9+
const playwrightPath = resolve(__dirname, '../node_modules/playwright')
10+
if (!await isExists(playwrightPath)) {
11+
throw new Error(`not found '${playwrightPath}'`)
12+
}
13+
14+
const playwrightPkg = await readPackageJSON(playwrightPath)
15+
if (!playwrightPkg.version) {
16+
throw new Error(`not found 'version' in 'playwright'`)
17+
}
18+
console.log(playwrightPkg.version)
19+
}
20+
21+
main().catch((err) => {
22+
console.error(err)
23+
process.exit(1)
24+
})

scripts/replaceDeps.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import { constants as FS_CONSTANTS, promises as fs } from 'node:fs'
1+
import { promises as fs } from 'node:fs'
22
import { resolve } from 'node:path'
33
import { fileURLToPath } from 'node:url'
44
import { readPackageJSON, writePackageJSON } from 'pkg-types'
5+
import { isExists } from './utils.ts'
56

67
const __dirname = fileURLToPath(new URL('.', import.meta.url))
78

8-
export async function isExists(path: string) {
9-
try {
10-
await fs.access(path, FS_CONSTANTS.F_OK)
11-
return true
12-
} catch {
13-
return false
14-
}
15-
}
16-
179
type Platform = 'browser' | 'node' | 'deno' | 'bun'
1810

1911
async function replaceNodePlatform(platform: 'node' | 'bun', playgroundPath: string) {

scripts/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { constants as FS_CONSTANTS, promises as fs } from 'node:fs'
2+
3+
export async function isExists(path: string) {
4+
try {
5+
await fs.access(path, FS_CONSTANTS.F_OK)
6+
return true
7+
} catch {
8+
return false
9+
}
10+
}

0 commit comments

Comments
 (0)