Skip to content

add on-the-fly note #39

add on-the-fly note

add on-the-fly note #39

# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main]
pull_request:
branches: [main]
name: test-coverage
jobs:
test-coverage:
runs-on: ubuntu-latest
permissions:
contents: write
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage
- name: Install package
run: |
options(warn = 2)
pak::pkg_install("pachadotdev/cpp4r", dependencies = TRUE)
pak::local_install_dev_deps("cpp4rtest", dependencies = TRUE)
install.packages("cpp4rtest", repos = NULL, INSTALL_opts = "--install-tests", type = "source")
shell: Rscript {0}
- name: Test coverage
run: |
coverage <- covr::package_coverage(quiet = FALSE)
percent <- round(covr::percent_coverage(coverage))
cat("Coverage:", percent, "%\n")
# Create badge color based on coverage
if (percent >= 90) {
color <- "brightgreen"
} else if (percent >= 80) {
color <- "green"
} else if (percent >= 70) {
color <- "yellowgreen"
} else if (percent >= 60) {
color <- "yellow"
} else if (percent >= 50) {
color <- "orange"
} else {
color <- "red"
}
writeLines(as.character(percent), "coverage_percent.txt")
writeLines(color, "coverage_color.txt")
shell: Rscript {0}
- name: Generate coverage badge
run: |
COVERAGE=$(cat coverage_percent.txt)
COVERAGE_COLOR=$(cat coverage_color.txt)
echo "Coverage: $COVERAGE%"
echo "Color: $COVERAGE_COLOR"
mkdir -p badges
curl -s "https://raw.githubusercontent.com/pachadotdev/ghacoveragebadge/refs/heads/main/badges/${COVERAGE_COLOR}.svg" > badges/coverage.svg
# each badge contains a placeholder {{ COVERAGE }} that we replace with the actual coverage percentage
sed -i "s/{{ COVERAGE }}/${COVERAGE}/g" badges/coverage.svg
- name: Commit coverage badge
if: github.ref == 'refs/heads/main'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add badges/coverage.svg
if ! git diff --staged --quiet; then
# Amend the last commit to include the updated badge, preserving its message
git commit --amend --no-edit
# Safely update the remote with force-with-lease to avoid clobbering concurrent changes
git push --force-with-lease origin main
else
echo "No changes to commit"
fi