improve unit test coverage (#55) #80
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 workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# | |
# See https://github.com/r-lib/actions/tree/master/examples#readme for | |
# additional example workflows available for the R community. | |
name: Check Code Coverage | |
on: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: write | |
jobs: | |
coverage: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
r-version: ['release'] | |
steps: | |
- name: Set up R ${{ matrix.r-version }} | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: ${{ matrix.r-version }} | |
use-public-rspm: true | |
- uses: actions/checkout@v3 | |
- name: Install system dependencies | |
run: | | |
sudo apt-get update -y | |
sudo apt-get install -y libcurl4-openssl-dev libssl-dev libxml2-dev | |
- name: Install dependencies | |
run: | | |
install.packages(c("covr","devtools")) | |
shell: Rscript {0} | |
- name: Get percent coverage | |
run: | | |
message('${{ github.workspace }}') | |
x <- covr::package_coverage('${{ github.workspace }}', quiet=FALSE) | |
p <- round(covr::percent_coverage(x)) | |
cat(p, file = "coverage.txt", sep = "") | |
shell: Rscript {0} | |
- name: Upload percent coverage | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage | |
path: coverage.txt | |
- name: Generate percent coverage badge | |
run: | | |
cat coverage.txt | |
COVERAGE=$(cat coverage.txt) | |
lt_50=$(echo "$COVERAGE < 50" | bc -l) | |
gt_75=$(echo "$COVERAGE > 75" | bc -l) | |
if [ "$lt_50" -eq 1 ]; then | |
curl -s "https://img.shields.io/badge/Test%20Coverage-${COVERAGE}%25-critical.svg" > coverage.svg | |
elif [ "$gt_75" -eq 1 ]; then | |
curl -s "https://img.shields.io/badge/Test%20Coverage-${COVERAGE}%25-success.svg" > coverage.svg | |
else | |
curl -s "https://img.shields.io/badge/Test%20Coverage-${COVERAGE}%25-important.svg" > coverage.svg | |
fi | |
- name: Upload coverage badge | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-badge | |
path: coverage.svg | |
- name: Commit and push changes | |
run: | | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noteply.github.com" | |
echo "see all files..." | |
ls -la | |
echo "performing git status..." | |
git status | |
echo "see all remote branches" | |
git show-ref | |
git ls-remote | |
if git ls-remote --exit-code --heads origin coverage_badge; then | |
echo "delete coverage_badge remote branch..." | |
git push origin :coverage_badge | |
fi | |
echo "delete other files except the badge..." | |
ls | grep -xv "coverage.svg" | xargs rm -rf | |
echo "staging badge..." | |
git branch coverage_badge | |
git checkout coverage_badge | |
git add . | |
echo "commit badge..." | |
git commit -m "Update badge" | |
echo "push remote..." | |
git push --set-upstream origin coverage_badge |