From 4305a5aece22410ce20701949be29c9c887cb111 Mon Sep 17 00:00:00 2001 From: yijhenlin Date: Thu, 11 Apr 2024 12:24:15 +0800 Subject: [PATCH 1/4] Add summary_mode --- README.md | 1 + action.yml | 4 ++++ dist/index.js | 12 ++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8505547..0de1666 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ for [Creating a workflow file](https://help.github.com/en/articles/configuring-a - `fail-emoji` - [*optional* {default: :x:}] Emoji to use for fail status shown when 'coverage < min coverage' (should be a Github supported emoji). - `continue-on-error` - [*optional* {default: true}] If true, then do not fail the action on error, but log a warning - `debug-mode` - [*optional* {default: false}] If true, run the action in debug mode and get debug logs printed in console +- `summary-mode` - [*optional* {default: false}] If true, report the result to workflow summary ### Outputs diff --git a/action.yml b/action.yml index e95f18b..76c1691 100644 --- a/action.yml +++ b/action.yml @@ -42,6 +42,10 @@ inputs: description: 'Run the action in debug mode and get debug logs printed in console' required: false default: 'false' + summary-mode: + description: 'Report to workflow summary' + required: false + default: 'false' outputs: coverage-overall: diff --git a/dist/index.js b/dist/index.js index 90d2a84..8ddfeae 100644 --- a/dist/index.js +++ b/dist/index.js @@ -83,6 +83,7 @@ function action() { const failEmoji = core.getInput('fail-emoji'); continueOnError = (0, processors_1.parseBooleans)(core.getInput('continue-on-error')); const debugMode = (0, processors_1.parseBooleans)(core.getInput('debug-mode')); + const summaryMode = (0, processors_1.parseBooleans)(core.getInput('summary-mode')); const event = github.context.eventName; core.info(`Event is ${event}`); if (debugMode) { @@ -133,10 +134,17 @@ function action() { pass: passEmoji, fail: failEmoji, }; - yield addComment(prNumber, updateComment, (0, render_1.getTitle)(title), (0, render_1.getPRComment)(project, { + const comment = (0, render_1.getPRComment)(project, { overall: minCoverageOverall, changed: minCoverageChangedFiles, - }, title, emoji), client, debugMode); + }, title, emoji); + if (summaryMode) { + core.summary.addRaw(comment); + core.summary.write({overwrite: updateComment}); + } + else { + yield addComment(prNumber, updateComment, (0, render_1.getTitle)(title), comment, client, debugMode); + } } } catch (error) { From 3b73c0e9af8d5130275b2834ff2124dd049f5662 Mon Sep 17 00:00:00 2001 From: yijhenlin Date: Fri, 19 Apr 2024 11:21:48 +0800 Subject: [PATCH 2/4] Token is not necessary for workflow summary --- README.md | 2 +- action.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0de1666..4254d3e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ for [Creating a workflow file](https://help.github.com/en/articles/configuring-a ### Inputs - `paths` - [**required**] Comma separated paths of the generated jacoco xml files (supports wildcard glob pattern) -- `token` - [**required**] Github personal token to add commits to Pull Request +- `token` - [*optional* {default: github.token}] Github personal token to add commits to Pull Request - `min-coverage-overall` - [*optional* {default: 80%}] The minimum code coverage that is required to pass for overall project - `min-coverage-changed-files` - [*optional* {default: 80%}] The minimum code coverage that is required to pass for changed files - `update-comment` - [*optional* {default: false}] If true, updates the previous coverage report comment instead of creating new one. diff --git a/action.yml b/action.yml index 76c1691..1681518 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,8 @@ inputs: required: true token: description: 'Github personal token to add commits to Pull Request' - required: true + required: false + default: ${{ github.token }} min-coverage-overall: description: 'The minimum code coverage that is required to pass for overall project' required: false From ba476fedbbf0e56747ec99223af72e9cf295afb9 Mon Sep 17 00:00:00 2001 From: yijhenlin Date: Thu, 19 Sep 2024 00:04:52 +0800 Subject: [PATCH 3/4] Add summary_mode in action.ts --- src/action.ts | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/action.ts b/src/action.ts index 3d775a8..ffaa76c 100644 --- a/src/action.ts +++ b/src/action.ts @@ -45,6 +45,7 @@ export async function action(): Promise { continueOnError = parseBooleans(core.getInput('continue-on-error')) const debugMode = parseBooleans(core.getInput('debug-mode')) + const summaryMode = parseBooleans(core.getInput('summary-mode')) const event = github.context.eventName core.info(`Event is ${event}`) @@ -106,22 +107,28 @@ export async function action(): Promise { pass: passEmoji, fail: failEmoji, } - await addComment( - prNumber, - updateComment, - getTitle(title), - getPRComment( - project, - { - overall: minCoverageOverall, - changed: minCoverageChangedFiles, - }, - title, - emoji - ), - client, - debugMode - ) + const comment = getPRComment( + project, + { + overall: minCoverageOverall, + changed: minCoverageChangedFiles, + }, + title, + emoji + ) + if (summaryMode) { + await core.summary.addRaw(comment).write({overwrite: updateComment}) + } + else { + await addComment( + prNumber, + updateComment, + getTitle(title), + comment, + client, + debugMode + ) + } } } catch (error) { if (error instanceof Error) { From c954d6058b3f666dc53b068f973371105df81b92 Mon Sep 17 00:00:00 2001 From: thsaravana Date: Wed, 18 Sep 2024 19:49:02 +0200 Subject: [PATCH 4/4] Update description for comment-type field --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c6d9151..62a745d 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,7 @@ inputs: required: false default: 'false' comment-type: - description: 'Specifies where to add the comment: as a PR comment, workflow summary, or both.' + description: 'Specifies where to add the comment, whether as a PR comment, workflow summary, or both.' required: false default: 'pr_comment' options: