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

Add skip-comment flag and input as well as coverage_report output #37

Merged
merged 6 commits into from
Jul 25, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/
.github/outputs/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- Fix issue with code coverage information missing when test files are deleted (fgrosse/go-coverage-report#35)
- Document permissions needed to use this action (fgrosse/go-coverage-report#32)
- Add new `skip-comment` input to skip adding a comment to the PR (fgrosse/go-coverage-report#34)

## [v1.0.2] - 2024-06-11
- Fix issue when coverage artifact contains more files than just the `coverage.txt` file (fgrosse/go-coverage-report#25)
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,22 @@ inputs:
default: "github.com/${{ github.repository }}"

trim:
description: Trim a prefix in the "Impacted Packages" column of the markdown report.
description: 'Trim a prefix in the "Impacted Packages" column of the markdown report.'
required: false

skip-comment:
description: |
Skip creating or updating the pull request comment. This may be useful when you want
to generate the coverage report and modify it in your own scripts.
required: false
default: 'false'
```

### Outputs

This action does not provide any outputs, but it will comment on your pull request
with the summary of the code coverage changes.
This action provides the following outputs:

- `coverage_report`: The generated coverage report in Markdown format.

## Limitations

Expand Down
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ inputs:
required: false
default: "github.com/${{ github.repository }}"

skip-comment:
description: |
Skip creating or updating the pull request comment. This may be useful when you want
to generate the coverage report and modify it in your own scripts.
required: false
default: 'false'

trim:
description: Trim a prefix in the "Impacted Packages" column of the markdown report.
required: false

outputs:
coverage_report:
description: 'The generated coverage report in Markdown format.'
value: ${{ steps.coverage.outputs.coverage_report }}

runs:
using: "composite"

Expand All @@ -64,6 +76,7 @@ runs:

- name: Code coverage report
shell: bash
id: coverage
run: $GITHUB_ACTION_PATH/scripts/github-action.sh "${{ github.repository }}" "${{ github.event.pull_request.number }}" "${{ github.run_id }}"
env:
GH_REPO: ${{ github.repository }}
Expand All @@ -74,4 +87,5 @@ runs:
COVERAGE_ARTIFACT_NAME: ${{ inputs.coverage-artifact-name }}
COVERAGE_FILE_NAME: ${{ inputs.coverage-file-name }}
ROOT_PACKAGE: ${{ inputs.root-package }}
SKIP_COMMENT: ${{ inputs.skip-comment }}
TRIM_PACKAGE: ${{ inputs.trim }}
25 changes: 23 additions & 2 deletions scripts/github-action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ You can use the following environment variables to configure the script:
- CHANGED_FILES_PATH: The path to the file containing the list of changed files (default: .github/outputs/all_modified_files.json)
- ROOT_PACKAGE: The import path of the tested repository to add as a prefix to all paths of the changed files (optional)
- TRIM_PACKAGE: Trim a prefix in the \"Impacted Packages\" column of the markdown report (optional)
- SKIP_COMMENT: Skip creating or updating the pull request comment (default: false)
"

if [[ $# != 3 ]]; then
Expand All @@ -42,7 +43,6 @@ fi
GITHUB_REPOSITORY=$1
GITHUB_PULL_REQUEST_NUMBER=$2
GITHUB_RUN_ID=$3

GITHUB_WORKFLOW=${GITHUB_WORKFLOW:-CI}
TARGET_BRANCH=${GITHUB_BASE_REF:-main}
COVERAGE_ARTIFACT_NAME=${COVERAGE_ARTIFACT_NAME:-code-coverage}
Expand All @@ -52,6 +52,7 @@ OLD_COVERAGE_PATH=.github/outputs/old-coverage.txt
NEW_COVERAGE_PATH=.github/outputs/new-coverage.txt
COVERAGE_COMMENT_PATH=.github/outputs/coverage-comment.md
CHANGED_FILES_PATH=${CHANGED_FILES_PATH:-.github/outputs/all_modified_files.json}
SKIP_COMMENT=${SKIP_COMMENT:-false}

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

if [[ -z ${GITHUB_OUTPUT+x} ]]; then
echo "Missing GITHUB_OUTPUT environment variable"
exit 1
fi

export GH_REPO="$GITHUB_REPOSITORY"

start_group(){
echo "::group::$*"
{ set -x; return; } 2>/dev/null
Expand Down Expand Up @@ -107,7 +115,20 @@ go-coverage-report \
end_group

if [ ! -s $COVERAGE_COMMENT_PATH ]; then
echo "::notice::No coverage report to comment"
echo "::notice::No coverage report to output"
exit 0
fi

# Output the coverage report as a multiline GitHub output parameter
echo "Writing GitHub output parameter to \"$GITHUB_OUTPUT\""
{
echo "coverage_report<<END_OF_COVERAGE_REPORT"
cat "$COVERAGE_COMMENT_PATH"
echo "END_OF_COVERAGE_REPORT"
} >> "$GITHUB_OUTPUT"

if [ "$SKIP_COMMENT" = "true" ]; then
echo "Skipping pull request comment (\$SKIP_COMMENT=true))"
exit 0
fi

Expand Down
Loading