From f9a83771b1a2740f66f18184cd5ddd2f0c0184ae Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 4 Jun 2026 11:08:57 +0800 Subject: [PATCH 1/7] chore: simplify puppeteer install --- .github/workflows/test.yml | 12 +---- package.json | 3 +- scripts/install-puppeteer-browser.mjs | 78 --------------------------- 3 files changed, 2 insertions(+), 91 deletions(-) delete mode 100644 scripts/install-puppeteer-browser.mjs diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb2fcb3..278a584 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,5 @@ name: Test -env: - PUPPETEER_SKIP_DOWNLOAD: true - # Controls when the action will run. on: # Triggers the workflow on pull request events but only for the main branch @@ -23,17 +20,10 @@ jobs: strategy: matrix: - include: - - os: ubuntu-latest - puppeteer-executable-path: /usr/bin/google-chrome - - os: windows-latest - puppeteer-executable-path: 'C:\Program Files\Google\Chrome\Application\chrome.exe' + os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} - env: - PUPPETEER_EXECUTABLE_PATH: ${{ matrix.puppeteer-executable-path }} - concurrency: group: test-${{ matrix.os }}-${{ github.ref }} diff --git a/package.json b/package.json index 2355002..ed16b8b 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,7 @@ "lint": "rslint", "lint:write": "rslint --fix", "prettier:ci": "prettier --check .", - "test": "pnpm run test:install && pnpm run test:type && rstest", - "test:install": "node scripts/install-puppeteer-browser.mjs", + "test": "pnpm run test:type && rstest", "test:type": "pnpm run build && pnpm --dir tests run type-check" }, "simple-git-hooks": { diff --git a/scripts/install-puppeteer-browser.mjs b/scripts/install-puppeteer-browser.mjs deleted file mode 100644 index 7985b8c..0000000 --- a/scripts/install-puppeteer-browser.mjs +++ /dev/null @@ -1,78 +0,0 @@ -import { spawnSync } from 'node:child_process'; -import { existsSync } from 'node:fs'; -import { rm } from 'node:fs/promises'; -import { createRequire } from 'node:module'; -import path from 'node:path'; - -import * as puppeteer from 'puppeteer'; - -const require = createRequire(import.meta.url); -const cliPath = require.resolve('puppeteer/lib/cjs/puppeteer/node/cli.js'); -const chromeVersion = puppeteer.PUPPETEER_REVISIONS.chrome; - -const configuredExecutablePath = process.env.PUPPETEER_EXECUTABLE_PATH; - -if (configuredExecutablePath) { - if (!existsSync(configuredExecutablePath)) { - console.error( - `Configured Puppeteer Chrome executable was not found: ${configuredExecutablePath}`, - ); - process.exit(1); - } - - console.log(`Puppeteer Chrome executable: ${configuredExecutablePath}`); - process.exit(0); -} - -const getChromeBuildDirectory = (executablePath) => { - const parts = executablePath.split(path.sep); - const chromeIndex = parts.findIndex( - (part, index) => - part === 'chrome' && parts[index + 1]?.endsWith(`-${chromeVersion}`), - ); - - if (chromeIndex === -1 || chromeIndex + 1 >= parts.length) { - return null; - } - - return parts.slice(0, chromeIndex + 2).join(path.sep); -}; - -const ensureCleanChromeCache = async () => { - const executablePath = puppeteer.executablePath(); - - if (existsSync(executablePath)) { - return executablePath; - } - - const buildDirectory = getChromeBuildDirectory(executablePath); - - if (buildDirectory) { - await rm(buildDirectory, { force: true, recursive: true }); - } - - return executablePath; -}; - -await ensureCleanChromeCache(); - -const result = spawnSync( - process.execPath, - [cliPath, 'browsers', 'install', 'chrome'], - { - stdio: 'inherit', - }, -); - -if (result.status !== 0) { - process.exit(result.status ?? 1); -} - -const executablePath = puppeteer.executablePath(); - -if (!existsSync(executablePath)) { - console.error(`Puppeteer Chrome executable was not found: ${executablePath}`); - process.exit(1); -} - -console.log(`Puppeteer Chrome executable: ${executablePath}`); From 63568a0741f6e7d7513e68e9ab5b0415427474e8 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 4 Jun 2026 11:35:47 +0800 Subject: [PATCH 2/7] ci: skip puppeteer download in check job --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 278a584..2346bea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,6 +54,8 @@ jobs: runs-on: ubuntu-latest permissions: contents: read + env: + PUPPETEER_SKIP_DOWNLOAD: true steps: - name: Checkout From 2bfbba1e992e3f00950e872e20e90cce113544f6 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 8 Jun 2026 16:06:36 +0800 Subject: [PATCH 3/7] ci: install puppeteer chrome explicitly --- .github/workflows/test.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2346bea..59f270e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,8 +44,13 @@ jobs: package-manager-cache: false - name: Install Dependencies + env: + PUPPETEER_SKIP_DOWNLOAD: true run: pnpm install + - name: Install Chrome + run: pnpm exec puppeteer browsers install chrome + - name: Run Test run: pnpm run test @@ -54,8 +59,6 @@ jobs: runs-on: ubuntu-latest permissions: contents: read - env: - PUPPETEER_SKIP_DOWNLOAD: true steps: - name: Checkout @@ -73,6 +76,8 @@ jobs: package-manager-cache: false - name: Install Dependencies + env: + PUPPETEER_SKIP_DOWNLOAD: true run: pnpm install - name: Lint From f11e003a60f34fc6252edfc4601ff0125e6cd75e Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 8 Jun 2026 16:56:08 +0800 Subject: [PATCH 4/7] ci: stabilize puppeteer browser tests --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59f270e..ce75c74 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,8 +51,11 @@ jobs: - name: Install Chrome run: pnpm exec puppeteer browsers install chrome + - name: Verify Chrome + run: node -e "const fs = require('node:fs'); const puppeteer = require('puppeteer'); const executablePath = puppeteer.executablePath(); fs.accessSync(executablePath); console.log(executablePath);" + - name: Run Test - run: pnpm run test + run: pnpm run test:type && pnpm exec rstest --pool.maxWorkers=2 check: name: Check From f8671739590d968fa16b40478804752506a9d289 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 8 Jun 2026 16:58:28 +0800 Subject: [PATCH 5/7] ci: cancel superseded test runs --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce75c74..14f9bf8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,7 @@ jobs: concurrency: group: test-${{ matrix.os }}-${{ github.ref }} + cancel-in-progress: true # Steps represent a sequence of tasks that will be executed as part of the job steps: From 5d915882cdb285eb99b810aacb117155e2653ad9 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 8 Jun 2026 17:05:04 +0800 Subject: [PATCH 6/7] ci: use puppeteer postinstall for chrome --- .github/workflows/test.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14f9bf8..9875ceb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,15 +46,9 @@ jobs: - name: Install Dependencies env: - PUPPETEER_SKIP_DOWNLOAD: true + PUPPETEER_CHROME_HEADLESS_SHELL_SKIP_DOWNLOAD: true run: pnpm install - - name: Install Chrome - run: pnpm exec puppeteer browsers install chrome - - - name: Verify Chrome - run: node -e "const fs = require('node:fs'); const puppeteer = require('puppeteer'); const executablePath = puppeteer.executablePath(); fs.accessSync(executablePath); console.log(executablePath);" - - name: Run Test run: pnpm run test:type && pnpm exec rstest --pool.maxWorkers=2 From e40f838507b6abed59a243c3fb8563f550df58aa Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 8 Jun 2026 17:20:01 +0800 Subject: [PATCH 7/7] ci: use runner chrome in tests --- .github/workflows/test.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9875ceb..dc72415 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,8 @@ name: Test +env: + PUPPETEER_SKIP_DOWNLOAD: true + # Controls when the action will run. on: # Triggers the workflow on pull request events but only for the main branch @@ -20,10 +23,17 @@ jobs: strategy: matrix: - os: [ubuntu-latest, windows-latest] + include: + - os: ubuntu-latest + puppeteer-executable-path: /usr/bin/google-chrome + - os: windows-latest + puppeteer-executable-path: 'C:\Program Files\Google\Chrome\Application\chrome.exe' runs-on: ${{ matrix.os }} + env: + PUPPETEER_EXECUTABLE_PATH: ${{ matrix.puppeteer-executable-path }} + concurrency: group: test-${{ matrix.os }}-${{ github.ref }} cancel-in-progress: true @@ -45,12 +55,10 @@ jobs: package-manager-cache: false - name: Install Dependencies - env: - PUPPETEER_CHROME_HEADLESS_SHELL_SKIP_DOWNLOAD: true run: pnpm install - name: Run Test - run: pnpm run test:type && pnpm exec rstest --pool.maxWorkers=2 + run: pnpm run test check: name: Check @@ -74,8 +82,6 @@ jobs: package-manager-cache: false - name: Install Dependencies - env: - PUPPETEER_SKIP_DOWNLOAD: true run: pnpm install - name: Lint