Skip to content

Commit

Permalink
Merge pull request #228 from stenjo/227-feattest-coverage-add-coverag…
Browse files Browse the repository at this point in the history
…e-in-pr-and-compare-with-main

feat(test-coverage): add coverage in pr and compare with main
  • Loading branch information
steoj authored Aug 28, 2024
2 parents 681c648 + d25d41e commit 6907cdd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/stryker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ jobs:
shell: /usr/bin/bash -e {0}

- name: Add formatted table to PR comment
uses: GrantBirki/[email protected]
continue-on-error: true
uses: mshick/add-pr-comment@v2
with:
comment-id: ${{ github.event.comment.id }}
edit-mode: replace
file: stryker-report.md
message-path: stryker-report.md
update-only: false
refresh-message-position: true
allow-repeats: false
message-id: 'add-pr-stryker-comment-${{ github.event.pull_request.number }}'

- name: Deploy HTML Report to GitHub Pages
env:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
# unit tests
units:
runs-on: ubuntu-latest
env:
covGistPrefix: 'https://gist.githubusercontent.com/stenjo/9ce1ad7d8e9db99796e782b244eefa4a/raw/f52cd85b82dd774ba0ce9d052f7ff2be505ea2d0'

steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -48,6 +51,7 @@ jobs:
echo "Coverage Percentage - ${{ steps.coverageComment.outputs.coverage }}"
echo "Coverage Color - ${{ steps.coverageComment.outputs.color }}"
echo "Summary HTML - ${{ steps.coverageComment.outputs.summaryHtml }}"
mv coverage/coverage-summary.json .
- name: Create the Badge
uses: schneegans/[email protected]
Expand All @@ -61,6 +65,37 @@ jobs:
color: ${{ steps.coverageComment.outputs.color }}
namedLogo: jest

- name: Gist Sync File
uses: danielmcconville/[email protected]
if: steps.branch-name.outputs.current_branch == 'main'
with:
gistPat: ${{ secrets.GIST_AUTH_TOKEN }}
action: update
filename: coverage-summary.json
gistId: 9ce1ad7d8e9db99796e782b244eefa4a

- name: Get coverage Gist
if: steps.branch-name.outputs.current_branch != 'main'
run: |
curl -o main-coverage.json ${{ env.covGistPrefix }}/coverage-summary.json
function diff { diff="$(echo "$2" - "$1" | bc -l | sed -e 's/^\./0./' -e 's/^-\./-0./')"; echo "$diff"; }
current=$(jq .total.lines.pct coverage-summary.json)
main=$(jq .total.lines.pct main-coverage.json)
pctLineChange=$(diff "$main" "$current")
echo '**Code Coverage change**' > coverage.md
echo 'This PR changes coverage by' "$pctLineChange" '%' >> coverage.md
echo 'Component coverage will change from ' "$main"'% to ' "$current"'%.' >> coverage.md
echo "$(<coverage.md)"
- name: Add PR Comment with coverage diff
uses: mshick/add-pr-comment@v2
with:
message-path: coverage.md
update-only: false
refresh-message-position: true
allow-repeats: false
message-id: 'add-pr-diff-comment-${{ github.event.pull_request.number }}'

# test action works running from the graph
test:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ __tests__/runner/*
# stryker temp files
.stryker-tmp
reports/**
out/index.js
reports/**
**/.DS_Store
**/.stryker-tmp
2 changes: 1 addition & 1 deletion script/generate_md_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def count_mutation_statuses(report: dict) -> dict:
def generate_markdown_report(status_counts: dict, url: str) -> str:
"""Generate a Markdown report summarizing
mutation status counts per file."""
markdown = "# Stryker report for changed files\n\n"
markdown = "# Stryker report\n\n"
markdown += "| File | % score | # killed \
| # timeout | # survived | # no cov | # errors |\n"
markdown += "|-----------------------|---------|----------\
Expand Down

0 comments on commit 6907cdd

Please sign in to comment.