diff --git a/action.yml b/action.yml index 4d458c809..fd5717edc 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,7 @@ inputs: required: true default: 'Benchmark' tool: - description: 'Tool to use get benchmark output. One of "cargo", "go", "benchmarkjs", "pytest"' + description: 'Tool to use get benchmark output. One of "cargo", "go", "benchmarkjs", "pytest", "customBiggerIsBetter", "customSmallerIsBetter"' required: true output-file-path: description: 'A path to file which contains the benchmark output' diff --git a/src/config.js b/src/config.js index e68d31ac7..07c1bd323 100644 --- a/src/config.js +++ b/src/config.js @@ -11,7 +11,16 @@ const core = __importStar(require("@actions/core")); const fs_1 = require("fs"); const os = __importStar(require("os")); const path = __importStar(require("path")); -exports.VALID_TOOLS = ['cargo', 'go', 'benchmarkjs', 'pytest', 'googlecpp', 'catch2']; +exports.VALID_TOOLS = [ + 'cargo', + 'go', + 'benchmarkjs', + 'pytest', + 'googlecpp', + 'catch2', + 'customBiggerIsBetter', + 'customSmallerIsBetter', +]; const RE_UINT = /^\d+$/; function validateToolType(tool) { if (exports.VALID_TOOLS.includes(tool)) { diff --git a/src/default_index_html.js b/src/default_index_html.js index 07e27658d..ecf121b05 100644 --- a/src/default_index_html.js +++ b/src/default_index_html.js @@ -119,6 +119,8 @@ exports.DEFAULT_INDEX_HTML = String.raw ` pytest: '#3572a5', googlecpp: '#f34b7d', catch2: '#f34b7d', + customBiggerIsBetter: '#38ff38', + customSmallerIsBetter: '#ff3838', _: '#333333' }; diff --git a/src/extract.js b/src/extract.js index 6c2cc5ff6..c669a4093 100644 --- a/src/extract.js +++ b/src/extract.js @@ -279,6 +279,17 @@ function extractCatch2Result(output) { } return ret; } +function extractCustomBenchmarkResult(output) { + try { + const json = JSON.parse(output); + return json.map(({ name, value, unit, range, extra }) => { + return { name, value, unit, range, extra }; + }); + } + catch (err) { + throw new Error(`Output file for 'custom-(bigger|smaller)-is-better' must be JSON file containing an array of entries in BenchmarkResult format: ${err.message}`); + } +} async function extractResult(config) { const output = await fs_1.promises.readFile(config.outputFilePath, 'utf8'); const { tool, githubToken } = config; @@ -302,6 +313,12 @@ async function extractResult(config) { case 'catch2': benches = extractCatch2Result(output); break; + case 'customBiggerIsBetter': + benches = extractCustomBenchmarkResult(output); + break; + case 'customSmallerIsBetter': + benches = extractCustomBenchmarkResult(output); + break; default: throw new Error(`FATAL: Unexpected tool: '${tool}'`); } diff --git a/src/write.js b/src/write.js index 43fdf8c9d..9cd2bcccf 100644 --- a/src/write.js +++ b/src/write.js @@ -66,6 +66,10 @@ function biggerIsBetter(tool) { return false; case 'catch2': return false; + case 'customBiggerIsBetter': + return true; + case 'customSmallerIsBetter': + return false; } } function findAlerts(curSuite, prevSuite, threshold) {