Skip to content

README fix

README fix #94

# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# also derived from https://github.com/we-cli/coverage-badge-action
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
name: test-coverage-local
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, any::DT, any::htmltools
needs: coverage
- name: Cache C++ and R dependencies
uses: actions/cache@v2
with:
path: |
~/.cache/R
~/.local/share/R
key: dependencies-${{ runner.os }}-${{ hashFiles('**/DESCRIPTION') }}
restore-keys: |
dependencies-${{ runner.os }}-
- name: Test coverage
run: |
Rscript -e "covpack<-covr::package_coverage(install_path='${{ github.workspace }}/cov', clean=FALSE); \
covr::report(covpack, file = file.path('${{ github.workspace }}', 'chopin-coverage-report.html')); \
covd<-covr::coverage_to_list(covpack)$totalcoverage; \
write.table(covd[length(covd)], file = '${{ github.workspace }}/local_cov.Rout', row.names = F, col.names = F)"
shell: bash
- name: Upload covr report as artifact
uses: actions/upload-artifact@v4
with:
name: covr-report
path: ${{ github.workspace }}/chopin-coverage-report.html
- name: Upload workspace dump as artifact if the test fails
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: test-outputs
path: ${{ github.workspace }}/**
- name: Get Values
id: get-values
shell: bash
run: |
COV=$(cat ${{ github.workspace }}/local_cov.Rout)
echo "coverage=$COV" >> $GITHUB_OUTPUT
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Create Badges
shell: bash
run: |
npm i -g badgen-cli
export COV=${{ steps.get-values.outputs.coverage }}
COLOR=$(node -p '+process.env.COV >= 95 ? `green` : `orange`')
mkdir -p badges
badgen -j coverage -s $COV% -c $COLOR > ${{ github.workspace }}/badges/coverage.svg
- name: Checkout artifacts branch
uses: actions/checkout@v4
with:
ref: artifacts
persist-credentials: false
- name: Commit and Push Badge to Artifacts Branch
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
mkdir -p actions/workflows/test-coverage-local.yaml
mv badges/coverage.svg actions/workflows/test-coverage-local.yaml/coverage.svg
git add actions/workflows/test-coverage-local.yaml/coverage.svg
git commit -m "Update coverage badge [skip ci]"
git push origin artifacts
if: success()