Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit dce7a31

Browse files
committed
Address review comments
1 parent c22258e commit dce7a31

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,12 @@ If it is set to `true`, this action will leave a commit comment comparing the cu
377377
`github-token` is necessary as well. Please note that a personal access token is not necessary to
378378
send a commit comment. `secrets.GITHUB_TOKEN` is sufficient.
379379

380-
#### `save-on-pr` (Optional)
380+
#### `save-data-file` (Optional)
381381

382382
- Type: Boolean
383383
- Default: `true`
384384

385-
If it is set to `true`, any commits that are part of a PR will not save the current benchmark.
385+
If it is set to `true`, this action will not save the current benchmark to the external data file.
386386
You can use this option to set up your action to compare the benchmarks between PR and base branch.
387387

388388
#### `alert-threshold` (Optional)

action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ inputs:
3939
description: 'Leave a comment with benchmark result comparison. To enable this feature, github-token input must be given as well'
4040
required: false
4141
default: false
42-
save-on-pr:
43-
description: 'Save the benchmark data on pull requests'
42+
save-data-file:
43+
description: 'Save the benchmark data to external file'
4444
required: false
4545
default: true
4646
comment-on-alert:

src/config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface Config {
1414
autoPush: boolean;
1515
skipFetchGhPages: boolean;
1616
commentAlways: boolean;
17-
saveOnPr: boolean;
17+
saveDataFile: boolean;
1818
commentOnAlert: boolean;
1919
alertThreshold: number;
2020
failOnAlert: boolean;
@@ -213,7 +213,7 @@ export async function configFromJobInput(): Promise<Config> {
213213
const autoPush = getBoolInput('auto-push');
214214
const skipFetchGhPages = getBoolInput('skip-fetch-gh-pages');
215215
const commentAlways = getBoolInput('comment-always');
216-
const saveOnPr = getBoolInput('save-on-pr');
216+
const saveDataFile = getBoolInput('save-data-file');
217217
const commentOnAlert = getBoolInput('comment-on-alert');
218218
const alertThreshold = getPercentageInput('alert-threshold');
219219
const failOnAlert = getBoolInput('fail-on-alert');
@@ -254,7 +254,7 @@ export async function configFromJobInput(): Promise<Config> {
254254
autoPush,
255255
skipFetchGhPages,
256256
commentAlways,
257-
saveOnPr,
257+
saveDataFile,
258258
commentOnAlert,
259259
alertThreshold,
260260
failOnAlert,

src/write.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,15 @@ function getCurrentRepo() {
117117
}
118118

119119
function floatStr(n: number) {
120-
return Number.isInteger(n) ? n.toFixed(0) : n.toFixed(2);
120+
if (Number.isInteger(n)) {
121+
return n.toFixed(0);
122+
}
123+
124+
if (n > 1) {
125+
return n.toFixed(2);
126+
}
127+
128+
return n.toString();
121129
}
122130

123131
function strVal(b: BenchmarkResult): string {
@@ -133,7 +141,6 @@ function commentFooter(): string {
133141
// eslint-disable-next-line @typescript-eslint/camelcase
134142
const repoUrl = repo.html_url ?? '';
135143
const actionUrl = repoUrl + '/actions?query=workflow%3A' + encodeURIComponent(github.context.workflow);
136-
core.debug(`Action URL: ${actionUrl}`);
137144

138145
return `This comment was automatically generated by [workflow](${actionUrl}) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`;
139146
}
@@ -360,7 +367,6 @@ async function writeBenchmarkToGitHubPagesWithRetry(
360367
autoPush,
361368
skipFetchGhPages,
362369
maxItemsInChart,
363-
saveOnPr,
364370
} = config;
365371
const dataPath = path.join(benchmarkDataDirPath, 'data.js');
366372
const isPrivateRepo = github.context.payload.repository?.private ?? false;
@@ -379,11 +385,6 @@ async function writeBenchmarkToGitHubPagesWithRetry(
379385
const data = await loadDataJs(dataPath);
380386
const prevBench = addBenchmarkToDataJson(name, bench, data, maxItemsInChart);
381387

382-
if (!saveOnPr && github.context.eventName === 'pull_request') {
383-
core.debug('Skipping storing benchmarks');
384-
return prevBench;
385-
}
386-
387388
await storeDataJs(dataPath, data);
388389

389390
await git.cmd('add', dataPath);
@@ -461,12 +462,12 @@ async function writeBenchmarkToExternalJson(
461462
jsonFilePath: string,
462463
config: Config,
463464
): Promise<Benchmark | null> {
464-
const { name, maxItemsInChart, saveOnPr } = config;
465+
const { name, maxItemsInChart, saveDataFile } = config;
465466
const data = await loadDataJson(jsonFilePath);
466467
const prevBench = addBenchmarkToDataJson(name, bench, data, maxItemsInChart);
467468

468-
if (!saveOnPr && github.context.eventName === 'pull_request') {
469-
core.debug('Skipping storing benchmarks');
469+
if (!saveDataFile) {
470+
core.debug('Skipping storing benchmarks in external data file');
470471
return prevBench;
471472
}
472473

test/write.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ describe('writeBenchmark()', function() {
189189
autoPush: false,
190190
skipFetchGhPages: false, // Should not affect
191191
commentAlways: false,
192-
saveOnPr: true,
192+
saveDataFile: true,
193193
commentOnAlert: false,
194194
alertThreshold: 2.0,
195195
failOnAlert: true,
@@ -897,7 +897,7 @@ describe('writeBenchmark()', function() {
897897
autoPush: true,
898898
skipFetchGhPages: false, // Should not affect
899899
commentAlways: false,
900-
saveOnPr: true,
900+
saveDataFile: true,
901901
commentOnAlert: false,
902902
alertThreshold: 2.0,
903903
failOnAlert: true,

0 commit comments

Comments
 (0)