use pkgsite with math rendering #42
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 | |
| 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" | |
| # Save the badge file before switching branches | |
| cp badges/coverage.svg /tmp/coverage.svg | |
| # Create or switch to coverage branch | |
| git checkout -B coverage | |
| # Remove everything except .git | |
| git rm -rf . || true | |
| # Restore just the badge | |
| mkdir -p badges | |
| cp /tmp/coverage.svg badges/coverage.svg | |
| git add badges/coverage.svg | |
| if ! git diff --staged --quiet; then | |
| git commit -m "Update coverage badge" | |
| git push --force origin coverage | |
| else | |
| echo "No changes to commit" | |
| fi | |
| # Switch back to main | |
| git checkout main |