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

Make the detailed coverage table in PR comment optional #43

Merged
merged 8 commits into from
May 14, 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
27 changes: 25 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ jobs:
diff-branch: main
diff-storage: _xml_coverage_reports
coverage-summary-title: "Code Coverage Summary (test-branch.xml)"
exclude-detailed-coverage: false
- path: test-missing-lines.xml
threshold: 50
fail: false
publish: true
diff: false
diff-branch: main
diff-storage: _xml_coverage_reports
diff-storage: _xml_coverage_reports_5
coverage-summary-title: "Code Coverage Summary (test-missing-lines.xml)"
exclude-detailed-coverage: false
- path: test-no-branch.xml
threshold: 90
fail: true
Expand All @@ -41,6 +43,7 @@ jobs:
diff-branch: main
diff-storage: _xml_coverage_reports_1
coverage-summary-title: "Code Coverage Summary (test-no-branch.xml)"
exclude-detailed-coverage: false
- path: test-python.xml
threshold: 90
fail: false
Expand All @@ -49,6 +52,25 @@ jobs:
diff-branch: main
diff-storage: _xml_coverage_reports_2
coverage-summary-title: "Code Coverage Summary (test-python.xml)"
exclude-detailed-coverage: false
- path: test-no-branch-2.xml
threshold: 90
fail: true
publish: true
diff: true
diff-branch: main
diff-storage: _xml_coverage_reports_3
coverage-summary-title: "Code Coverage Summary (test-no-branch.xml) without detailed coverage"
exclude-detailed-coverage: true
- path: test-missing-lines-2.xml
threshold: 50
fail: false
publish: true
diff: false
diff-branch: main
diff-storage: _xml_coverage_reports_4
coverage-summary-title: "Code Coverage Summary (test-missing-lines.xml) without detailed coverage"
exclude-detailed-coverage: true
steps:
- name: Checkout Code 🛎
uses: actions/checkout@v4
Expand All @@ -63,4 +85,5 @@ jobs:
diff: ${{ matrix.reports.diff }}
diff-branch: ${{ matrix.reports.diff-branch }}
diff-storage: ${{ matrix.reports.diff-storage }}
coverage-summary-title: ${{ matrix.reports.coverage-summary-title}}
coverage-summary-title: ${{ matrix.reports.coverage-summary-title }}
exclude-detailed-coverage: ${{ matrix.reports.exclude-detailed-coverage }}
50 changes: 29 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
# Code Coverage Report Action

### Description

Action that converts a Cobertura XML report into a markdown report.
### Action Type

Composite

### Author

Insights Engineering
Inisghts Engineering

### Inputs

* `token`:

_Description_: Github token to use to publish the check.
Expand All @@ -31,7 +27,7 @@ Insights Engineering

_Required_: `false`

_Default_: `.`
_Default_: `coverage.xml`

* `threshold`:

Expand All @@ -47,23 +43,23 @@ Insights Engineering

_Required_: `false`

_Default_: `true`
_Default_: `True`

* `publish`:

_Description_: Publish the coverage report as an issue comment.

_Required_: `false`

_Default_: `false`
_Default_: `False`

* `diff`:

_Description_: Create a diff of the coverage report.

_Required_: `false`

_Default_: `false`
_Default_: `False`

* `diff-branch`:

Expand All @@ -73,21 +69,21 @@ Insights Engineering

_Default_: `main`

* `diff-storage`:
* `storage-subdirectory`:

_Description_: Branch where coverage reports are stored for diff purposes.
_Description_: Subdirectory in the diff-storage branch where the XML reports will be stored.

_Required_: `false`

_Default_: `_xml_coverage_reports`
_Default_: `.`

* `storage-subdirectory`:
* `diff-storage`:

_Description_: Subdirectory in the diff-storage branch where the XML reports will be stored.
_Description_: Branch where coverage reports are stored for diff purposes.

_Required_: `false`

_Default_: `.`
_Default_: `_xml_coverage_reports`

* `coverage-summary-title`:

Expand All @@ -103,37 +99,49 @@ Insights Engineering

_Required_: `false`

_Default_: `false`
_Default_: `False`

* `new-uncovered-statements-failure`:

_Description_: Fail the action if any new uncovered statements are introduced compared to the `diff-branch`.

_Required_: `false`

_Default_: `false`
_Default_: `False`

* `pycobertura-exception-failure`:

_Description_: Fail the action in case of a `Pycobertura` exception.

_Required_: `false`

_Default_: `true`
_Default_: `True`

* `togglable-report`:

_Description_: Make the code coverage report togglable.

_Required_: `false`

_Default_: `false`
_Default_: `False`

### Outputs
* `exclude-detailed-coverage`:

_Description_: Whether a detailed coverage report should be excluded from the PR comment.
The detailed coverage report contains the following information per file:
number of code statements, number of statements not covered by any test,
coverage percentage, and line numbers not covered by any test.


_Required_: `false`

_Default_: `False`

### Outputs
* `summary`:

_Description_: A summary of coverage report
_Description_: Summary of coverage report

<!-- END_ACTION_DOC -->

## How it works
Expand Down
35 changes: 25 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ inputs:
description: Make the code coverage report togglable.
required: false
default: false
exclude-detailed-coverage:
description: |
Whether a detailed coverage report should be excluded from the PR comment.
The detailed coverage report contains the following information per file:
number of code statements, number of statements not covered by any test,
coverage percentage, and line numbers not covered by any test.
required: false
default: false

outputs:
summary:
Expand Down Expand Up @@ -240,17 +248,24 @@ runs:
}
fi
echo -e "## ${{ inputs.coverage-summary-title }}\n" >> .coverage-output.final
if [[ "${{ inputs.togglable-report }}" == "true" ]]
if [[ "${{ inputs.exclude-detailed-coverage }}" == "false" ]]
then {
echo -e "<details>\n\n" >> .coverage-output.final
if [[ "${{ inputs.togglable-report }}" == "true" ]]
then {
echo -e "<details>\n\n" >> .coverage-output.final
}
fi
echo -e "\`\`\`" >> .coverage-output.final
cat .coverage-output >> .coverage-output.final
echo -e "\n\`\`\`\n" >> .coverage-output.final
if [[ "${{ inputs.togglable-report }}" == "true" ]]
then {
echo -e "</details>\n\n" >> .coverage-output.final
}
fi
}
fi
echo -e "\`\`\`" >> .coverage-output.final
cat .coverage-output >> .coverage-output.final
echo -e "\n\`\`\`\n" >> .coverage-output.final
if [[ "${{ inputs.togglable-report }}" == "true" ]]
then {
echo -e "</details>\n\n" >> .coverage-output.final
else {
echo -e "\n" >> .coverage-output.final
}
fi
if [[ "${{ inputs.diff }}" == "true" && -f .coverage-output.diff ]]
Expand Down Expand Up @@ -285,7 +300,7 @@ runs:

- name: Set as output
id: create-output
run: |
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "summary<<$EOF" >> $GITHUB_OUTPUT
echo "$(cat .coverage-output.final)" >> $GITHUB_OUTPUT
Expand Down
Loading
Loading