GitHub Action
CI Badges
This action generates badges (as JSON files) from Go, JUnit, Cobertura and JaCoCo test and coverage reports and upload them to a Gist to make them available to Shields through the endpoint feature with (almost) zero configuration.
Create a Gist and an access token (with the gist
scope) and store the access
token in your repository secrets.
Add the action to your workflow (after running tests, as reports must be available in the current working directory):
uses: gaelgirodon/ci-badges-action@v1
with:
gist-id: <gist-id>
token: ${{ secrets.GIST_TOKEN }}
Each generated badge JSON file is uploaded to your Gist and is available
via: https://gist.githubusercontent.com/{user}/{gist-id}/raw/{repo}-[{ref}-]{format}-{type}.json
,
e.g. .../myproject-cobertura-coverage.json
.
This URL can be used with Shields Endpoint
to generate the badge SVG image: https://img.shields.io/endpoint?url={url}
.
The usual query parameters (style
, label
, ...) can be used to further
customize the badge.
Name | Required | Default | Description |
---|---|---|---|
gist-id |
✔️ | The unique identifier of the Gist | |
token |
✔️ | GitHub REST API access token (with the gist scope) |
|
prefix |
Repository name | Filenames prefix | |
ref |
false |
Include the short ref name (branch or tag) in filenames |
This action loads reports, extracts key data and generates JSON files following the Shields schema, instead of directly generating SVG images, to allow taking advantage of Shields customization features (through the query string).
This badge displays the number of passed and failed tests extracted from a test report.
{"schemaVersion":1,"label":"tests","message":"3 passed","color":"brightgreen"}
This badge displays the percentage of covered lines extracted from a coverage report.
{"schemaVersion":1,"label":"coverage","message":"96%","color":"brightgreen"}
This action supports multiple report formats with their conventional or most popular configurations.
Only matched report formats will get a file uploaded to the Gist.
Write the verbose test output (>
or tee
) with coverage enabled to a
test*.{out,txt}
file next to the go.mod
file:
RUN
,PASS
andFAIL
flags will be used to count tests- The last percentage will be used as the coverage value
go tool cover -func=cover.out
output may be appended to the above file to make
sure the last percentage is the global coverage value.
➡️ {repo}-[{ref}-]go-tests.json
➡️ {repo}-[{ref}-]go-coverage.json
Write the test report to a file matching:
**/report.xml
**/*TEST*.xml
**/*test*.xml
**/*junit*.xml
The number of tests and failures will be extracted from the <testsuites>
tag.
➡️ {repo}-[{ref}-]junit-tests.json
Write the coverage report to a file matching:
**/*cobertura*.xml
**/*coverage*.xml
The coverage will be extracted from the line-rate
attribute of the
<coverage>
tag.
➡️ {repo}-[{ref}-]cobertura-coverage.json
Write the coverage report to a file matching:
**/*jacoco*.xml
**/*coverage*.xml
The coverage will be extracted from the last <counter>
tag with type LINE
.
➡️ {repo}-[{ref}-]jacoco-coverage.json
CI Badges action is licensed under the GNU General Public License.