diff --git a/.github/actions/post-coverage-comment/action.yml b/.github/actions/post-coverage-comment/action.yml new file mode 100644 index 00000000..0f3a862a --- /dev/null +++ b/.github/actions/post-coverage-comment/action.yml @@ -0,0 +1,105 @@ +name: Post Coverage Comment +description: Posts a standardized code coverage comment on a pull request + +inputs: + pr_number: + description: 'Pull request number' + required: true + coverage_percentage: + description: 'Overall coverage percentage' + required: true + covered_lines: + description: 'Number of covered lines' + required: true + total_lines: + description: 'Total number of lines' + required: true + patch_coverage_pct: + description: 'Patch/diff coverage percentage' + required: true + low_coverage_files: + description: 'Files with lowest coverage (multiline)' + required: true + patch_coverage_summary: + description: 'Patch coverage summary markdown (multiline)' + required: true + ado_url: + description: 'Azure DevOps build URL' + required: true + +runs: + using: composite + steps: + - name: Post coverage comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: Code Coverage Report + number: ${{ inputs.pr_number }} + message: | + # 📊 Code Coverage Report + +
|
+
+ ### 🔥 Diff Coverage
+ ### **${{ inputs.patch_coverage_pct }}**
+ + |
+
+
+ ### 🎯 Overall Coverage
+ ### **${{ inputs.coverage_percentage }}**
+ + |
+ + + **📈 Total Lines Covered:** `${{ inputs.covered_lines }}` out of `${{ inputs.total_lines }}` + **📁 Project:** `mssql-python` + + | +
| + ⚙️ Build Summary + | ++ 📋 Coverage Details + | +
| + + [View Azure DevOps Build](${{ inputs.ado_url }}) + + | ++ + [Browse Full Coverage Report](${{ inputs.ado_url }}&view=codecoverage-tab) + + | +
|
-
- ### 🔥 Diff Coverage
- ### **${{ env.PATCH_COVERAGE_PCT }}**
- - |
-
-
- ### 🎯 Overall Coverage
- ### **${{ env.COVERAGE_PERCENTAGE }}**
- - |
- - - **📈 Total Lines Covered:** `${{ env.COVERED_LINES }}` out of `${{ env.TOTAL_LINES }}` - **📁 Project:** `mssql-python` - - | -
| - ⚙️ Build Summary - | -- 📋 Coverage Details - | -
| - - [View Azure DevOps Build](${{ env.ADO_URL }}) - - | -+ - name: Save coverage data for comment + run: | + mkdir -p coverage-comment-data + jq -n \ + --arg pr_number "${{ github.event.pull_request.number }}" \ + --arg coverage_percentage "${{ env.COVERAGE_PERCENTAGE }}" \ + --arg covered_lines "${{ env.COVERED_LINES }}" \ + --arg total_lines "${{ env.TOTAL_LINES }}" \ + --arg patch_coverage_pct "${{ env.PATCH_COVERAGE_PCT }}" \ + --arg low_coverage_files "${{ env.LOW_COVERAGE_FILES }}" \ + --arg patch_coverage_summary "${{ env.PATCH_COVERAGE_SUMMARY }}" \ + --arg ado_url "${{ env.ADO_URL }}" \ + '{ + pr_number: $pr_number, + coverage_percentage: $coverage_percentage, + covered_lines: $covered_lines, + total_lines: $total_lines, + patch_coverage_pct: $patch_coverage_pct, + low_coverage_files: $low_coverage_files, + patch_coverage_summary: $patch_coverage_summary, + ado_url: $ado_url + }' > coverage-comment-data/pr-info.json + + # Validate JSON before uploading + echo "Validating generated JSON..." + jq . coverage-comment-data/pr-info.json > /dev/null || { + echo "❌ Invalid JSON generated" + cat coverage-comment-data/pr-info.json + exit 1 + } + echo "✅ JSON validation successful" + cat coverage-comment-data/pr-info.json - [Browse Full Coverage Report](${{ env.ADO_URL }}&view=codecoverage-tab) + - name: Upload coverage comment data + # Only upload artifact for forked PRs since same-repo PRs post comment directly + # This prevents unnecessary workflow_run triggers for same-repo PRs + if: github.event.pull_request.head.repo.full_name != github.repository + uses: actions/upload-artifact@v4 + with: + name: coverage-comment-data + path: coverage-comment-data/ + retention-days: 7 - | -