-
Notifications
You must be signed in to change notification settings - Fork 8
Code coverage support #49
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8fc53e8
feat: enable code coverage
froozeify 9cccaf4
chore: increase default version
froozeify 9250bfb
feat: Better coverage report with comparaison and config file
froozeify e71cfb2
feat: Better coverage report with comparaison and config file
froozeify 906562a
Code coverage is only run when targeting main branch
froozeify 29135f6
Update after cedric returns
froozeify cf8c318
Rebase conflict
froozeify c7da20f
Update action version
froozeify 7bbb0dd
Rebase conflict
froozeify c00dcc3
PCOV can't be enabled via env var
froozeify File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| name: "Coverage report" | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| plugin-key: | ||
| required: true | ||
| type: string | ||
| workflow-name: | ||
| description: "Name of the CI workflow that produces the coverage artifact." | ||
| required: false | ||
| type: string | ||
| default: "Continuous integration" | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
| actions: read | ||
|
|
||
| jobs: | ||
| coverage-report: | ||
| runs-on: "ubuntu-latest" | ||
| name: "Coverage report" | ||
| if: github.event_name == 'pull_request' | ||
| steps: | ||
| - name: "Check target branch" | ||
| id: "check-branch" | ||
| run: | | ||
| if [[ "${{ github.base_ref }}" != "${{ github.event.repository.default_branch }}" ]]; then | ||
| echo "ℹ️ Code coverage is disabled for pull requests targeting non-default branch (${{ github.base_ref }})." | ||
| echo "skip=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "skip=false" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: "Download coverage report" | ||
| if: steps.check-branch.outputs.skip != 'true' | ||
| uses: "actions/download-artifact@v7" | ||
| with: | ||
| name: "coverage-report" | ||
|
|
||
| - name: "Read coverage configuration" | ||
| id: "coverage-config" | ||
| run: | | ||
| if [[ "${{ steps.check-branch.outputs.skip }}" == "true" ]]; then | ||
| echo "skip=true" >> $GITHUB_OUTPUT | ||
| exit 0 | ||
| fi | ||
|
|
||
| CONFIG_FILE=".glpi-coverage.json" | ||
| if [[ ! -f "$CONFIG_FILE" ]]; then | ||
| echo "⚠️ No $CONFIG_FILE found, skipping coverage report." | ||
| echo "skip=true" >> $GITHUB_OUTPUT | ||
| exit 0 | ||
| fi | ||
|
|
||
| ENABLED=$(jq -r '.enabled // true' "$CONFIG_FILE") | ||
| if [[ "$ENABLED" != "true" ]]; then | ||
| echo "ℹ️ Code coverage is disabled via $CONFIG_FILE" | ||
| echo "skip=true" >> $GITHUB_OUTPUT | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "skip=false" >> $GITHUB_OUTPUT | ||
| echo "only-list-changed-files=$(jq -r '.only_list_changed_files // true' "$CONFIG_FILE")" >> $GITHUB_OUTPUT | ||
| echo "badge=$(jq -r '.badge // true' "$CONFIG_FILE")" >> $GITHUB_OUTPUT | ||
| echo "overall-coverage-fail-threshold=$(jq -r '.overall_coverage_fail_threshold // 0' "$CONFIG_FILE")" >> $GITHUB_OUTPUT | ||
| echo "file-coverage-error-min=$(jq -r '.file_coverage_error_min // 50' "$CONFIG_FILE")" >> $GITHUB_OUTPUT | ||
| echo "file-coverage-warning-max=$(jq -r '.file_coverage_warning_max // 75' "$CONFIG_FILE")" >> $GITHUB_OUTPUT | ||
| echo "fail-on-negative-difference=$(jq -r '.fail_on_negative_difference // false' "$CONFIG_FILE")" >> $GITHUB_OUTPUT | ||
| echo "retention-days=$(jq -r '.retention_days // 90' "$CONFIG_FILE")" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: "Generate coverage report" | ||
| if: steps.coverage-config.outputs.skip != 'true' | ||
| uses: "clearlyip/code-coverage-report-action@v6" | ||
| id: "coverage-report" | ||
| with: | ||
| filename: "cobertura.xml" | ||
| only_list_changed_files: ${{ steps.coverage-config.outputs.only-list-changed-files }} | ||
| badge: ${{ steps.coverage-config.outputs.badge }} | ||
| overall_coverage_fail_threshold: ${{ steps.coverage-config.outputs.overall-coverage-fail-threshold }} | ||
| file_coverage_error_min: ${{ steps.coverage-config.outputs.file-coverage-error-min }} | ||
| file_coverage_warning_max: ${{ steps.coverage-config.outputs.file-coverage-warning-max }} | ||
| fail_on_negative_difference: ${{ steps.coverage-config.outputs.fail-on-negative-difference }} | ||
| retention_days: ${{ steps.coverage-config.outputs.retention-days }} | ||
| artifact_download_workflow_names: "${{ inputs.workflow-name }}" | ||
|
|
||
| - name: "Generating Markdown report" | ||
| if: steps.coverage-config.outputs.skip != 'true' && steps.coverage-report.outputs.file != '' | ||
| run: | | ||
| COVERAGE="${{ steps.coverage-report.outputs.coverage }}" | ||
| REPORT_FILE="code-coverage-results.md" | ||
| ARTIFACT_LINK="📥 [Download coverage-report artifact](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) _(contains \`clover.xml\` for IDE import + config file)_" | ||
|
|
||
| # Split: keep header/badge visible, collapse the table inside <details> | ||
| FIRST_TABLE_LINE=$(grep -n "^|" "$REPORT_FILE" | head -1 | cut -d: -f1) | ||
|
|
||
| if [[ -z "$FIRST_TABLE_LINE" ]]; then | ||
| { | ||
| cat "$REPORT_FILE" | ||
| echo "" | ||
| echo "$ARTIFACT_LINK" | ||
| } > "${REPORT_FILE}.tmp" | ||
| else | ||
| { | ||
| head -n "$((FIRST_TABLE_LINE - 1))" "$REPORT_FILE" | ||
| echo "" | ||
| echo "<details>" | ||
| echo "<summary>📋 Details</summary>" | ||
| echo "" | ||
| tail -n "+${FIRST_TABLE_LINE}" "$REPORT_FILE" | ||
| echo "" | ||
| echo "$ARTIFACT_LINK" | ||
| echo "" | ||
| echo "</details>" | ||
| } > "${REPORT_FILE}.tmp" | ||
| fi | ||
|
|
||
| mv "${REPORT_FILE}.tmp" "$REPORT_FILE" | ||
|
|
||
| - name: "Add coverage PR comment" | ||
| if: steps.coverage-config.outputs.skip != 'true' && steps.coverage-report.outputs.file != '' | ||
| uses: "marocchino/sticky-pull-request-comment@v3" | ||
| with: | ||
| header: coverage | ||
| path: code-coverage-results.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.