Skip to content

Commit

Permalink
fix: 213 summary-always and gh-repository don't work together (#214)
Browse files Browse the repository at this point in the history
* move summary logic into writeBenchmark function so that we only clone repo once
  • Loading branch information
ktrz authored Jan 25, 2024
1 parent 83426c0 commit 029e9b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from '@actions/core';
import { configFromJobInput } from './config';
import { extractResult } from './extract';
import { writeBenchmark, writeSummary } from './write';
import { writeBenchmark } from './write';

async function main() {
const config = await configFromJobInput();
Expand All @@ -12,10 +12,6 @@ async function main() {

await writeBenchmark(bench, config);

if (config.summaryAlways) {
await writeSummary(bench, config);
}

console.log('github-action-benchmark was run successfully!', '\nData:', bench);
}

Expand Down
18 changes: 8 additions & 10 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,15 @@ export async function writeBenchmark(bench: Benchmark, config: Config) {
} else {
await handleComment(name, bench, prevBench, config);
await handleAlert(name, bench, prevBench, config);
await handleSummary(name, bench, prevBench, config);
}
}

export async function writeSummary(bench: Benchmark, config: Config): Promise<void> {
const { name, externalDataJsonPath } = config;
const prevBench = externalDataJsonPath
? await writeBenchmarkToExternalJson(bench, externalDataJsonPath, config)
: await writeBenchmarkToGitHubPages(bench, config);
async function handleSummary(benchName: string, currBench: Benchmark, prevBench: Benchmark, config: Config) {
const { summaryAlways } = config;

if (prevBench === null) {
core.debug('Alert check was skipped because previous benchmark result was not found');
if (!summaryAlways) {
core.debug('Summary was skipped because summary-always is disabled');
return;
}

Expand All @@ -556,7 +554,7 @@ export async function writeSummary(bench: Benchmark, config: Config): Promise<vo
header: true,
},
{
data: `Current: "${bench.commit.id}"`,
data: `Current: "${currBench.commit.id}"`,
header: true,
},
{
Expand All @@ -568,7 +566,7 @@ export async function writeSummary(bench: Benchmark, config: Config): Promise<vo
header: true,
},
];
const rows: SummaryTableRow[] = bench.benches.map((bench) => {
const rows: SummaryTableRow[] = currBench.benches.map((bench) => {
const previousBench = prevBench.benches.find((pb) => pb.name === bench.name);

if (previousBench) {
Expand Down Expand Up @@ -609,7 +607,7 @@ export async function writeSummary(bench: Benchmark, config: Config): Promise<vo
});

await core.summary
.addHeading(`Benchmarks: ${name}`)
.addHeading(`Benchmarks: ${benchName}`)
.addTable([headers, ...rows])
.write();
}

0 comments on commit 029e9b8

Please sign in to comment.