-
Notifications
You must be signed in to change notification settings - Fork 414
RI-7038: Update Github flow to show code coverage reports to each PR #4555
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
32 commits
Select commit
Hold shift + click to select a range
ba46518
RI-7038: add code coverage summary for FE tests
KrumTy 594e269
temp: trigger code change
KrumTy 5848a65
update workflow
KrumTy 8e304f0
add jest coverage report
KrumTy af70726
update workflows
KrumTy a4828dd
update workflow
KrumTy d46f303
update workflow
KrumTy 300eae3
update workflow file
KrumTy b5a63a1
update workflow
KrumTy e88b8ac
update workflow
KrumTy 9902796
update workflow
KrumTy ce112f9
update workflow
KrumTy 3cc458b
Merge branch 'main' into feature/RI-7038/code-coverage-workflows
KrumTy 901ac4b
update workflow
KrumTy 0ef0260
update workflow
KrumTy 157d06a
update workflows
KrumTy 5a80bdd
update code coverage title
KrumTy 30d728f
remove comment
KrumTy d37c01c
add integration tests code coverage
KrumTy efe6939
fix workflow
KrumTy d2860fd
update integration workflow
KrumTy 8c93fed
update integration workflow
KrumTy 601780f
debug integration workflow
KrumTy 1f8be59
update workflow
KrumTy 591df4a
remove debug section
KrumTy bcc3959
update integration tests coverage markdown
KrumTy 628c354
remove dep install for jest test coverage
KrumTy c941a2a
update integration flow and formatting
KrumTy 5b500e9
refactor workflows
KrumTy a5c83e6
update workflow
KrumTy 532a0a2
revert temp code change
KrumTy c207a2d
RI-7038: apply review suggestions
KrumTy 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,140 @@ | ||
| name: 'Code Coverage' | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| type: | ||
| description: Type of report (unit or integration) | ||
| type: string | ||
| resource_name: | ||
| description: Resource name of coverage report | ||
| type: string | ||
|
|
||
| jobs: | ||
| coverage-unit: | ||
| runs-on: ubuntu-latest | ||
| name: Unit tests coverage | ||
| if: ${{ inputs.type == 'unit' }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Download Coverage Report | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: ${{ inputs.resource_name }} | ||
| path: report | ||
|
|
||
| - uses: jwalton/gh-find-current-pr@v1 | ||
| id: findPr | ||
|
|
||
| - uses: ArtiomTr/jest-coverage-report-action@v2 | ||
| with: | ||
| prnumber: ${{ steps.findPr.outputs.number }} | ||
| coverage-file: report/coverage/report.json | ||
| base-coverage-file: report/coverage/report.json | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| skip-step: all | ||
| custom-title: Code Coverage - ${{ inputs.resource_name == 'report-be' && 'Backend' || 'Frontend' }} unit tests | ||
|
|
||
| coverage-integration: | ||
| runs-on: ubuntu-latest | ||
| name: Integration tests coverage | ||
| if: ${{ inputs.type == 'integration' }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Download Coverage Report | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: ${{ inputs.resource_name }} | ||
|
|
||
| - name: Parse Coverage Summary | ||
| id: parse-coverage | ||
| run: | | ||
| # Extract coverage data from file. | ||
| # Example of processed row: | ||
| # Statements : 81.75% ( 16130/19730 ) | ||
| # field '$3' = 81.75%, field '$5' = 16130 | ||
| extract_coverage_data() { | ||
| local keyword=$1 | ||
| local field=$2 | ||
| awk "/$keyword/ {print $field}" integration-coverage.txt | tr -d '\n|%' | ||
| } | ||
|
|
||
| # Determine status based on percentage | ||
| get_status() { | ||
| if [ "$(echo "$1 < 50" | bc)" -eq 1 ]; then | ||
| echo "🔴" | ||
| elif [ "$(echo "$1 < 80" | bc)" -eq 1 ]; then | ||
| echo "🟡" | ||
| else | ||
| echo "🟢" | ||
| fi | ||
| } | ||
|
|
||
| # Extract coverage data from the summary | ||
| STATEMENTS_PERCENT=$(extract_coverage_data "Statements" '$3') | ||
| STATEMENTS_COVERED=$(extract_coverage_data "Statements" '$5') | ||
| STATEMENTS_STATUS=$(get_status $STATEMENTS_PERCENT) | ||
|
|
||
| BRANCHES_PERCENT=$(extract_coverage_data "Branches" '$3') | ||
| BRANCHES_COVERED=$(extract_coverage_data "Branches" '$5') | ||
| BRANCHES_STATUS=$(get_status $BRANCHES_PERCENT) | ||
|
|
||
| FUNCTIONS_PERCENT=$(extract_coverage_data "Functions" '$3') | ||
| FUNCTIONS_COVERED=$(extract_coverage_data "Functions" '$5') | ||
| FUNCTIONS_STATUS=$(get_status $FUNCTIONS_PERCENT) | ||
|
|
||
| LINES_PERCENT=$(extract_coverage_data "Lines" '$3') | ||
| LINES_COVERED=$(extract_coverage_data "Lines" '$5') | ||
| LINES_STATUS=$(get_status $LINES_PERCENT) | ||
|
|
||
| # Format as a Markdown table | ||
| echo "| Status | Category | Percentage | Covered / Total |" > coverage-table.md | ||
| echo "|-------------|-------------|-------------|-----------------|" >> coverage-table.md | ||
| echo "| $STATEMENTS_STATUS | Statements | ${STATEMENTS_PERCENT}% | ${STATEMENTS_COVERED} |" >> coverage-table.md | ||
| echo "| $BRANCHES_STATUS | Branches | ${BRANCHES_PERCENT}% | ${BRANCHES_COVERED} |" >> coverage-table.md | ||
| echo "| $FUNCTIONS_STATUS | Functions | ${FUNCTIONS_PERCENT}% | ${FUNCTIONS_COVERED} |" >> coverage-table.md | ||
| echo "| $LINES_STATUS | Lines | ${LINES_PERCENT}% | ${LINES_COVERED} |" >> coverage-table.md | ||
|
|
||
| - uses: jwalton/gh-find-current-pr@v1 | ||
| id: findPr | ||
|
|
||
| - name: Post or Update Coverage Summary Comment | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const table = fs.readFileSync('coverage-table.md', 'utf8'); | ||
| const commentBody = `### Code Coverage - Integration Tests\n\n${table}`; | ||
|
|
||
| // Fetch existing comments on the pull request | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: process.env.RR_Number, | ||
| }); | ||
|
|
||
| // Check if a comment with the same header already exists | ||
| const existingComment = comments.find(comment => | ||
| comment.body.startsWith('### Code Coverage - Integration Tests') | ||
| ); | ||
|
|
||
| if (existingComment) { | ||
| // Update the existing comment | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existingComment.id, | ||
| body: commentBody, | ||
| }); | ||
| } else { | ||
| // Create a new comment | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: process.env.RR_Number, | ||
| body: commentBody, | ||
| }); | ||
| } | ||
| env: | ||
| RR_Number: ${{ steps.findPr.outputs.number }} | ||
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
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
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.