Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set report output & skip comment #13

Merged
merged 4 commits into from
Apr 10, 2024
Merged
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
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
matrix:
description: 'Metadata about the current job matrix in JSON.'
default: ''
skip-comment:
description: 'Skip creating a comment. Useful alongside `report` output.'
default: 'false'
slow-threshold:
description: 'Number of seconds before an action is to be considered slow.'
default: 120
Expand All @@ -26,6 +29,8 @@ inputs:
outputs:
comment-created:
description: 'Whether or not the comment was created on the pull request.'
report:
description: 'The generated report.'
runs:
using: 'node20'
main: 'dist/index.js'
Expand Down
24 changes: 15 additions & 9 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async function run() {
try {
const accessToken = core.getInput('access-token');
const limit = Number(core.getInput('limit'));
const skipComment = core.getBooleanInput('skip-comment');
const slowThreshold = Number(core.getInput('slow-threshold'));
const workspaceRoot =
core.getInput('workspace-root') || process.env.GITHUB_WORKSPACE || process.cwd();
Expand Down Expand Up @@ -118,20 +119,25 @@ async function run() {

// Format the report into markdown
const markdown = formatReportToMarkdown(report, { limit, slowThreshold, workspaceRoot });

// Create the comment (does not work in forks)
try {
await saveComment(accessToken, markdown);
} catch (error: unknown) {
core.warning(String(error));
core.notice('\nFailed to create comment on pull request. Perhaps this is ran in a fork?\n');
core.info(markdown);
core.setOutput('report', markdown);

if (skipComment) {
core.debug('Skipping comment creation');
} else {
// Create the comment (does not work in forks)
try {
await saveComment(accessToken, markdown);
} catch (error: unknown) {
core.warning(String(error));
core.notice('\nFailed to create comment on pull request. Perhaps this is ran in a fork?\n');
core.info(markdown);
}
}

// Create an action summary (does work in forks)
await saveSummary(markdown);

core.setOutput('comment-created', 'true');
core.setOutput('comment-created', skipComment ? 'false' : 'true');
} catch (error: unknown) {
core.setOutput('comment-created', 'false');
core.setFailed((error as Error).message);
Expand Down
Loading