Skip to content

Commit

Permalink
remove old method
Browse files Browse the repository at this point in the history
  • Loading branch information
vezenovm committed Aug 16, 2024
1 parent e306205 commit 6523ebb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 92 deletions.
86 changes: 1 addition & 85 deletions src/format/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,90 +324,6 @@ const MARKDOWN_DIFF_COLS_BRILLIG = [
{ txt: "" },
];

export const formatMarkdownDiff = (
header: string,
diffs: DiffCircuit[],
repository: string,
commitHash: string,
refCommitHash?: string,
summaryQuantile = 0.8
) => {
const diffReport = [header, "", generateCommitInfo(repository, commitHash, refCommitHash)];
if (diffs.length === 0)
return diffReport.concat(["", "### There are no changes in circuit sizes"]).join("\n").trim();

const summaryHeader = MARKDOWN_SUMMARY_COLS_CIRCUIT.map((entry) => entry.txt)
.join(" | ")
.trim();
const summaryHeaderSeparator = MARKDOWN_SUMMARY_COLS_CIRCUIT.map((entry) =>
entry.txt ? alignPattern(entry.align) : ""
)
.join("|")
.trim();

const diffHeader = MARKDOWN_DIFF_COLS_CIRCUIT.map((entry) => entry.txt)
.join(" | ")
.trim();
const diffHeaderSeparator = MARKDOWN_DIFF_COLS_CIRCUIT.map((entry) =>
entry.txt ? alignPattern(entry.align) : ""
)
.join("|")
.trim();

const sortedMethods = _sortBy(diffs, (program) => Math.abs(program.circuit_size.percentage));
const circuitChangeQuantile = Math.abs(
sortedMethods[Math.floor((sortedMethods.length - 1) * summaryQuantile)]?.circuit_size
.percentage ?? 0
);

const summaryRows = selectSummaryDiffs(diffs, circuitChangeQuantile).flatMap((diff) =>
[
"",
`**${diff.name}**`,
...formatMarkdownSummaryCell([diff.opcodes]),
...formatMarkdownSummaryCell([diff.circuit_size]),
"",
]
.join(" | ")
.trim()
);

const fullReportRows = diffs.flatMap((diff) =>
[
"",
`**${diff.name}**`,
...formatMarkdownFullCell([diff.opcodes]),
...formatMarkdownFullCell([diff.circuit_size]),
"",
]
.join(" | ")
.trim()
);

return diffReport
.concat([
"",
`### 🧾 Summary (${Math.round((1 - summaryQuantile) * 100)}% most significant diffs)`,
"",
summaryHeader,
summaryHeaderSeparator,
...summaryRows,
"---",
"",
"<details>",
"<summary><strong>Full diff report</strong> 👇</summary>",
"<br />",
"",
diffHeader,
diffHeaderSeparator,
...fullReportRows,
"</details>",
"",
])
.join("\n")
.trim();
};

export const formatCircuitRows = (
diffs: DiffCircuit[],
summaryQuantile = 0.8
Expand Down Expand Up @@ -465,7 +381,7 @@ export const formatBrilligRows = (
return [summaryRows, fullReportRows];
};

export const formatMarkdownDiffNew = (
export const formatMarkdownDiff = (
header: string,
repository: string,
commitHash: string,
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { context, getOctokit } from "@actions/github";
import {
formatBrilligRows,
formatCircuitRows,
formatMarkdownDiffNew,
formatMarkdownDiff,
formatShellBrilligRows,
formatShellCircuitRows,
formatShellDiff,
Expand Down Expand Up @@ -154,7 +154,7 @@ async function run() {

core.info(`Format markdown of ${numDiffs} diffs`);
// const [summaryRows, fullReportRows] = formatCircuitRows(diffCircuitRows, summaryQuantile);
const markdown = formatMarkdownDiffNew(
const markdown = formatMarkdownDiff(
header,
repository,
context.sha,
Expand Down
9 changes: 4 additions & 5 deletions tests/program_report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
formatBrilligRows,
formatCircuitRows,
formatMarkdownDiff,
formatMarkdownDiffNew,
formatShellBrilligRows,
formatShellCircuitRows,
formatShellDiff,
Expand Down Expand Up @@ -49,7 +48,7 @@ describe("Markdown format", () => {
const [summaryRows, fullReportRows] = formatCircuitRows(circuitDiffs, 0.8);
fs.writeFileSync(
"tests/mocks/1-2-program-acir.md",
formatMarkdownDiffNew(
formatMarkdownDiff(
"# Changes to gas cost",
"Rubilmax/foundry-gas-diff",
"d62d23148ca73df77cd4378ee1b3c17f1f303dbf",
Expand All @@ -64,7 +63,7 @@ describe("Markdown format", () => {
const [summaryRowsBrillig, fullReportRowsBrillig] = formatBrilligRows(brilligDiffs, 0.8);
fs.writeFileSync(
"tests/mocks/1-2-program-brillig.md",
formatMarkdownDiffNew(
formatMarkdownDiff(
"# Changes to gas cost",
"Rubilmax/foundry-gas-diff",
"d62d23148ca73df77cd4378ee1b3c17f1f303dbf",
Expand All @@ -87,7 +86,7 @@ describe("Markdown format", () => {
const [summaryRows, fullReportRows] = formatCircuitRows(circuitDiffs, 0.8);
fs.writeFileSync(
"tests/mocks/1-1-program-acir.md",
formatMarkdownDiffNew(
formatMarkdownDiff(
"# Changes to gas cost",
"Rubilmax/foundry-gas-diff",
"d62d23148ca73df77cd4378ee1b3c17f1f303dbf",
Expand All @@ -100,7 +99,7 @@ describe("Markdown format", () => {
const [summaryRowsBrillig, fullReportRowsBrillig] = formatBrilligRows(brilligDiffs, 0.8);
fs.writeFileSync(
"tests/mocks/1-1-program-brillig.md",
formatMarkdownDiffNew(
formatMarkdownDiff(
"# Changes to gas cost",
"Rubilmax/foundry-gas-diff",
"d62d23148ca73df77cd4378ee1b3c17f1f303dbf",
Expand Down

0 comments on commit 6523ebb

Please sign in to comment.