diff --git a/.github/actions/build-rspack/action.yaml b/.github/actions/build-rspack/action.yaml index 551faa0d..b564ec12 100644 --- a/.github/actions/build-rspack/action.yaml +++ b/.github/actions/build-rspack/action.yaml @@ -26,15 +26,6 @@ outputs: runs: using: composite steps: - - shell: bash - run: | - npm install -g corepack@0.24.1 - echo "Corepack version: $(corepack --version)" - corepack enable - - shell: bash - run: pnpm --version - - shell: bash - run: pnpm install --prefer-frozen-lockfile --prefer-offline - name: Build Rspack JS shell: bash run: >- diff --git a/bin/cli.js b/bin/cli.js index e5b16cd1..849be5b2 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -111,8 +111,24 @@ if (!command || command === "build") { if (!command || command === "bench") { if (isGitHubActions) { - await $`lscpu -e=CPU,MHZ`; - await $`echo "CPU Usage: "$[100-$(vmstat 1 2|tail -1|awk '{print $15}')]"%"`; + await $`echo "===== System Information ====="`; + await $`uname -a`; + await $`cat /etc/os-release`; + await $`uname -r`; + await $`uptime`; + + await $`echo "===== Resource Usage ====="`; + await $`top -b -n1 | head -n10`; + await $`vmstat`; + await $`df -h`; + await $`free -h`; + + await $`echo "===== Hardware Information ====="`; + await $`lscpu`; + await $`lsblk`; + + await $`echo "===== Environment Variables ====="`; + await $`printenv`; } const shardPair = shard.split("/").map(t => parseInt(t, 10)); diff --git a/bin/upload.js b/bin/upload.js index 15406dc9..077bce26 100644 --- a/bin/upload.js +++ b/bin/upload.js @@ -2,7 +2,8 @@ import { readFile, writeFile, readdir, mkdir, copyFile } from "fs/promises"; import { existsSync } from "fs"; import { resolve, join } from "path"; import { fileURLToPath } from "url"; -import { runCommand, dirExist, formatDate } from "../lib/utils.js"; +import { $, cd } from "zx"; +import { dirExist, formatDate } from "../lib/utils.js"; const [, , token] = process.argv; const GITHUB_ACTOR = process.env.GITHUB_ACTOR; @@ -16,12 +17,7 @@ const rspackDir = process.env.RSPACK_DIR || resolve(rootDir, ".rspack"); const dateDir = resolve(dataDir, date); async function getCommitSHA() { - let commitSHA; - await runCommand("git", ["rev-parse", "HEAD"], { - onData(stdout) { - commitSHA = stdout.toString().trim(); - } - }); + const commitSHA = (await $`git rev-parse HEAD`).toString().trim(); console.log("Current Commit SHA", commitSHA); return commitSHA; } @@ -40,22 +36,13 @@ async function appendRspackBuildInfo() { (async () => { if (!(await dirExist(dataDir))) { - await runCommand("git", [ - "clone", - "--branch", - "data", - "--single-branch", - "--depth", - "1", - repoUrl, - ".data" - ]); + await $`git clone --branch data --single-branch --depth 1 ${repoUrl} .data`; } - process.chdir(dataDir); - await runCommand("git", ["remote", "set-url", "origin", repoUrl]); - await runCommand("git", ["reset", "--hard", "origin/data"]); - await runCommand("git", ["pull", "--rebase"]); + cd(dataDir); + await $`git remote set-url origin ${repoUrl}`; + await $`git reset --hard origin/data`; + await $`git pull --rebase`; console.log("== copy output files =="); const indexFile = resolve(dataDir, "index.txt"); @@ -77,23 +64,18 @@ async function appendRspackBuildInfo() { await writeFile(indexFile, Array.from(files, f => `${f}\n`).join("") + "\n"); console.log("== update build-info.json =="); - process.chdir(rspackDir); + cd(rspackDir); await appendRspackBuildInfo(); - process.chdir(dataDir); + cd(dataDir); console.log("== commit =="); - await runCommand("git", [ - "add", - `${date}/*.json`, - "index.txt", - "build-info.json" - ]); + await $`git add ${date}/*.json index.txt build-info.json`; try { - await runCommand("git", ["commit", "-m", `"add ${date} results"`]); + await $`git commit -m "add ${date} results"`; } catch {} console.log("== push =="); - await runCommand("git", ["push"]); + await $`git push`; })().catch(err => { process.exitCode = 1; console.error(err.stack); diff --git a/lib/scenarios/index.js b/lib/scenarios/index.js index e95b8809..97d937b9 100644 --- a/lib/scenarios/index.js +++ b/lib/scenarios/index.js @@ -2,7 +2,8 @@ import path from "path"; import { readFile, unlink, writeFile } from "fs/promises"; import { fileURLToPath } from "url"; import actionsCore from "@actions/core"; -import { isGitHubActions, runCommand } from "../utils.js"; +import { $, cd } from "zx"; +import { isGitHubActions } from "../utils.js"; import { getDirSizes, calcStatistics, @@ -41,20 +42,21 @@ async function runRspack(ctx) { data[name] = (data[name] || 0) + +valueStr; } }; - let remainingLine = ""; - await runCommand( + const p = $.spawn( path.join(rootDir, "node_modules/@rspack/cli/bin/rspack"), ctx.rspackArgs, { - verbose: false, - onData: function (chunk) { - const lines = (remainingLine + chunk).split("\n"); - remainingLine = lines.pop(); - lines.forEach(processLine); - } + shell: true, + stdio: ["ignore", "pipe", "ignore"] } ); - + let remainingLine = ""; + p.stdout.on("data", chunk => { + const lines = (remainingLine + chunk).split("\n"); + remainingLine = lines.pop(); + lines.forEach(processLine); + }); + const exitCode = await new Promise(resolve => p.once("exit", resolve)); data.exec = Date.now() - start; await promise; if (dataSetCounter > 1) { @@ -62,6 +64,7 @@ async function runRspack(ctx) { data[key] /= dataSetCounter; } } + if (exitCode !== 0) throw new Error(`Build failed with ${exitCode}`); data["dist size"] = await getDirSizes("dist"); return data; } @@ -70,7 +73,7 @@ export function getScenario(caseName) { return { async setup() { const caseDir = path.resolve(rootDir, "cases", caseName); - process.chdir(caseDir); + cd(caseDir); const configFilePath = path.resolve(caseDir, "rspack.config.js"); const config = await readFile(configFilePath); const hmrConfig = await getHmrConfig(path.resolve(caseDir, "hmr.js")); @@ -105,25 +108,19 @@ module.exports.plugins.push(new (require("../../lib/scenarios/build-plugin.cjs") const rspackDir = process.env.RSPACK_DIR || path.resolve(rootDir, ".rspack"); console.log("Create Rspack package link"); - await runCommand("mkdir", [ - "-p", - path.resolve(rootDir, "node_modules/@rspack") - ]); - await runCommand("ln", [ - "-nsf", - path.resolve(rspackDir, "packages/rspack"), - path.resolve(rootDir, "node_modules/@rspack/core") - ]); - await runCommand("ln", [ - "-nsf", - path.resolve(rspackDir, "packages/rspack-cli"), - path.resolve(rootDir, "node_modules/@rspack/cli") - ]); - await runCommand("ln", [ - "-nsf", - path.resolve(rspackDir, "packages/rspack-plugin-react-refresh"), - path.resolve(rootDir, "node_modules/@rspack/plugin-react-refresh") - ]); + await $`mkdir -p ${path.resolve(rootDir, "node_modules/@rspack")}`; + await $`ln -nsf ${path.resolve( + rspackDir, + "packages/rspack" + )} ${path.resolve(rootDir, "node_modules/@rspack/core")}`; + await $`ln -nsf ${path.resolve( + rspackDir, + "packages/rspack-cli" + )} ${path.resolve(rootDir, "node_modules/@rspack/cli")}`; + await $`ln -nsf ${path.resolve( + rspackDir, + "packages/rspack-plugin-react-refresh" + )} ${path.resolve(rootDir, "node_modules/@rspack/plugin-react-refresh")}`; }, async warmup(ctx) { console.log("Run Rspack with args:", ctx.rspackArgs); @@ -155,7 +152,7 @@ module.exports.plugins.push(new (require("../../lib/scenarios/build-plugin.cjs") return writeFile(path, content); }) ); - process.chdir(rootDir); + cd(rootDir); } }; } diff --git a/lib/utils.js b/lib/utils.js index dec4d930..9d2624ce 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,4 +1,3 @@ -import { spawn } from "child_process"; import { stat } from "fs/promises"; export async function useAddons(addons, stage, ...args) { @@ -7,32 +6,6 @@ export async function useAddons(addons, stage, ...args) { } } -export async function runCommand( - command, - args, - { verbose = true, env, onData } = {} -) { - const hasOnData = typeof onData === "function"; - const stdio = verbose ? "inherit" : "ignore"; - const p = spawn(command, args, { - shell: true, - stdio: [stdio, hasOnData ? "pipe" : stdio, "inherit"], - env: env - ? { - ...process.env, - ...env - } - : undefined - }); - if (hasOnData) { - p.stdout.on("data", onData); - } - - const exitCode = await new Promise(resolve => p.once("exit", resolve)); - if (exitCode !== 0) - throw new Error(`${command} ${args.join(" ")} failed with ${exitCode}`); -} - export function getType(metric) { if (metric.endsWith(" memory")) return "memory"; if (metric.endsWith(" size")) return "size";