-
Notifications
You must be signed in to change notification settings - Fork 32
FEAT: Forked PR coverage comment workflow #375
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
+270
−70
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cdb94b2
testing code coverage failure
gargsaumya b2a1ac6
testing
gargsaumya 7e50a98
testing
gargsaumya 50023f7
addressed review comments
gargsaumya ad54413
adding std action for posting cov comment
gargsaumya 6aaf839
cleanup
gargsaumya 2f4efea
same main.py
gargsaumya 7b26fbd
Merge branch 'main' into saumya/code-cov-test
gargsaumya 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
|
||
| <table> | ||
| <tr> | ||
| <td align="center" width="200"> | ||
|
|
||
| ### 🔥 Diff Coverage | ||
| ### **${{ inputs.patch_coverage_pct }}** | ||
| <br> | ||
| </td> | ||
| <td align="center" width="200"> | ||
|
|
||
| ### 🎯 Overall Coverage | ||
| ### **${{ inputs.coverage_percentage }}** | ||
| <br> | ||
| </td> | ||
| <td> | ||
|
|
||
| **📈 Total Lines Covered:** `${{ inputs.covered_lines }}` out of `${{ inputs.total_lines }}` | ||
| **📁 Project:** `mssql-python` | ||
|
|
||
| </td> | ||
| </tr> | ||
| </table> | ||
|
|
||
| --- | ||
|
|
||
| ${{ inputs.patch_coverage_summary }} | ||
|
|
||
| --- | ||
| ### 📋 Files Needing Attention | ||
|
|
||
| <details> | ||
| <summary>📉 <strong>Files with overall lowest coverage</strong> (click to expand)</summary> | ||
| <br> | ||
|
|
||
| ```diff | ||
| ${{ inputs.low_coverage_files }} | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| --- | ||
| ### 🔗 Quick Links | ||
|
|
||
| <table> | ||
| <tr> | ||
| <td align="left" width="200"> | ||
| <b>⚙️ Build Summary</b> | ||
| </td> | ||
| <td align="left"> | ||
| <b>📋 Coverage Details</b> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td align="left" width="200"> | ||
|
|
||
| [View Azure DevOps Build](${{ inputs.ado_url }}) | ||
|
|
||
| </td> | ||
| <td align="left"> | ||
|
|
||
| [Browse Full Coverage Report](${{ inputs.ado_url }}&view=codecoverage-tab) | ||
|
|
||
| </td> | ||
| </tr> | ||
| </table> |
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,111 @@ | ||
| name: Post Coverage Comment | ||
|
|
||
| # This workflow handles posting coverage comments for FORKED PRs. | ||
| # | ||
| # Why a separate workflow? | ||
| # - Forked PRs have restricted GITHUB_TOKEN permissions for security | ||
| # - They cannot write comments directly to the base repository's PRs | ||
| # - workflow_run triggers run in the BASE repository context with full permissions | ||
| # - This allows us to safely post comments on forked PRs | ||
| # | ||
| # How it works: | ||
| # 1. PR Code Coverage workflow uploads coverage data as an artifact (forked PRs only) | ||
| # 2. This workflow triggers when PR Code Coverage completes successfully | ||
| # 3. Downloads the artifact and posts the comment with full write permissions | ||
| # | ||
| # Same-repo PRs post comments directly in pr-code-coverage.yml (faster) | ||
| # Forked PRs use this workflow (required for permissions) | ||
|
|
||
| on: | ||
| workflow_run: | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| workflows: ["PR Code Coverage"] | ||
| types: | ||
| - completed | ||
|
|
||
| jobs: | ||
| post-comment: | ||
| runs-on: ubuntu-latest | ||
| if: > | ||
| github.event.workflow_run.event == 'pull_request' && | ||
| github.event.workflow_run.conclusion == 'success' | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| permissions: | ||
| pull-requests: write | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Download coverage data | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| # Download artifact with error handling for non-existent artifacts | ||
| if ! gh run download ${{ github.event.workflow_run.id }} \ | ||
| --repo ${{ github.repository }} \ | ||
| --name coverage-comment-data 2>&1; then | ||
| echo "⚠️ No coverage-comment-data artifact found" | ||
| echo "This is expected for same-repo PRs (they post comments directly)" | ||
| echo "Exiting gracefully..." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Verify artifact was downloaded | ||
| if [[ ! -f pr-info.json ]]; then | ||
| echo "⚠️ Artifact downloaded but pr-info.json not found" | ||
| echo "This may indicate an issue with artifact upload" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Read coverage data | ||
| id: coverage | ||
| run: | | ||
| if [[ ! -f pr-info.json ]]; then | ||
| echo "❌ pr-info.json not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| cat pr-info.json | ||
|
|
||
| # Extract values from JSON with proper quoting | ||
| PR_NUMBER="$(jq -r '.pr_number' pr-info.json)" | ||
| COVERAGE_PCT="$(jq -r '.coverage_percentage' pr-info.json)" | ||
| COVERED_LINES="$(jq -r '.covered_lines' pr-info.json)" | ||
| TOTAL_LINES="$(jq -r '.total_lines' pr-info.json)" | ||
| PATCH_PCT="$(jq -r '.patch_coverage_pct' pr-info.json)" | ||
| LOW_COV_FILES="$(jq -r '.low_coverage_files' pr-info.json)" | ||
| PATCH_SUMMARY="$(jq -r '.patch_coverage_summary' pr-info.json)" | ||
| ADO_URL="$(jq -r '.ado_url' pr-info.json)" | ||
|
|
||
| # Export to env for next step (single-line values) | ||
| echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV | ||
| echo "COVERAGE_PERCENTAGE=${COVERAGE_PCT}" >> $GITHUB_ENV | ||
| echo "COVERED_LINES=${COVERED_LINES}" >> $GITHUB_ENV | ||
| echo "TOTAL_LINES=${TOTAL_LINES}" >> $GITHUB_ENV | ||
| echo "PATCH_COVERAGE_PCT=${PATCH_PCT}" >> $GITHUB_ENV | ||
| echo "ADO_URL=${ADO_URL}" >> $GITHUB_ENV | ||
|
|
||
| # Handle multiline values with proper quoting | ||
| { | ||
| echo "LOW_COVERAGE_FILES<<EOF" | ||
| echo "$LOW_COV_FILES" | ||
| echo "EOF" | ||
| } >> $GITHUB_ENV | ||
|
|
||
| { | ||
| echo "PATCH_COVERAGE_SUMMARY<<EOF" | ||
| echo "$PATCH_SUMMARY" | ||
| echo "EOF" | ||
| } >> $GITHUB_ENV | ||
|
|
||
| - name: Comment coverage summary on PR | ||
| uses: ./.github/actions/post-coverage-comment | ||
| with: | ||
| pr_number: ${{ env.PR_NUMBER }} | ||
| coverage_percentage: ${{ env.COVERAGE_PERCENTAGE }} | ||
| covered_lines: ${{ env.COVERED_LINES }} | ||
| total_lines: ${{ env.TOTAL_LINES }} | ||
| patch_coverage_pct: ${{ env.PATCH_COVERAGE_PCT }} | ||
| low_coverage_files: ${{ env.LOW_COVERAGE_FILES }} | ||
| patch_coverage_summary: ${{ env.PATCH_COVERAGE_SUMMARY }} | ||
| ado_url: ${{ env.ADO_URL }} | ||
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
Oops, something went wrong.
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.