ci: fix coverage parsing and JSON payload construction
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Cinco Euzebio 2026-02-28 21:34:01 -03:00
parent 801a2c08fb
commit 41523ce6a1

View File

@ -23,9 +23,8 @@ steps:
from_secret: gitea_token from_secret: gitea_token
commands: commands:
- apt-get update -qq && apt-get install -y -qq jq curl - apt-get update -qq && apt-get install -y -qq jq curl
- cargo tarpaulin --out Json 2>/dev/null
- | - |
PCT=$(jq '(.covered / .coverable * 100) | floor' tarpaulin-report.json) PCT=$(cargo tarpaulin 2>&1 | grep -oE '[0-9]+\.[0-9]+% coverage' | cut -d'.' -f1)
if [ "$PCT" -ge 80 ]; then COLOR="brightgreen" if [ "$PCT" -ge 80 ]; then COLOR="brightgreen"
elif [ "$PCT" -ge 60 ]; then COLOR="yellow" elif [ "$PCT" -ge 60 ]; then COLOR="yellow"
else COLOR="red"; fi else COLOR="red"; fi
@ -37,9 +36,13 @@ steps:
| jq -r '.sha // empty') | jq -r '.sha // empty')
CONTENT=$(base64 -w 0 coverage.svg) CONTENT=$(base64 -w 0 coverage.svg)
if [ -n "$SHA" ]; then if [ -n "$SHA" ]; then
PAYLOAD="{\"message\":\"ci: update coverage badge [CI SKIP]\",\"content\":\"$CONTENT\",\"sha\":\"$SHA\",\"branch\":\"master\"}" PAYLOAD=$(jq -n --arg msg "ci: update coverage badge [CI SKIP]" \
--arg content "$CONTENT" --arg sha "$SHA" --arg branch "master" \
'{message: $msg, content: $content, sha: $sha, branch: $branch}')
else else
PAYLOAD="{\"message\":\"ci: add coverage badge [CI SKIP]\",\"content\":\"$CONTENT\",\"branch\":\"master\"}" PAYLOAD=$(jq -n --arg msg "ci: add coverage badge [CI SKIP]" \
--arg content "$CONTENT" --arg branch "master" \
'{message: $msg, content: $content, branch: $branch}')
fi fi
curl -fsSL -X PUT \ curl -fsSL -X PUT \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \