-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Generate code coverage badge #350
Comments
Hello @cristianrgreco 👋, Thank you for the feature request! I was considering something similar, and have some thoughts on this:
Generating just a badge URL is simple, but it still needs an algorithm on how to inject this URL into the README file. Currently, I don't know how to correctly do this, perhaps some other action could modify the README file? |
Thanks for the quick response @ArtiomTr! I didn't understand this:
This article shows for example how a unique badge could be created for master/PRs. This action could for example create the badge in the user's gist and output the link to it. I'm imagining multiple runs against the master branch would update the same code coverage bade, so that users could link to it in their READMEs
Ah, you are one step ahead of me, I was thinking simply that this action could output the link. |
For reference, there's also https://github.com/MishaKav/jest-coverage-comment. It uses the gist approach, but only on commits to main, because of if: github.ref == 'refs/heads/main' Here's a sample from my workflow: - name: Jest Coverage Comment
id: coverageComment
uses: MishaKav/jest-coverage-comment@main
with:
# hide-comment: true
coverage-summary-path: ./coverage/coverage-summary.json
- name: Check the output coverage
run: |
echo "Coverage Percentage - ${{ steps.coverageComment.outputs.coverage }}"
echo "Coverage Color - ${{ steps.coverageComment.outputs.color }}"
echo "Summary HTML - ${{ steps.coverageComment.outputs.summaryHtml }}"
- name: Create the badge
if: github.ref == 'refs/heads/main'
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GH_TOKEN_GISTS }}
gistID: 26d0f88b04b6883e1a6bba5b9b344fab
filename: jest-coverage-comment__main.json
label: Coverage
message: ${{ steps.coverageComment.outputs.coverage }}%
color: ${{ steps.coverageComment.outputs.color }}
namedLogo: javascript The initial gist, token/secret and badge link in README have to be set up manually, i.e.
and of course https://gist.github.com/gadicc/26d0f88b04b6883e1a6bba5b9b344fab contains: {"schemaVersion":1,"label":"Coverage","message":"65%","color":"yellow","namedLogo":"javascript"} Hope this helps! |
Idea
Similar to https://dev.to/thejaredwilcurt/coverage-badge-with-github-actions-finally-59fa and https://nedbatchelder.com/blog/202209/making_a_coverage_badge.html, it would be awesome if this action could create/update a code coverage badge, that could be embedded into the README.
Description
This library requires the jest coverage to be in a JSON file, and it is not easy to pull out an overall % number to manually create a badge with. Because this library already calculates everything from the coverage map, it could make creating a badge easy.
Perhaps the gist URL and colour thresholds and other such variables could be inputs to the action.
Alternatives
I've tried implementing the solutions from the 2 websites above, but it's tricky to get the coverage numbers from jest when the output is in JSON.
Additional context
The text was updated successfully, but these errors were encountered: