visit
It’s easy to using the built-in feature. One line in .gitlab-ci.yml
to rule them all:
test:
coverage: /\d+.\d+ \% covered/
There is a better choice. GitHub provides Pages service, where you can publish a coverage report for example. Technically, you can publish any static set of HTML files placed in a special gh-pages
branch. Looks like an ideal place for storing badges because it will not clog up the history of the main branch.
Take a look at the snippet with URLs below. If you are using a private repository, you will probably want to make the published report on GitHub Pages closed behind authorization as well. In that case, you won't be able to add a badge reference (1)
inside your README. Instead, provide a link to the RAW file in the repository. GitHub will redirect the request (2)
to something like (3)
. The token
parameter is generated for a closed repository for authorization purposes. The token is temporary — after several hours the link will become a 🎃. To avoid such behavior you may add a parameter raw=true
to the file’s link:
//github.com/user/my-project/raw/gh-pages/badges/jacoco.svg?raw=true
//my-project.pages.github.io/badges/coverage.svg (1) GitHub Pages link
//github.com/user/my-project/raw/gh-pages/badges/coverage.svg (2) RAW link
//raw.githubusercontent.com/user/my-project/gh-pages/badges/coverage.svg?token=GHSAT0AAAAAABTVGF2OW2264AQOCSDOKKHGYXPQLUA (3) Permalink to the file in the private repo
gh-pages
branch;raw=true
parameter.
Practice time! I forked repository. This is one of the implementations of the Conduit App (Medium.com clone).
- name: Generate JaCoCo Badge
# if: ${{ github.ref == 'refs/heads/master' }}
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
badges-directory: build/reports/jacoco/test/html/badges
- name: Publish coverage report to GitHub Pages
# if: ${{ github.ref == 'refs/heads/master' }}
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build/reports/jacoco/test/html
We need to set the path to the HTML report. Just a reminder, the generated badge will also be inside this directory. After the commit you’ll need to open the repository Settings → Pages and select the branch you want to publish the site from:
The last piece to add is the link to the badge in README. Don't forget about the raw=true
parameter, so that the picture will be displayed for private repositories as well:
[![Test Coverage](//cdn.gzht888.com/images/2hVuiN1gfbdO9OXUxjCttPNETq73-2022-08-08T22:19:48.257Z-cl6lbgrz6002p0as65v8sfgja)](//drakulavich.github.io/spring-boot-realworld-example-app/)