From e3535f6ae85e5238e56a982bc6e5ca6f283b9d9d Mon Sep 17 00:00:00 2001 From: jpaul Date: Tue, 21 Nov 2023 16:18:50 +0100 Subject: [PATCH] add mermaid diagramm to pr comment --- action.yml | 4 ++++ dist/cleanup/index.js | 39 ++++++++++++++++++++++++++++++----- dist/main/index.js | 39 ++++++++++++++++++++++++++++++----- src/features/reports.ts | 45 +++++++++++++++++++++++++++++++++-------- 4 files changed, 109 insertions(+), 18 deletions(-) diff --git a/action.yml b/action.yml index 1eac87a..13c853a 100644 --- a/action.yml +++ b/action.yml @@ -43,6 +43,10 @@ inputs: required: false description: 'Post a comment containing a Native Image build report on pull requests.' default: 'false' + native-image-pr-comparison: + required: false + description: 'Post a comment containing a comparison between the Native Image of the pr-branch and the pr-base-branch on pull.' + default: 'false' version: required: false description: 'GraalVM version (release, latest, dev).' diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 3750a98..42f674c 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -74427,6 +74427,7 @@ const BYTES_TO_GiB = 1024 * 1024 * 1024; const DOCS_BASE = 'https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md'; const INPUT_NI_JOB_REPORTS = 'native-image-job-reports'; const INPUT_NI_PR_REPORTS = 'native-image-pr-reports'; +const INPUT_NI_PR_COMPARISON = 'native-image-pr-comparison'; const NATIVE_IMAGE_CONFIG_FILE = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-options.properties'); const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE'; function setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalVMVersion) { @@ -74458,9 +74459,6 @@ function generateReports() { return; } const buildOutput = JSON.parse(fs.readFileSync(BUILD_OUTPUT_JSON_PATH, 'utf8')); - const treeSha = yield (0, utils_1.createTree)(JSON.stringify(buildOutput)); - yield (0, utils_1.createRef)(treeSha); - const prMetrics = JSON.parse(yield (0, utils_1.getPrBaseBranchMetrics)()); const report = createReport(buildOutput); if (areJobReportsEnabled()) { core.summary.addRaw(report); @@ -74469,8 +74467,12 @@ function generateReports() { if (arePRReportsEnabled()) { yield (0, utils_1.createPRComment)(report); } - const prBaseReport = createPRComparison(buildOutput, prMetrics); - yield (0, utils_1.createPRComment)(prBaseReport); + const treeSha = yield (0, utils_1.createTree)(JSON.stringify(buildOutput)); + yield (0, utils_1.createRef)(treeSha); + if (arePRBaseComparisonEnabled()) { + const prMetrics = JSON.parse(yield (0, utils_1.getPrBaseBranchMetrics)()); + yield (0, utils_1.createPRComment)(createPRComparison(buildOutput, prMetrics)); + } } }); } @@ -74481,6 +74483,9 @@ function areJobReportsEnabled() { function arePRReportsEnabled() { return (0, utils_1.isPREvent)() && core.getInput(INPUT_NI_PR_REPORTS) === 'true'; } +function arePRBaseComparisonEnabled() { + return (0, utils_1.isPREvent)() && core.getInput(INPUT_NI_PR_COMPARISON) === 'true'; +} function getNativeImageOptionsFile() { let optionsFile = process.env[NATIVE_IMAGE_CONFIG_FILE_ENV]; if (optionsFile === undefined) { @@ -74548,6 +74553,30 @@ function createPRComparison(dataRecent, dataBase) { +\`\`\`mermaid +gantt + title Native Image Size Details + todayMarker off + dateFormat X + axisFormat %s + + section Code area + ${recentBranch} (${bytesToHuman(detailsRecent.code_area.bytes)}) : active, 0, ${detailsRecent.code_area.bytes / 1000000} + ${baseBranch} (${bytesToHuman(detailsBase.code_area.bytes)}) : 0, ${detailsBase.code_area.bytes / 1000000} + + section Image heap + ${recentBranch} (${bytesToHuman(detailsRecent.image_heap.bytes)}) : active, 0, ${detailsRecent.image_heap.bytes / 1000000} + ${baseBranch} (${bytesToHuman(detailsBase.image_heap.bytes)}) : 0, ${detailsBase.image_heap.bytes / 1000000} + + section Other data + ${recentBranch} (${bytesToHuman(otherBytesRecent)}) : active, 0, ${otherBytesRecent / 1000000} + ${baseBranch} (${bytesToHuman(otherBytesBase)}) : 0, ${otherBytesBase / 1000000} + + section Total + ${recentBranch} (${bytesToHuman(detailsRecent.total_bytes)}) : active, 0, ${detailsRecent.total_bytes / 1000000} + ${baseBranch} (${bytesToHuman(detailsBase.total_bytes)}) : 0, ${detailsBase.total_bytes / 1000000} +\`\`\` + Report generated by setup-graalvm.`; } function createReport(data) { diff --git a/dist/main/index.js b/dist/main/index.js index d97a5e1..cb39e75 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -74526,6 +74526,7 @@ const BYTES_TO_GiB = 1024 * 1024 * 1024; const DOCS_BASE = 'https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md'; const INPUT_NI_JOB_REPORTS = 'native-image-job-reports'; const INPUT_NI_PR_REPORTS = 'native-image-pr-reports'; +const INPUT_NI_PR_COMPARISON = 'native-image-pr-comparison'; const NATIVE_IMAGE_CONFIG_FILE = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-options.properties'); const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE'; function setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalVMVersion) { @@ -74557,9 +74558,6 @@ function generateReports() { return; } const buildOutput = JSON.parse(fs.readFileSync(BUILD_OUTPUT_JSON_PATH, 'utf8')); - const treeSha = yield (0, utils_1.createTree)(JSON.stringify(buildOutput)); - yield (0, utils_1.createRef)(treeSha); - const prMetrics = JSON.parse(yield (0, utils_1.getPrBaseBranchMetrics)()); const report = createReport(buildOutput); if (areJobReportsEnabled()) { core.summary.addRaw(report); @@ -74568,8 +74566,12 @@ function generateReports() { if (arePRReportsEnabled()) { yield (0, utils_1.createPRComment)(report); } - const prBaseReport = createPRComparison(buildOutput, prMetrics); - yield (0, utils_1.createPRComment)(prBaseReport); + const treeSha = yield (0, utils_1.createTree)(JSON.stringify(buildOutput)); + yield (0, utils_1.createRef)(treeSha); + if (arePRBaseComparisonEnabled()) { + const prMetrics = JSON.parse(yield (0, utils_1.getPrBaseBranchMetrics)()); + yield (0, utils_1.createPRComment)(createPRComparison(buildOutput, prMetrics)); + } } }); } @@ -74580,6 +74582,9 @@ function areJobReportsEnabled() { function arePRReportsEnabled() { return (0, utils_1.isPREvent)() && core.getInput(INPUT_NI_PR_REPORTS) === 'true'; } +function arePRBaseComparisonEnabled() { + return (0, utils_1.isPREvent)() && core.getInput(INPUT_NI_PR_COMPARISON) === 'true'; +} function getNativeImageOptionsFile() { let optionsFile = process.env[NATIVE_IMAGE_CONFIG_FILE_ENV]; if (optionsFile === undefined) { @@ -74647,6 +74652,30 @@ function createPRComparison(dataRecent, dataBase) { +\`\`\`mermaid +gantt + title Native Image Size Details + todayMarker off + dateFormat X + axisFormat %s + + section Code area + ${recentBranch} (${bytesToHuman(detailsRecent.code_area.bytes)}) : active, 0, ${detailsRecent.code_area.bytes / 1000000} + ${baseBranch} (${bytesToHuman(detailsBase.code_area.bytes)}) : 0, ${detailsBase.code_area.bytes / 1000000} + + section Image heap + ${recentBranch} (${bytesToHuman(detailsRecent.image_heap.bytes)}) : active, 0, ${detailsRecent.image_heap.bytes / 1000000} + ${baseBranch} (${bytesToHuman(detailsBase.image_heap.bytes)}) : 0, ${detailsBase.image_heap.bytes / 1000000} + + section Other data + ${recentBranch} (${bytesToHuman(otherBytesRecent)}) : active, 0, ${otherBytesRecent / 1000000} + ${baseBranch} (${bytesToHuman(otherBytesBase)}) : 0, ${otherBytesBase / 1000000} + + section Total + ${recentBranch} (${bytesToHuman(detailsRecent.total_bytes)}) : active, 0, ${detailsRecent.total_bytes / 1000000} + ${baseBranch} (${bytesToHuman(detailsBase.total_bytes)}) : 0, ${detailsBase.total_bytes / 1000000} +\`\`\` + Report generated by setup-graalvm.`; } function createReport(data) { diff --git a/src/features/reports.ts b/src/features/reports.ts index 0c680cf..c4df1cd 100644 --- a/src/features/reports.ts +++ b/src/features/reports.ts @@ -15,6 +15,7 @@ const DOCS_BASE = 'https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md' const INPUT_NI_JOB_REPORTS = 'native-image-job-reports' const INPUT_NI_PR_REPORTS = 'native-image-pr-reports' +const INPUT_NI_PR_COMPARISON = 'native-image-pr-comparison' const NATIVE_IMAGE_CONFIG_FILE = join( tmpdir(), 'native-image-options.properties' @@ -128,12 +129,6 @@ export async function generateReports(): Promise { fs.readFileSync(BUILD_OUTPUT_JSON_PATH, 'utf8') ) - const treeSha = await createTree(JSON.stringify(buildOutput)) - await createRef(treeSha) - const prMetrics: BuildOutput = JSON.parse( - await getPrBaseBranchMetrics() - ) - const report = createReport(buildOutput) if (areJobReportsEnabled()) { core.summary.addRaw(report) @@ -142,8 +137,14 @@ export async function generateReports(): Promise { if (arePRReportsEnabled()) { await createPRComment(report) } - const prBaseReport = createPRComparison(buildOutput, prMetrics) - await createPRComment(prBaseReport) + const treeSha = await createTree(JSON.stringify(buildOutput)) + await createRef(treeSha) + if (arePRBaseComparisonEnabled()) { + const prMetrics: BuildOutput = JSON.parse( + await getPrBaseBranchMetrics() + ) + await createPRComment(createPRComparison(buildOutput, prMetrics)) + } } } @@ -155,6 +156,10 @@ function arePRReportsEnabled(): boolean { return isPREvent() && core.getInput(INPUT_NI_PR_REPORTS) === 'true' } +function arePRBaseComparisonEnabled(): boolean { + return isPREvent() && core.getInput(INPUT_NI_PR_COMPARISON) === 'true' +} + function getNativeImageOptionsFile(): string { let optionsFile = process.env[NATIVE_IMAGE_CONFIG_FILE_ENV] if (optionsFile === undefined) { @@ -228,6 +233,30 @@ function createPRComparison(dataRecent: BuildOutput, dataBase: BuildOutput): str +\`\`\`mermaid +gantt + title Native Image Size Details + todayMarker off + dateFormat X + axisFormat %s + + section Code area + ${recentBranch} (${bytesToHuman(detailsRecent.code_area.bytes)}) : active, 0, ${detailsRecent.code_area.bytes / 1000000} + ${baseBranch} (${bytesToHuman(detailsBase.code_area.bytes)}) : 0, ${detailsBase.code_area.bytes / 1000000} + + section Image heap + ${recentBranch} (${bytesToHuman(detailsRecent.image_heap.bytes)}) : active, 0, ${detailsRecent.image_heap.bytes / 1000000} + ${baseBranch} (${bytesToHuman(detailsBase.image_heap.bytes)}) : 0, ${detailsBase.image_heap.bytes / 1000000} + + section Other data + ${recentBranch} (${bytesToHuman(otherBytesRecent)}) : active, 0, ${otherBytesRecent / 1000000} + ${baseBranch} (${bytesToHuman(otherBytesBase)}) : 0, ${otherBytesBase / 1000000} + + section Total + ${recentBranch} (${bytesToHuman(detailsRecent.total_bytes)}) : active, 0, ${detailsRecent.total_bytes / 1000000} + ${baseBranch} (${bytesToHuman(detailsBase.total_bytes)}) : 0, ${detailsBase.total_bytes / 1000000} +\`\`\` + Report generated by setup-graalvm.` }