-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Push coverage (lines %) to a gist, which then backs a https://shields.io badge.
- Loading branch information
Showing
7 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,26 @@ | ||
name: Coverage | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
coverage: | ||
runs-on: ubuntu-latest | ||
environment: Code Coverage Badge | ||
env: | ||
CARGO_TERM_COLOR: always | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install cargo-llvm-cov | ||
uses: taiki-e/install-action@cargo-llvm-cov | ||
- name: Generate code coverage | ||
run: | | ||
percent_coverage="$(cargo llvm-cov --json | jq '.data[].totals.lines.percent')" | ||
printf '::notice title=Coverage (lines %%)::%s' "$percent_coverage" | ||
echo "LINES_PERCENT=$percent_coverage" >> "$GITHUB_ENV" | ||
- name: Upload to gist | ||
run: ./scripts/percent_to_shields_gist coverage "$LINES_PERCENT" | ||
env: | ||
GIST_URL: ${{ vars.GIST_URL }} | ||
GH_TOKEN: ${{ secrets.API_TOKEN }} |
This file contains 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 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,2 @@ | ||
![Code Coverage](https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Fyshavit%2F53901a0115b596e015a891c41fb0f256%2Fraw%2Fmdq-coverage.json) | ||
|
This file contains 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 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,10 @@ | ||
set -euo pipefail | ||
|
||
function msg() { | ||
echo >&2 "$@" | ||
} | ||
|
||
function err() { | ||
msg "$@" | ||
exit 1 | ||
} |
This file contains 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,31 @@ | ||
#!/bin/bash | ||
|
||
source scripts/common.sh || exit 1 | ||
|
||
if [ $# -ne 1 ]; then | ||
err 'require exactly one argument' | ||
fi | ||
percent="$1" | ||
|
||
percent_0_to_5="$(printf 'scale=0; %s / 20\n' "$percent" | bc)" | ||
|
||
case "$percent_0_to_5" in | ||
0) # 0 - 19% | ||
echo darkred | ||
;; | ||
1) # 20 - 39% | ||
echo crimson | ||
;; | ||
2) # 40 - 59% | ||
echo orangered | ||
;; | ||
3) # 60 - 79% | ||
echo yellowgreen | ||
;; | ||
4 | 5) | ||
echo forestgreen | ||
;; | ||
*) | ||
err 'invalid percent' | ||
;; | ||
esac |
This file contains 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,22 @@ | ||
#!/bin/bash | ||
|
||
source scripts/common.sh || exit 1 | ||
|
||
if [ -z "${GIST_URL:-}" ]; then | ||
err "no GIST_URL env set" | ||
fi | ||
if [ $# -ne 2 ]; then | ||
err 'requires exactly two arguments' | ||
fi | ||
label="$1" | ||
percent="$2" | ||
|
||
color="$(scripts/percent_to_color "$percent")" | ||
|
||
json_text="$(echo '{}' | | ||
jq -c '{schemaVersion: 1, label: $badge_label, color: $color, message: $percent}' \ | ||
--arg badge_label "$label" --arg color "$color" --arg percent "$(printf '%.1f%%' "$percent")" )" | ||
|
||
gh gist edit "$GIST_URL" <(echo "$json_text") | ||
|
||
|