Skip to content

Commit

Permalink
Merge pull request #220 from r-world-devs/test
Browse files Browse the repository at this point in the history
First release
  • Loading branch information
maciekbanas authored May 15, 2023
2 parents a0ca271 + 5451565 commit 8ccc3c9
Show file tree
Hide file tree
Showing 86 changed files with 8,202 additions and 2,327 deletions.
12 changes: 12 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
^renv$
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^LICENSE\.md$
^README.Rmd
^codecov\.yml$
^\.covrignore$
^devel$
^_pkgdown\.yml$
^docs$
^pkgdown$
^meta_data.yaml
4 changes: 4 additions & 0 deletions .Renviron
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is a bypass of common CMD-check error unsolved at the core.
# For more information you can check this issue:
# https://stackoverflow.com/questions/63613301/r-cmd-check-note-unable-to-verify-current-time
_R_CHECK_SYSTEM_CLOCK_=0
4 changes: 4 additions & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if (Sys.getenv("USE_RENV", unset = "TRUE") == "TRUE") {
Sys.setenv(RENV_CONFIG_RSPM_ENABLED = FALSE)
source("renv/activate.R")
}
1 change: 1 addition & 0 deletions .covrignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
R/examples.R
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
47 changes: 47 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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: [master]
pull_request:
branches: [devel, test, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-latest, r: 'release'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
GITLAB_PAT_PUBLIC: ${{ secrets.GITLAB_PAT}}
R_KEEP_PKG_SOURCE: yes
USE_RENV: "FALSE"

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
227 changes: 227 additions & 0 deletions .github/workflows/code-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
on:
workflow_dispatch:
workflow_call:
inputs:
r-version:
description: 'The version of R to use'
default: '4.1.3'
required: false
type: string
skip-coverage-badges:
description: 'Skip code coverage badge creation'
default: false
required: false
type: boolean
push:
branches:
- master
pull_request:
branches:
- master
- devel
- test

name: Code Coverage

concurrency:
group: coverage-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
coverage:
name: Test Coverage
runs-on: ubuntu-20.04
if: >
!contains(github.event.commits[0].message, '[skip coverage]')
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
outputs:
coverage-percent: ${{ steps.set-coverage-percentage.outputs.coverage-percentage }}
steps:
##################### BEGIN boilerplate steps #####################
- name: Get branch names
id: branch-name
uses: tj-actions/[email protected]

- name: Checkout repo (PR) 🛎
uses: actions/checkout@v3
if: github.event_name == 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
repository: ${{ github.event.pull_request.head.repo.full_name }}

- name: Checkout repository
uses: actions/checkout@v3
if: github.event_name != 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}

- name: Normalize inputs
id: normalizer
run: |
R_VERSION="${{ inputs.r-version }}"
if [ "$R_VERSION" == "" ]
then {
R_VERSION="4.1.3"
}
fi
echo "R_VERSION=$R_VERSION" >> $GITHUB_OUTPUT
shell: bash

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ steps.normalizer.outputs.R_VERSION }}

- name: Restore cache
uses: actions/cache@v3
with:
path: |
~/.local/share/renv
~/.staged.dependencies
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
restore-keys: ${{ runner.os }}-renv-

- name: Setup Pandoc
uses: r-lib/actions/setup-pandoc@v2

- name: Run Staged dependencies
uses: insightsengineering/staged-dependencies-action@v1
with:
run-system-dependencies: true
enable-check: false
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
USE_RENV: "FALSE"
##################### END boilerplate steps #####################

- name: Install package
run: renv::install(".")
shell: Rscript {0}

- name: Run coverage 👟
run: |
tryCatch(
expr = {
x <- covr::package_coverage(
path=".",
clean = FALSE,
quiet = FALSE
)
print(x)
covr::to_cobertura(x, filename = "coverage.xml")
p <- round(covr::percent_coverage(x))
cat(p, file = "coverage.txt", sep = "")
covr::report(
x,
file = "coverage-report.html",
browse = FALSE
)
},
error = function(e) {
message("Errors generated during coverage analysis:")
print(e)
error_file <- list.files(path = "/tmp", pattern="*.fail$", recursive = T, full.names = T)[1]
if (length(error_file) && file.exists(error_file)) {
cat("__________FULL OUTPUT__________")
writeLines(readLines(error_file))
}
},
warning = function(w) {
message("Warnings generated during coverage analysis:")
print(w)
}
)
shell: Rscript {0}

- name: Check whether coverage reports exists
id: check_coverage_reports
uses: andstor/file-existence-action@v1
with:
files: "coverage.xml, coverage.txt, coverage-report.html"

- name: Set coverage percentage as output
id: set-coverage-percentage
run: echo "coverage-percentage=$(cat coverage.txt)" >> $GITHUB_OUTPUT
if: steps.check_coverage_reports.outputs.files_exists == 'true'

- name: Generate Coverage Summary Report
if: steps.check_coverage_reports.outputs.files_exists == 'true' && github.event_name == 'pull_request'
uses: irongut/[email protected]
with:
filename: coverage.xml
badge: true
fail_below_min: false
format: markdown
hide_branch_rate: true
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'

- name: Upload report for review
if: steps.check_coverage_reports.outputs.files_exists == 'true' && github.event_name == 'pull_request'
uses: actions/upload-artifact@v2
with:
name: coverage-report
path: "coverage-report.html"
continue-on-error: true

- name: Add Coverage PR Comment
if: steps.check_coverage_reports.outputs.files_exists == 'true' && github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: code-coverage
path: code-coverage-results.md
continue-on-error: true

badge:
name: Generate badge for coverage
needs: [coverage]
runs-on: ubuntu-20.04
if: >
inputs.skip-coverage-badges != 'true' ||
!contains(github.event.commits[0].message, '[skip coverage]')
steps:
- name: Checkout the badges branch in repo
uses: actions/checkout@v3
with:
ref: badges
path: badges

# Use the output from the `coverage` step
- name: Generate the badge SVG image
uses: emibcn/badge-action@v1
id: badge
with:
label: 'Test Coverage'
status: "${{ needs.coverage.outputs.coverage-percent }}%"
color: ${{
needs.coverage.outputs.coverage-percent > 90 && 'green' ||
needs.coverage.outputs.coverage-percent > 80 && 'yellow,green' ||
needs.coverage.outputs.coverage-percent > 70 && 'yellow' ||
needs.coverage.outputs.coverage-percent > 60 && 'orange,yellow' ||
needs.coverage.outputs.coverage-percent > 50 && 'orange' ||
needs.coverage.outputs.coverage-percent > 40 && 'red,orange' ||
needs.coverage.outputs.coverage-percent > 30 && 'red,red,orange' ||
needs.coverage.outputs.coverage-percent > 20 && 'red,red,red,orange' ||
'red' }}
path: badges/test-coverage.svg

- name: Commit badge
working-directory: ./badges
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
mkdir -p "${BRANCH}"
mv test-coverage.svg "${BRANCH}"
git add "${BRANCH}/test-coverage.svg"
git commit -m "Add/Update badge" || true
- name: Push badges
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: badges
directory: badges
continue-on-error: true
16 changes: 16 additions & 0 deletions .github/workflows/other-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Check 🛠

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
spelling:
if: github.event_name == 'pull_request'
name: Spell Check 🆎
uses: insightsengineering/r.pkg.template/.github/workflows/spelling.yaml@main
52 changes: 52 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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: [master]
pull_request:
branches: [devel, test, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
GITLAB_PAT_PUBLIC: ${{ secrets.GITLAB_PAT}}
USE_RENV: "FALSE"

steps:
- uses: actions/checkout@v3

- 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: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
.Rhistory
.RData
.Ruserdata
examples.R
example_workflow_Roche.R
example_branch.R
docs
inst/doc
Loading

0 comments on commit 8ccc3c9

Please sign in to comment.