diff --git a/action.yml b/action.yml index a88f084..882c014 100644 --- a/action.yml +++ b/action.yml @@ -50,6 +50,10 @@ inputs: description: 'The column and direction to sort the results by. The format is "column:direction", where column is one of "Filename", "Size", or "Change" and direction is "asc" or "desc". For example, "Size:desc" sorts the table by file size in descending order.' default: 'Filename:asc' +outputs: + comment-body: + description: 'The full Markdown body the action posts to the PR, including the size report and footer.' + runs: using: 'node24' main: 'index.js' \ No newline at end of file diff --git a/src/index.js b/src/index.js index 2ad852a..15927bf 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ import { getInput, setFailed, startGroup, endGroup, debug } from '@actions/core' import { context, getOctokit } from '@actions/github'; import { exec } from '@actions/exec'; import { SizePlugin } from '@rschristian/size-plugin'; -import { getPackageManagerAndInstallScript, diffTable, toBool, stripHash, getSortOrder } from './utils.js'; +import { getPackageManagerAndInstallScript, diffTable, toBool, stripHash, getSortOrder, setOutput } from './utils.js'; /** * @typedef {ReturnType} Octokit @@ -170,6 +170,8 @@ async function run(octokit, context, token) { `\n\ncompressed-size-action${commentKey ? `::${commentKey}` : ''}` }; + setOutput('comment-body', comment.body); + if (context.eventName !== 'pull_request' && context.eventName !== 'pull_request_target') { console.log('No PR associated with this action run. Not posting a check or comment.'); outputRawMarkdown = false; diff --git a/src/utils.js b/src/utils.js index fc4b8b7..45857e1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,5 +1,6 @@ import fs from 'fs'; import path from 'path'; +import { EOL } from 'os'; import prettyBytes from 'pretty-bytes'; /** @@ -269,3 +270,22 @@ export function getSortOrder(sortBy) { console.warn(`Invalid 'order-by' value '${sortBy}', defaulting to 'Filename:asc'`); return 'Filename:asc'; } + +/** + * + * @param {string} name + * @param {string} value + */ +export function setOutput(name, value) { + const outputPath = process.env.GITHUB_OUTPUT; + + if (outputPath) { + const delimiter = `ghadelimiter_${Date.now()}`; + fs.appendFileSync(outputPath, `${name}<<${delimiter}${EOL}${value}${EOL}${delimiter}${EOL}`); + return; + } + + console.log( + `::set-output name=${name}::${String(value).replace(/\n/g, '%0A').replace(/\r/g, '%0D')}` + ); +} \ No newline at end of file