11/// run `make perf-tester` after updating this or util.js
22
3- import fs from 'fs' ;
4- import { exec } from '@actions/exec' ;
3+ const fs = require ( 'fs' ) ;
4+ const { exec } = require ( '@actions/exec' ) ;
55
6- export const getInput = key => ( {
6+ const getInput = key => ( {
77 'build-script' : 'make bootstrap benchmark_setup' ,
88 benchmark : 'make -s run_benchmark' ,
99 'minimum-change-threshold' : 5 ,
1010 'use-check' : 'no' ,
1111 'repo-token' : process . env . GITHUB_TOKEN
1212} ) [ key ]
13+ exports . getInput = getInput
1314
14- export async function runBenchmark ( ) {
15+ exports . runBenchmark = async ( ) => {
1516 let benchmarkBuffers = [ ]
1617 await exec ( getInput ( 'benchmark' ) , [ ] , {
1718 listeners : {
@@ -36,7 +37,7 @@ function parse(benchmarkData) {
3637 return benchmarks
3738}
3839
39- export function averageBenchmarks ( benchmarks ) {
40+ exports . averageBenchmarks = ( benchmarks ) => {
4041 const result = Object . create ( null )
4142 for ( const key of Object . keys ( benchmarks [ 0 ] ) ) {
4243 result [ key ] = benchmarks . reduce ( ( acc , bench ) => acc + bench [ key ] , 0 ) / benchmarks . length
@@ -49,7 +50,7 @@ export function averageBenchmarks(benchmarks) {
4950 * @param {{[key: string]: number} } after
5051 * @return {Diff[] }
5152 */
52- export function toDiff ( before , after ) {
53+ exports . toDiff = ( before , after ) => {
5354 const names = [ ...new Set ( [ ...Object . keys ( before ) , ...Object . keys ( after ) ] ) ]
5455 return names . map ( name => {
5556 const timeBefore = before [ name ] || 0
@@ -60,49 +61,11 @@ export function toDiff(before, after) {
6061}
6162
6263
63- /**
64- * Check if a given file exists and can be accessed.
65- * @param {string } filename
66- */
67- export async function fileExists ( filename ) {
68- try {
69- await fs . promises . access ( filename , fs . constants . F_OK ) ;
70- return true ;
71- } catch ( e ) { }
72- return false ;
73- }
74-
75- /**
76- * Remove any matched hash patterns from a filename string.
77- * @param {string= } regex
78- * @returns {(((fileName: string) => string) | undefined) }
79- */
80- export function stripHash ( regex ) {
81- if ( regex ) {
82- console . log ( `Striping hash from build chunks using '${ regex } ' pattern.` ) ;
83- return function ( fileName ) {
84- return fileName . replace ( new RegExp ( regex ) , ( str , ...hashes ) => {
85- hashes = hashes . slice ( 0 , - 2 ) . filter ( ( c ) => c != null ) ;
86- if ( hashes . length ) {
87- for ( let i = 0 ; i < hashes . length ; i ++ ) {
88- const hash = hashes [ i ] || '' ;
89- str = str . replace ( hash , hash . replace ( / ./ g, '*' ) ) ;
90- }
91- return str ;
92- }
93- return '' ;
94- } ) ;
95- } ;
96- }
97-
98- return undefined ;
99- }
100-
10164/**
10265 * @param {number } delta
10366 * @param {number } difference
10467 */
105- export function getDeltaText ( delta , difference ) {
68+ function getDeltaText ( delta , difference ) {
10669 let deltaText = ( delta > 0 ? '+' : '' ) + delta . toLocaleString ( 'en-US' ) + 'ms' ;
10770 if ( delta && Math . abs ( delta ) > 1 ) {
10871 deltaText += ` (${ Math . abs ( difference ) } %)` ;
@@ -113,7 +76,7 @@ export function getDeltaText(delta, difference) {
11376/**
11477 * @param {number } difference
11578 */
116- export function iconForDifference ( difference ) {
79+ function iconForDifference ( difference ) {
11780 let icon = '' ;
11881 if ( difference >= 50 ) icon = '🆘' ;
11982 else if ( difference >= 20 ) icon = '🚨' ;
@@ -174,7 +137,7 @@ function markdownTable(rows) {
174137 * @param {boolean } [options.omitUnchanged]
175138 * @param {number } [options.minimumChangeThreshold]
176139 */
177- export function diffTable ( tests , { showTotal, collapseUnchanged, omitUnchanged, minimumChangeThreshold } ) {
140+ exports . diffTable = ( tests , { showTotal, collapseUnchanged, omitUnchanged, minimumChangeThreshold } ) => {
178141 let changedRows = [ ] ;
179142 let unChangedRows = [ ] ;
180143
@@ -225,6 +188,4 @@ export function diffTable(tests, { showTotal, collapseUnchanged, omitUnchanged,
225188 * Convert a string "true"/"yes"/"1" argument value to a boolean
226189 * @param {string } v
227190 */
228- export function toBool ( v ) {
229- return / ^ ( 1 | t r u e | y e s ) $ / . test ( v ) ;
230- }
191+ exports . toBool = v => / ^ ( 1 | t r u e | y e s ) $ / . test ( v ) ;
0 commit comments