use rhub #36
This file contains hidden or 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
| # 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 | |
| env: | |
| GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - 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 cpp4rtest | |
| 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" | |
| } | |
| # Write coverage info to environment | |
| writeLines(paste0("COVERAGE=", percent), Sys.getenv("GITHUB_ENV")) | |
| writeLines(paste0("COVERAGE_COLOR=", color), Sys.getenv("GITHUB_ENV")) | |
| shell: Rscript {0} | |
| - name: Generate coverage badge | |
| run: | | |
| mkdir -p badges | |
| curl -s "https://img.shields.io/badge/coverage-${{ env.COVERAGE }}%25-${{ env.COVERAGE_COLOR }}" > 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 | |
| git diff --staged --quiet || git commit -m "Update coverage badge [skip ci]" || true | |
| git push || true |