Skip to content

Commit

Permalink
chore: merge origin main
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed May 17, 2024
2 parents ecd4a29 + 4fdec78 commit 523892c
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 24 deletions.
15 changes: 13 additions & 2 deletions .github/actions/env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
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
3 changes: 1 addition & 2 deletions .github/workflows/bench_rspack_commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/bench_rspack_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/scheduled_bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<project_root>/.rspack`. You can set target branch with the parameter. eg.

``` bash
node bin/build-rspack.js # use the main branch to build
Expand All @@ -28,7 +28,7 @@ RSPACK_DIR=<your-rspack-path> node bin/bench.js 10000_development-mode_hmr # set

* `node bin/compare-bench.js <baseDate> <currentDate>`

Compare and print the difference between `<baseDate>` and `<currentDate>`. 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 `<baseDate>` and `<currentDate>`. 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
Expand Down
15 changes: 11 additions & 4 deletions bin/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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));
}
Expand Down Expand Up @@ -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 {}
Expand Down
1 change: 1 addition & 0 deletions cases/arco-pro/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ module.exports = {
loader: "builtin:swc-loader",
exclude: [/[\\/]node_modules[\\/]/],
options: {
sourceMaps: true,
jsc: {
parser: {
syntax: "typescript",
Expand Down
6 changes: 3 additions & 3 deletions lib/rspack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down
17 changes: 12 additions & 5 deletions lib/services.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
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.
*
* @returns {Promise<Object.<string, {commitSHA: string}>>}
*/
export async function fetchBuildInfo() {
return fetch(`${fetchPrefix}/build-info.json`).then(res => res.json())
return fetch(`${fetchPrefix}/build-info.json`).then(res => res.json());
}

/**
Expand Down Expand Up @@ -43,6 +49,7 @@ export async function fetchIndex() {
* @param {string} file - The specific file to fetch data from.
* @returns {Promise<{[key: string]: Object.<string, number>}>} 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();
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]"
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 523892c

Please sign in to comment.