Skip to content

Commit

Permalink
GHA: modernize - step 5
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Jan 23, 2025
1 parent 364c1da commit 9ed4a0c
Showing 1 changed file with 36 additions and 64 deletions.
100 changes: 36 additions & 64 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,84 +1,56 @@
on: [push]

name: covr
name: test-coverage.yaml

jobs:
covr:
if: "! contains(github.event.head_commit.message, '[ci skip]')"

timeout-minutes: 10
permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest

name: covr

strategy:
fail-fast: false

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RSPM: https://packagemanager.rstudio.com/cran/__linux__/jammy/latest
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
## R CMD check
_R_CHECK_CRAN_INCOMING_: false
_R_CHECK_LENGTH_1_CONDITION_: true
_R_CHECK_LENGTH_1_LOGIC2_: true
_R_CHECK_MATRIX_DATA_: true
_R_CHECK_SUGGESTS_ONLY_: true
_R_CHECK_THINGS_IN_TEMP_DIR_: true

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2
- name: Assert CODECOV_TOKEN is set
run: |
if [[ -z "${{secrets.CODECOV_TOKEN}}" ]]; then
>&2 echo "::error::ERROR: 'secrets.CODECOV_TOKEN' not set"
exit 1
fi
- uses: r-lib/actions/setup-r@v2
with:
r-version: release

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
use-public-rspm: true

- name: Cache R packages
uses: actions/cache@v4
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
extra-packages: any::covr, any::xml2
needs: coverage

- name: Install system dependencies
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"
- name: Install dependencies
run: |
install.packages(c("covr", "sessioninfo"))
remotes::install_deps(dependencies = TRUE)
install.packages(".", repos=NULL, type="source")
shell: Rscript {0}

- name: Session info
run: |
options(width = 100)
pkgs <- installed.packages()[, "Package"]
sessioninfo::session_info(pkgs, include_base = TRUE)
shell: Rscript {0}

- name: Test coverage
run: |
## 1. Get 'Repository Upload Token' from Codecov:
## https://app.codecov.io/gh/<org>/<repo>/settings
## 2. Set 'CODECOV_TOKEN' in GitHub Secrets:
## https://github.com/<org>/<repo>/settings/environments/
coverage <- covr::package_coverage()
print(coverage)
covr::codecov(coverage = coverage, token="${{secrets.CODECOV_TOKEN}}")
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
print(cov)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package

0 comments on commit 9ed4a0c

Please sign in to comment.