From 54e4ec8b0d7e7d231e9a95eff355188bb3537411 Mon Sep 17 00:00:00 2001 From: Jason Heeris Date: Sun, 27 Aug 2023 10:36:35 +0800 Subject: [PATCH] Move size reporting job into separate composite workflow. --- .../report-code-size-changes/action.yml | 56 +++++++++++++++++++ .github/workflows/check-binary-size.yml | 46 ++------------- 2 files changed, 62 insertions(+), 40 deletions(-) create mode 100644 .github/actions/report-code-size-changes/action.yml diff --git a/.github/actions/report-code-size-changes/action.yml b/.github/actions/report-code-size-changes/action.yml new file mode 100644 index 000000000..6d71feab2 --- /dev/null +++ b/.github/actions/report-code-size-changes/action.yml @@ -0,0 +1,56 @@ +# Github composite action to report on code size changes +name: Report binary size changes on PR +description: | + Report on code size changes resulting from a PR as a comment on the PR + (accessed via context). +inputs: + reference: + description: The size in bytes of the reference binary (base of PR). + required: true + updated: + description: The size in bytes of the updated binary (head of PR). + required: true +runs: + using: composite + steps: + - name: Post a PR comment if the size has changed + uses: actions/github-script@v6 + env: + SIZE_REFERENCE: ${{ inputs.reference }} + SIZE_UPDATED: ${{ inputs.updated }} + with: + script: | + const reference = process.env.SIZE_REFERENCE; + const updated = process.env.SIZE_UPDATED; + + if (!(reference > 0)) { + core.setFailed(`Reference size invalid: ${reference}`); + return; + } + + if (!(updated > 0)) { + core.setFailed(`Updated size invalid: ${updated}`); + return; + } + + const diff = updated - reference; + const plus = diff > 0 ? "+" : ""; + const diff_str = `${plus}${diff}B`; + + if (diff !== 0) { + const percent = (((updated / reference) - 1) * 100).toFixed(2); + // The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines, + // which is interpreted as a code block by Markdown. + const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace. + + Original binary size: **${reference}B** + Updated binary size: **${updated}B** + Difference: **${diff_str}** (${percent}%)`; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body + }) + } diff --git a/.github/workflows/check-binary-size.yml b/.github/workflows/check-binary-size.yml index 485204d23..35dc99a63 100644 --- a/.github/workflows/check-binary-size.yml +++ b/.github/workflows/check-binary-size.yml @@ -94,44 +94,10 @@ jobs: permissions: pull-requests: write steps: - - name: Post a PR comment if the size has changed - uses: actions/github-script@v6 - env: - SIZE_REFERENCE: ${{ needs.measure.outputs.binary-size-reference }} - SIZE_UPDATED: ${{ needs.measure.outputs.binary-size-updated }} + # Clone backtrace to access Github composite actions to report size. + - uses: actions/checkout@v3 + # Run the size reporting action. + - uses: ./.github/actions/report-code-size-changes with: - script: | - const reference = process.env.SIZE_REFERENCE; - const updated = process.env.SIZE_UPDATED; - - if (!(reference > 0)) { - core.setFailed(`Reference size invalid: ${reference}`); - return; - } - - if (!(updated > 0)) { - core.setFailed(`Updated size invalid: ${updated}`); - return; - } - - const diff = updated - reference; - const plus = diff > 0 ? "+" : ""; - const diff_str = `${plus}${diff}B`; - - if (diff !== 0) { - const percent = (((updated / reference) - 1) * 100).toFixed(2); - // The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines, - // which is interpreted as a code block by Markdown. - const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace. - - Original binary size: **${reference}B** - Updated binary size: **${updated}B** - Difference: **${diff_str}** (${percent}%)`; - - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body - }) - } + reference: ${{ needs.measure.outputs.binary-size-reference }} + updated: ${{ needs.measure.outputs.binary-size-updated }}