Skip to content

Commit 94f0113

Browse files
jshufrofgrosse
andauthored
Add skip-comment input (#37)
Co-authored-by: Friedrich Große <friedrich.grosse@gmail.com>
1 parent 89095d9 commit 94f0113

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dist/
2+
.github/outputs/

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
- Fix issue with code coverage information missing when test files are deleted (fgrosse/go-coverage-report#35)
99
- Document permissions needed to use this action (fgrosse/go-coverage-report#32)
10+
- Add new `skip-comment` input to skip adding a comment to the PR (fgrosse/go-coverage-report#34)
1011

1112
## [v1.0.2] - 2024-06-11
1213
- Fix issue when coverage artifact contains more files than just the `coverage.txt` file (fgrosse/go-coverage-report#25)

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,22 @@ inputs:
142142
default: "github.com/${{ github.repository }}"
143143

144144
trim:
145-
description: Trim a prefix in the "Impacted Packages" column of the markdown report.
145+
description: 'Trim a prefix in the "Impacted Packages" column of the markdown report.'
146146
required: false
147+
148+
skip-comment:
149+
description: |
150+
Skip creating or updating the pull request comment. This may be useful when you want
151+
to generate the coverage report and modify it in your own scripts.
152+
required: false
153+
default: 'false'
147154
```
148155
149156
### Outputs
150157
151-
This action does not provide any outputs, but it will comment on your pull request
152-
with the summary of the code coverage changes.
158+
This action provides the following outputs:
159+
160+
- `coverage_report`: The generated coverage report in Markdown format.
153161

154162
## Limitations
155163

action.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ inputs:
3535
required: false
3636
default: "github.com/${{ github.repository }}"
3737

38+
skip-comment:
39+
description: |
40+
Skip creating or updating the pull request comment. This may be useful when you want
41+
to generate the coverage report and modify it in your own scripts.
42+
required: false
43+
default: 'false'
44+
3845
trim:
3946
description: Trim a prefix in the "Impacted Packages" column of the markdown report.
4047
required: false
4148

49+
outputs:
50+
coverage_report:
51+
description: 'The generated coverage report in Markdown format.'
52+
value: ${{ steps.coverage.outputs.coverage_report }}
53+
4254
runs:
4355
using: "composite"
4456

@@ -64,6 +76,7 @@ runs:
6476
6577
- name: Code coverage report
6678
shell: bash
79+
id: coverage
6780
run: $GITHUB_ACTION_PATH/scripts/github-action.sh "${{ github.repository }}" "${{ github.event.pull_request.number }}" "${{ github.run_id }}"
6881
env:
6982
GH_REPO: ${{ github.repository }}
@@ -74,4 +87,5 @@ runs:
7487
COVERAGE_ARTIFACT_NAME: ${{ inputs.coverage-artifact-name }}
7588
COVERAGE_FILE_NAME: ${{ inputs.coverage-file-name }}
7689
ROOT_PACKAGE: ${{ inputs.root-package }}
90+
SKIP_COMMENT: ${{ inputs.skip-comment }}
7791
TRIM_PACKAGE: ${{ inputs.trim }}

scripts/github-action.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ You can use the following environment variables to configure the script:
3131
- CHANGED_FILES_PATH: The path to the file containing the list of changed files (default: .github/outputs/all_modified_files.json)
3232
- ROOT_PACKAGE: The import path of the tested repository to add as a prefix to all paths of the changed files (optional)
3333
- TRIM_PACKAGE: Trim a prefix in the \"Impacted Packages\" column of the markdown report (optional)
34+
- SKIP_COMMENT: Skip creating or updating the pull request comment (default: false)
3435
"
3536

3637
if [[ $# != 3 ]]; then
@@ -42,7 +43,6 @@ fi
4243
GITHUB_REPOSITORY=$1
4344
GITHUB_PULL_REQUEST_NUMBER=$2
4445
GITHUB_RUN_ID=$3
45-
4646
GITHUB_WORKFLOW=${GITHUB_WORKFLOW:-CI}
4747
TARGET_BRANCH=${GITHUB_BASE_REF:-main}
4848
COVERAGE_ARTIFACT_NAME=${COVERAGE_ARTIFACT_NAME:-code-coverage}
@@ -52,6 +52,7 @@ OLD_COVERAGE_PATH=.github/outputs/old-coverage.txt
5252
NEW_COVERAGE_PATH=.github/outputs/new-coverage.txt
5353
COVERAGE_COMMENT_PATH=.github/outputs/coverage-comment.md
5454
CHANGED_FILES_PATH=${CHANGED_FILES_PATH:-.github/outputs/all_modified_files.json}
55+
SKIP_COMMENT=${SKIP_COMMENT:-false}
5556

5657
if [[ -z ${GITHUB_REPOSITORY+x} ]]; then
5758
echo "Missing github_repository argument"
@@ -68,6 +69,13 @@ if [[ -z ${GITHUB_RUN_ID+x} ]]; then
6869
exit 1
6970
fi
7071

72+
if [[ -z ${GITHUB_OUTPUT+x} ]]; then
73+
echo "Missing GITHUB_OUTPUT environment variable"
74+
exit 1
75+
fi
76+
77+
export GH_REPO="$GITHUB_REPOSITORY"
78+
7179
start_group(){
7280
echo "::group::$*"
7381
{ set -x; return; } 2>/dev/null
@@ -107,7 +115,20 @@ go-coverage-report \
107115
end_group
108116

109117
if [ ! -s $COVERAGE_COMMENT_PATH ]; then
110-
echo "::notice::No coverage report to comment"
118+
echo "::notice::No coverage report to output"
119+
exit 0
120+
fi
121+
122+
# Output the coverage report as a multiline GitHub output parameter
123+
echo "Writing GitHub output parameter to \"$GITHUB_OUTPUT\""
124+
{
125+
echo "coverage_report<<END_OF_COVERAGE_REPORT"
126+
cat "$COVERAGE_COMMENT_PATH"
127+
echo "END_OF_COVERAGE_REPORT"
128+
} >> "$GITHUB_OUTPUT"
129+
130+
if [ "$SKIP_COMMENT" = "true" ]; then
131+
echo "Skipping pull request comment (\$SKIP_COMMENT=true))"
111132
exit 0
112133
fi
113134

0 commit comments

Comments
 (0)