Skip to content

Commit

Permalink
tweak: add compared and has-changed outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaromartmart committed Aug 2, 2023
1 parent b2d81f8 commit 6f3bf6d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
comment-author: 'github-actions[bot]'
- name: Create or Update Comment
uses: peter-evans/[email protected]
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request' && steps.coverage.outputs.compared == 'true' && steps.coverage.outputs.has-changed == 'true'
with:
issue-number: ${{ github.event.number }}
body-path: ${{ steps.coverage.outputs.comment-file }}
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ Example: adding a comment to the PR with the summary
id: coverage
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Find Comment
- name: Write comment
# Do it only if there were changes in coverage
if: (steps.coverage.outputs.compared == 'true') && (steps.coverage.outputs.has-changed == 'true')
uses: peter-evans/[email protected]
if: github.event_name == 'pull_request'
with:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ outputs:
description: 'Coverage summary'
comment-file:
description: 'Path to markdown file with the coverage summary'
compared:
description: 'Returns true if the action was able to compare coverage with the base branch'
has-changed:
description: 'Returns true if a comparison with base branch was performed and there are changes in coverage'
runs:
using: 'node16'
main: 'dist/index.js'
2 changes: 2 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/compare-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ function getCoverageComment({ commitId, currentCoverageFile, previousCommitId, p
`| Lines | ? | ${currentCov.Lines}% | ? |\n`
])
].join('\n');
core.setOutput('compared', trends !== null);
core.setOutput('has-changed', (trends === null || trends === void 0 ? void 0 : trends.Branches) || (trends === null || trends === void 0 ? void 0 : trends.Functions) || (trends === null || trends === void 0 ? void 0 : trends.Lines) || (trends === null || trends === void 0 ? void 0 : trends.Statements));
core.debug(message);
return message;
}
Expand Down
6 changes: 6 additions & 0 deletions src/compare-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ export function getCoverageComment({
])
].join('\n')

core.setOutput('compared', trends !== null)
core.setOutput(
'has-changed',
trends?.Branches || trends?.Functions || trends?.Lines || trends?.Statements
)

core.debug(message)
return message
}

0 comments on commit 6f3bf6d

Please sign in to comment.