diff --git a/.github/actions/env/action.yml b/.github/actions/env/action.yml index fd633f97..9a7237f3 100644 --- a/.github/actions/env/action.yml +++ b/.github/actions/env/action.yml @@ -8,10 +8,21 @@ runs: - name: Setup node uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 20 - name: Activate corepack shell: bash - run: corepack enable + run: | + # corepack > 0.24.1 will use native fetch + # and native fetch not support HTTP_PROXY + # https://github.com/nodejs/undici/issues/1650 + npm install -g corepack@0.24.1 + corepack enable - name: Install dependencies with pnpm shell: bash run: pnpm install + - name: Set Rspack Dir + shell: bash + run: | + if [[ ! -z "$PNPM_CACHE" ]]; then + echo "RSPACK_DIR=$PNPM_CACHE/rspack" >> $GITHUB_ENV + fi diff --git a/.github/workflows/bench_rspack_commit.yml b/.github/workflows/bench_rspack_commit.yml index 2f5169bd..73b63abf 100644 --- a/.github/workflows/bench_rspack_commit.yml +++ b/.github/workflows/bench_rspack_commit.yml @@ -10,8 +10,7 @@ on: jobs: run-bench: - runs-on: [self-hosted, rspack-bench] - timeout-minutes: 30 + runs-on: [self-hosted, benchmark] outputs: diff-result: ${{ steps.print-results.outputs.diff-result }} steps: diff --git a/.github/workflows/bench_rspack_pr.yml b/.github/workflows/bench_rspack_pr.yml index 5977dbf1..073353c6 100644 --- a/.github/workflows/bench_rspack_pr.yml +++ b/.github/workflows/bench_rspack_pr.yml @@ -32,8 +32,7 @@ jobs: return comment.id run-bench: - runs-on: [self-hosted, rspack-bench] - timeout-minutes: 30 + runs-on: [self-hosted, benchmark] needs: create-comment outputs: diff-result: ${{ steps.print-results.outputs.diff-result }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3af80014..4530a1ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: ci: needs: prepare-binding - runs-on: [self-hosted, rspack-bench] + runs-on: [self-hosted, benchmark] timeout-minutes: 30 strategy: matrix: diff --git a/.github/workflows/scheduled_bench.yml b/.github/workflows/scheduled_bench.yml index d5f7121f..9d4b2e64 100644 --- a/.github/workflows/scheduled_bench.yml +++ b/.github/workflows/scheduled_bench.yml @@ -6,8 +6,7 @@ on: workflow_dispatch: jobs: bench: - runs-on: [self-hosted, rspack-bench] - timeout-minutes: 30 + runs-on: [self-hosted, benchmark] steps: - name: Checkout uses: actions/checkout@v2 diff --git a/README.md b/README.md index 7128cfe5..b342a700 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ You can use the scripts in the `bin` directory to prepare and run benchmark. * `node bin/build-rspack.js [remote] [branch]` -Clone and build [rspack](https://github.com/web-infra-dev/rspack) in `.rspack` folder. You can set target branch with the parameter. eg. +Clone and build [rspack](https://github.com/web-infra-dev/rspack) in the folder which defined by the environment variable of `RSPACK_DIR` or `/.rspack`. You can set target branch with the parameter. eg. ``` bash node bin/build-rspack.js # use the main branch to build @@ -28,7 +28,7 @@ RSPACK_DIR= node bin/bench.js 10000_development-mode_hmr # set * `node bin/compare-bench.js ` -Compare and print the difference between `` and ``. The parameter have three types, `current` will use the data from `output` folder. `latest` will use the latest data from `data` branch. A date string like `YYYY-MM-DD` will use the data of that day from `data` branch. eg. +Compare and print the difference between `` and ``. The parameter has three types, `current` will use the data from `output` folder. `latest` will use the latest data from `data` branch. A date string like `YYYY-MM-DD` will use the data of that day from `data` branch. eg. ``` bash node bin/compare-bench.js current latest # use output data as base, and latest data as current diff --git a/bin/upload.js b/bin/upload.js index d1c15d66..15406dc9 100644 --- a/bin/upload.js +++ b/bin/upload.js @@ -12,7 +12,7 @@ const repoUrl = `https://${GITHUB_ACTOR}:${token}@github.com/web-infra-dev/rspac const rootDir = resolve(fileURLToPath(import.meta.url), "../.."); const dataDir = resolve(rootDir, ".data"); const outputDir = resolve(rootDir, "output"); -const rspackDir = resolve(rootDir, ".rspack"); +const rspackDir = process.env.RSPACK_DIR || resolve(rootDir, ".rspack"); const dateDir = resolve(dataDir, date); async function getCommitSHA() { @@ -29,9 +29,11 @@ async function getCommitSHA() { async function appendRspackBuildInfo() { const commitSHA = await getCommitSHA(); const buildInfoFile = join(dataDir, "build-info.json"); - const buildInfo = existsSync(buildInfoFile) ? JSON.parse(await readFile(buildInfoFile, "utf-8")) : {}; + const buildInfo = existsSync(buildInfoFile) + ? JSON.parse(await readFile(buildInfoFile, "utf-8")) + : {}; buildInfo[date] = { - commitSHA, + commitSHA }; await writeFile(buildInfoFile, JSON.stringify(buildInfo, null, 2)); } @@ -80,7 +82,12 @@ async function appendRspackBuildInfo() { process.chdir(dataDir); console.log("== commit =="); - await runCommand("git", ["add", `${date}/*.json`, "index.txt", "build-info.json"]); + await runCommand("git", [ + "add", + `${date}/*.json`, + "index.txt", + "build-info.json" + ]); try { await runCommand("git", ["commit", "-m", `"add ${date} results"`]); } catch {} diff --git a/cases/arco-pro/rspack.config.js b/cases/arco-pro/rspack.config.js index e041760c..23e73a85 100644 --- a/cases/arco-pro/rspack.config.js +++ b/cases/arco-pro/rspack.config.js @@ -160,6 +160,7 @@ module.exports = { loader: "builtin:swc-loader", exclude: [/[\\/]node_modules[\\/]/], options: { + sourceMaps: true, jsc: { parser: { syntax: "typescript", diff --git a/lib/rspack.js b/lib/rspack.js index eb4f10aa..408dc673 100644 --- a/lib/rspack.js +++ b/lib/rspack.js @@ -3,7 +3,7 @@ import { fileURLToPath } from "url"; import { runCommand, dirExist } from "./utils.js"; const rootDir = resolve(fileURLToPath(import.meta.url), "../.."); -const rspackDir = resolve(rootDir, ".rspack"); +const rspackDir = process.env.RSPACK_DIR || resolve(rootDir, ".rspack"); const repoUrl = `https://github.com/web-infra-dev/rspack.git`; async function switchToBranch(remote, branch) { @@ -30,8 +30,8 @@ async function switchToBranch(remote, branch) { export async function buildRspack(remote, branch) { if (!(await dirExist(rspackDir))) { - console.log(`git clone ${repoUrl} .rspack`); - await runCommand("git", ["clone", repoUrl, ".rspack"]); + console.log(`git clone ${repoUrl} ${rspackDir}`); + await runCommand("git", ["clone", repoUrl, rspackDir]); } process.chdir(rspackDir); diff --git a/lib/services.js b/lib/services.js index 2e526f6b..2fcf8c94 100644 --- a/lib/services.js +++ b/lib/services.js @@ -1,6 +1,12 @@ -import * as path from 'path'; +import { ProxyAgent, setGlobalDispatcher } from "undici"; -const fetchPrefix = "https://raw.githubusercontent.com/web-infra-dev/rspack-ecosystem-benchmark/data"; +if (process.env.http_proxy) { + const agent = new ProxyAgent(process.env.http_proxy); + setGlobalDispatcher(agent); +} + +const fetchPrefix = + "https://raw.githubusercontent.com/web-infra-dev/rspack-ecosystem-benchmark/data"; /** * Fetch the build information from a JSON file. @@ -8,7 +14,7 @@ const fetchPrefix = "https://raw.githubusercontent.com/web-infra-dev/rspack-ecos * @returns {Promise>} */ export async function fetchBuildInfo() { - return fetch(`${fetchPrefix}/build-info.json`).then(res => res.json()) + return fetch(`${fetchPrefix}/build-info.json`).then(res => res.json()); } /** @@ -43,6 +49,7 @@ export async function fetchIndex() { * @param {string} file - The specific file to fetch data from. * @returns {Promise<{[key: string]: Object.}>} A promise that resolves to the benchmark result data. */ -export function fetchBenchmarkResult(date, file) { - return fetch(`${fetchPrefix}/${date}/${file}`).then(res => res.json()); +export async function fetchBenchmarkResult(date, file) { + const res = await fetch(`${fetchPrefix}/${date}/${file}`); + return await res.json(); } diff --git a/package.json b/package.json index 0ea2b007..61173ad5 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "@icon-park/react": "^1.4.2", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-refresh": "^0.14.0" + "react-refresh": "^0.14.0", + "undici": "^6.11.0" }, "packageManager": "pnpm@8.14.3" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f3e745bd..36ebd4d4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: react-refresh: specifier: ^0.14.0 version: 0.14.0 + undici: + specifier: ^6.11.0 + version: 6.11.0 cases/10000: {} @@ -6114,6 +6117,11 @@ packages: which-boxed-primitive: 1.0.2 dev: false + /undici@6.11.0: + resolution: {integrity: sha512-y4AOKcD36FXz+MY19yw8Emtbsdp8wBWTLln508+EJwqWezUheU5PSRbvIb+pQld7ZoOY8ruNwqSejSVGZUS/aA==} + engines: {node: '>=18.0'} + dev: false + /unicode-canonical-property-names-ecmascript@2.0.0: resolution: {integrity: sha512-yY5PpDlfVIU5+y/BSCxAJRBIS1Zc2dDG3Ujq+sR0U+JjUevW2JhocOF+soROYDSaAezOzOKuyyixhD6mBknSmQ==} engines: {node: '>=4'}