From d58623da745369a45ff17969861cc094e98d1f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Trze=C5=9Bniewski?= Date: Fri, 26 Jan 2024 16:59:21 +0100 Subject: [PATCH] fix: 159 markdown rendering for summary is broken (#218) * add additional debug lines to `handleSummary` function * create a summary without expandable details * add summary always to all CI benchmarks --- .github/workflows/ci.yml | 10 +++++- src/write.ts | 73 +++++----------------------------------- 2 files changed, 18 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 006ed60d0..eed878cb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/src/write.ts b/src/write.ts index 6f0fc02bc..fdf248a66 100644 --- a/src/write.ts +++ b/src/write.ts @@ -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 { @@ -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}`, '', - '
', + expandableDetails ? '
' : '', '', `| Benchmark suite | Current: ${curSuite.commit.id} | Previous: ${prevSuite.commit.id} | Ratio |`, '|-|-|-|-|', @@ -189,7 +188,7 @@ function buildComment(benchName: string, curSuite: Benchmark, prevSuite: Benchma } // Footer - lines.push('', '
', '', commentFooter()); + lines.push('', expandableDetails ? '
' : '', '', commentFooter()); return lines.join('\n'); } @@ -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(); }