@dapplion/benchmark
Version:
Ensures that new code does not introduce performance regressions with CI. Tracks:
86 lines (85 loc) • 4.12 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = run;
const github = __importStar(require("@actions/github"));
const index_js_1 = require("./history/index.js");
const shouldPersist_js_1 = require("./history/shouldPersist.js");
const schema_js_1 = require("./history/schema.js");
const index_js_2 = require("./compare/index.js");
const index_js_3 = require("./utils/index.js");
const mochaRunner_js_1 = require("./mochaPlugin/mochaRunner.js");
const compute_js_1 = require("./compare/compute.js");
const comment_js_1 = require("./github/comment.js");
const context_js_1 = require("./github/context.js");
/* eslint-disable no-console */
async function run(opts) {
// Sanitize opts
if (isNaN(opts.threshold))
throw Error("opts.threshold is not a number");
// Retrieve history
const historyProvider = (0, index_js_1.getHistoryProvider)(opts);
console.log(`Connected to historyProvider: ${historyProvider.providerInfo()}`);
// Select prev benchmark to compare against
const compareWith = await (0, index_js_2.resolveCompareWith)(opts);
const prevBench = await (0, index_js_2.resolvePrevBenchmark)(compareWith, historyProvider);
if (prevBench) {
console.log(`Found previous benchmark for ${(0, index_js_2.renderCompareWith)(compareWith)}, at commit ${prevBench.commitSha}`);
(0, schema_js_1.validateBenchmark)(prevBench);
}
else {
console.log(`No previous bencharmk found for ${(0, index_js_2.renderCompareWith)(compareWith)}`);
}
// TODO: Forward all options to mocha
// Run benchmarks with mocha programatically
const results = await (0, mochaRunner_js_1.runMochaBenchmark)(opts, prevBench);
if (results.length === 0) {
throw Error("No benchmark result was produced");
}
const currentCommit = await (0, index_js_3.getCurrentCommitInfo)();
const currBench = {
commitSha: currentCommit.commitSha,
results,
};
// Persist new benchmark data
const currentBranch = await (0, index_js_3.getCurrentBranch)();
const shouldPersist = await (0, shouldPersist_js_1.resolveShouldPersist)(opts, currentBranch);
if (shouldPersist === true) {
const refStr = github.context.ref || (await (0, index_js_3.shell)("git symbolic-ref HEAD"));
const branch = (0, index_js_3.parseBranchFromRef)(refStr);
console.log(`Persisting new benchmark data for branch '${branch}' commit '${currBench.commitSha}'`);
// TODO: prune and limit total entries
// appendBenchmarkToHistoryAndPrune(history, currBench, branch, opts);
await historyProvider.writeLatestInBranch(branch, currBench);
await historyProvider.writeToHistory(currBench);
}
const resultsComp = (0, compute_js_1.computeBenchComparision)(currBench, prevBench, opts.threshold);
if (!opts.skipPostComment && (0, context_js_1.isGaRun)()) {
await (0, comment_js_1.postGaComment)(resultsComp);
}
if (resultsComp.someFailed && !opts.noThrow) {
throw Error("Performance regression");
}
}