add job to count pending TODOs #21
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
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.COVERAGE_GIST_URL }} | |
GH_TOKEN: ${{ secrets.API_TOKEN }} | |
- name: Count TODOs | |
run: | | |
set -euo pipefail | |
todos_count="$( | |
git ls-tree -r --name-only HEAD | | |
grep --fixed-string -v .github/workflows/coverage.yml | | |
grep --fixed-string -v README.md | | |
(xargs grep todo -i -o || true) | | |
wc -l | |
)" | |
if [ "$todos_count" -eq 0 ]; then | |
color=green | |
else | |
color=orange | |
fi | |
json_text="$(echo '{}' | | |
jq -c '{schemaVersion: 1, label: $badge_label, color: $color, message: $message}' \ | |
--arg badge_label "☑ Pending TODOs" --arg color "$color" --arg message "$todos_count")" | |
percent_coverage="$(cargo llvm-cov --json | jq '.data[].totals.lines.percent')" | |
printf '::notice title=TODOs Count::%s' "$todos_count" | |
gh gist edit "$GIST_URL" <(echo "$json_text") | |
env: | |
GIST_URL: ${{ vars.TODOS_GIST_URL }} | |
GH_TOKEN: ${{ secrets.API_TOKEN }} | |