Skip to content

Commit

Permalink
create measure date workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Feb 16, 2021
1 parent 8ebbaf5 commit ab91d62
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/compare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
restore-keys: |
yarn-${{ matrix.case }}-
yarn-
- run: yarn
- uses: nick-invision/[email protected]
with:
max_attempts: 3
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/measure-date.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Measure date

on:
workflow_dispatch:
inputs:
date:
description: "Date to measure (yyyy-mm-dd)"
default: "2021-01-01"
required: true
jobs:
bench:
strategy:
fail-fast: false
matrix:
case:
- common-libs
- esbuild-three
scenario:
- development-build
- development-build+persistent-cache
- development-build+pnp
- development-rebuild
- production-build
- production-build+source-map
- production-build+no-minimize
- production-build+no-minimize+no-concatenation
- production-build+persistent-cache
- production-build+source-map+persistent-cache
runs-on: ubuntu-latest
steps:
- run: echo ${{ github.event.inputs.date }}
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
- id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ matrix.case }}-${{ github.event.inputs.date }}
restore-keys: |
yarn-${{ matrix.case }}-
yarn-
- run: yarn
- run: node bin/measure-mean.js ${{ matrix.case }} ${{ matrix.scenario }} ${{ github.event.inputs.date }}
- uses: actions/upload-artifact@v2
with:
name: measure-results
path: output
upload:
needs: [bench]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- run: echo ${{ github.event.inputs.date }}
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
- id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-upload-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-upload-
yarn-
- run: yarn
- uses: actions/download-artifact@v2
with:
name: measure-results
path: output
- run: node bin/upload.js ${{ github.event.inputs.date }}
2 changes: 2 additions & 0 deletions .github/workflows/verify-stability.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
restore-keys: |
yarn-${{ matrix.case }}-
yarn-
- run: yarn
- uses: nick-invision/[email protected]
with:
max_attempts: 3
Expand Down Expand Up @@ -76,6 +77,7 @@ jobs:
restore-keys: |
yarn-${{ matrix.case }}-
yarn-
- run: yarn
- uses: nick-invision/[email protected]
with:
max_attempts: 3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cases/**/yarn.lock
.yarnrc.yml
.pnp.js
/output
.gh-pages
84 changes: 84 additions & 0 deletions bin/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { readFile, writeFile, stat } from "fs/promises";
import { resolve, relative } from "path";
import { fileURLToPath } from "url";
import { runCommand } from "../lib/utils.js";
import ncpCallback from "ncp";
import { promisify } from "util";

const ncp = promisify(ncpCallback);

const [, , name] = process.argv;

if (!name) throw new Error("name argument missing");

const rootDir = resolve(fileURLToPath(import.meta.url), "../..");

const run = (command, args) => runCommand(command, args, true);

const dirExist = async (p) => {
try {
if ((await stat(p)).isDirectory()) return true;
} catch {
return false;
}
};

(async () => {
const targetDir = resolve(rootDir, ".gh-pages");
if (!(await dirExist(targetDir))) {
await run("git", [
"clone",
"--branch",
"gh-pages",
"--single-branch",
"--depth",
"1",
"https://github.com/webpack/benchmark",
".gh-pages",
]);
}
process.chdir(targetDir);
for (let i = 0; i < 2; i++) {
await run("git", ["reset", "--hard"]);
await run("git", ["pull"]);

console.log("== copy output files ==");
const indexFile = resolve(targetDir, "results", "index.txt");
const files = new Set((await readFile(indexFile, "utf-8")).split("\n"));
files.delete("");
await ncp(resolve(rootDir, "output"), resolve(targetDir, "results", name), {
filter: (filename) => {
if (filename.endsWith(".json")) {
files.add(
`${name}/${relative(resolve(rootDir, "output"), filename).replace(
/\\/g,
"/"
)}`
);
}
return true;
},
});

console.log("== update index.txt ==");
await writeFile(
indexFile,
Array.from(files, (f) => `${f}\n`).join("") + "\n"
);

console.log("== commit ==");
await run("git", ["add", `results/${name}/*.json`, "results/index.txt"]);
try {
await run("git", ["commit", "-m", `"add ${name} results"`]);
} catch {
break;
}

console.log("== push ==");
await run("git", ["push"]);
break;
}
})().catch((err) => {
process.exitCode = 1;
console.error(err.stack);
});
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const alterFile = async (filePath, fn, options = {}) => {
export const revertFile = (filePath) =>
alterFile(filePath, null, { past: true });

const runCommand = async (command, args, verbose) => {
export const runCommand = async (command, args, verbose) => {
const p = spawn(command, args, {
shell: true,
stdio: verbose ? "inherit" : "ignore",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"license": "MIT",
"private": true,
"dependencies": {
"ncp": "^2.0.0",
"ssl-root-cas": "^1.3.1"
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
resolved "https://registry.yarnpkg.com/@coolaj86/urequest/-/urequest-1.3.7.tgz#66a1d66378dd6534e9c8e68948bf09acf32bab77"
integrity sha512-PPrVYra9aWvZjSCKl/x1pJ9ZpXda1652oJrPBYy5rQumJJMkmTBN3ux+sK2xAUwVvv2wnewDlaQaHLxLwSHnIA==

ncp@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ncp/-/ncp-2.0.0.tgz#195a21d6c46e361d2fb1281ba38b91e9df7bdbb3"
integrity sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=

ssl-root-cas@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/ssl-root-cas/-/ssl-root-cas-1.3.1.tgz#6b0566f7de4f0e6be99fbd93dbfbe5c7ab33b949"
Expand Down

0 comments on commit ab91d62

Please sign in to comment.