Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import("@actions/github").getOctokit>} Octokit
Expand Down Expand Up @@ -170,6 +170,8 @@ async function run(octokit, context, token) {
`\n\n<a href="https://github.com/preactjs/compressed-size-action"><sub>compressed-size-action${commentKey ? `::${commentKey}` : ''}</sub></a>`
};

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;
Expand Down
20 changes: 20 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import { EOL } from 'os';
import prettyBytes from 'pretty-bytes';

/**
Expand Down Expand Up @@ -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')}`
);
}