Skip to content

Commit

Permalink
fix: 159 markdown rendering for summary is broken (#218)
Browse files Browse the repository at this point in the history
* add additional debug lines to `handleSummary` function
* create a summary without expandable details
* add summary always to all CI benchmarks
  • Loading branch information
ktrz committed Jan 26, 2024
1 parent 6fc0096 commit d58623d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 65 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
tool: 'cargo'
output-file-path: examples/rust/output.txt
fail-on-alert: true
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Rust Benchmark'

go:
Expand Down Expand Up @@ -68,6 +68,7 @@ jobs:
output-file-path: examples/go/output.txt
skip-fetch-gh-pages: true
fail-on-alert: true
summary-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Go Benchmark'

benchmarkjs:
Expand Down Expand Up @@ -97,6 +98,7 @@ jobs:
output-file-path: examples/benchmarkjs/output.txt
skip-fetch-gh-pages: true
fail-on-alert: true
summary-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Benchmark.js Benchmark'

pytest-benchmark:
Expand Down Expand Up @@ -132,6 +134,7 @@ jobs:
output-file-path: examples/pytest/output.json
skip-fetch-gh-pages: true
fail-on-alert: true
summary-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Python Benchmark with pytest-benchmark'

google-benchmark-framework:
Expand Down Expand Up @@ -168,6 +171,7 @@ jobs:
output-file-path: examples/cpp/benchmark_result.json
skip-fetch-gh-pages: true
fail-on-alert: true
summary-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'C++ Benchmark'

catch2-framework:
Expand Down Expand Up @@ -202,6 +206,7 @@ jobs:
output-file-path: examples/catch2/benchmark_result.txt
skip-fetch-gh-pages: true
fail-on-alert: true
summary-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Catch2 Benchmark'

julia-benchmark:
Expand Down Expand Up @@ -240,6 +245,7 @@ jobs:
output-file-path: examples/julia/output.json
skip-fetch-gh-pages: true
fail-on-alert: true
summary-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Julia benchmark'

benchmarkdotnet-framework:
Expand Down Expand Up @@ -272,6 +278,7 @@ jobs:
output-file-path: examples/benchmarkdotnet/BenchmarkDotNet.Artifacts/results/Sample.Benchmarks-report-full-compressed.json
skip-fetch-gh-pages: true
fail-on-alert: true
summary-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Benchmark.Net Benchmark'

jmh:
Expand Down Expand Up @@ -308,6 +315,7 @@ jobs:
output-file-path: examples/java/jmh-result.json
skip-fetch-gh-pages: true
fail-on-alert: true
summary-always: true
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'JMH Benchmark'

only-alert-with-cache:
Expand Down
73 changes: 9 additions & 64 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as git from './git';
import { Benchmark, BenchmarkResult } from './extract';
import { Config, ToolType } from './config';
import { DEFAULT_INDEX_HTML } from './default_index_html';
import { SummaryTableRow } from '@actions/core/lib/summary';

export type BenchmarkSuites = { [name: string]: Benchmark[] };
export interface DataJson {
Expand Down Expand Up @@ -161,11 +160,11 @@ function commentFooter(): string {
return `This comment was automatically generated by [workflow](${actionUrl}) using [github-action-benchmark](https://github.com/marketplace/actions/continuous-benchmark).`;
}

function buildComment(benchName: string, curSuite: Benchmark, prevSuite: Benchmark): string {
function buildComment(benchName: string, curSuite: Benchmark, prevSuite: Benchmark, expandableDetails = true): string {
const lines = [
`# ${benchName}`,
'',
'<details>',
expandableDetails ? '<details>' : '',
'',
`| Benchmark suite | Current: ${curSuite.commit.id} | Previous: ${prevSuite.commit.id} | Ratio |`,
'|-|-|-|-|',
Expand All @@ -189,7 +188,7 @@ function buildComment(benchName: string, curSuite: Benchmark, prevSuite: Benchma
}

// Footer
lines.push('', '</details>', '', commentFooter());
lines.push('', expandableDetails ? '</details>' : '', '', commentFooter());

return lines.join('\n');
}
Expand Down Expand Up @@ -558,66 +557,12 @@ async function handleSummary(benchName: string, currBench: Benchmark, prevBench:
return;
}

const headers = [
{
data: 'Benchmark Suite',
header: true,
},
{
data: `Current: "${currBench.commit.id}"`,
header: true,
},
{
data: `Previous: "${prevBench.commit.id}"`,
header: true,
},
{
data: 'Ratio',
header: true,
},
];
const rows: SummaryTableRow[] = currBench.benches.map((bench) => {
const previousBench = prevBench.benches.find((pb) => pb.name === bench.name);

if (previousBench) {
const ratio = biggerIsBetter(config.tool)
? previousBench.value / bench.value
: bench.value / previousBench.value;

return [
{
data: bench.name,
},
{
data: strVal(bench),
},
{
data: strVal(previousBench),
},
{
data: floatStr(ratio),
},
];
}
const body = buildComment(benchName, currBench, prevBench, false);

return [
{
data: bench.name,
},
{
data: strVal(bench),
},
{
data: '-',
},
{
data: '-',
},
];
});
const summary = core.summary.addRaw(body);

core.debug('Writing a summary about benchmark comparison');
core.debug(summary.stringify());

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

0 comments on commit d58623d

Please sign in to comment.