Skip to content

Commit

Permalink
Enable CI for dso-r (#10)
Browse files Browse the repository at this point in the history
* Add github actions for test and release

* enable pre-commit

* Remove python deps

* fix syntax

* Roxygenize with pre-commit

* Update pre-commit hook

* Add missing params documentation

* Set workflow permissions

* autofixes

* pre-commit autofixes

* disable autoformatting in certain unit tests

* pre-commit autofixes

* pre-commit autofixes

* Fix missing params docs

* pre-commit autofixes

* trigger CI

* updated to remove warnings

* updated dsoParams class to remove warnings;

* pre-commit autofixes

* trigger CI

* updated .Rbuildignore

* updated

* updated dsoparams class

* bumped version

* pre-commit autofixes

* trigger CI

---------

Co-authored-by: grst <[email protected]>
Co-authored-by: zxBIB Schreyer,Daniel (TMCP Data Sc) EXTERNAL <[email protected]>
Co-authored-by: DSchreyer <[email protected]>
  • Loading branch information
4 people authored Oct 18, 2024
1 parent 6d8115b commit 1b7a290
Show file tree
Hide file tree
Showing 23 changed files with 414 additions and 107 deletions.
5 changes: 5 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.pre-commit-config\.yaml$
^\.github$
^CHANGELOG\.md$
41 changes: 41 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

name: pre-commit

jobs:
pre-commit:
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::roxygen2
needs: roxygen2

- uses: pre-commit/[email protected]

- uses: stefanzweifel/git-auto-commit-action@v5
if: '!cancelled()'
with:
commit_message: pre-commit autofixes
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build and Attach R Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
r-version: release
http-user-agent: release
use-public-rspm: true

- name: Build package
run: |
R CMD build .
FILENAME=$(ls dso_*.tar.gz)
echo "FILENAME=${FILENAME}" >> $GITHUB_ENV
- name: Check version
run: |
VERSION=$(echo $FILENAME | sed 's/.*_\(.*\).tar.gz/\1/')
if [ "v${VERSION}" != "${GITHUB_REF#refs/tags/}" ]; then
echo "Version mismatch. Tag version and package version should be the same."
exit 1
fi
- name: Attach tarball to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./${{ env.FILENAME }}
asset_name: ${{ env.FILENAME }}
asset_content_type: application/gzip
50 changes: 50 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# The purpose of this workflow is to execute `R CMD check` on different R and OS version.
#
# 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, master]
pull_request:
branches: [main, 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: macOS-latest, r: "release" }
- { os: windows-latest, r: "release" }
- { os: ubuntu-latest, r: "devel", http-user-agent: "release" }
- { os: ubuntu-latest, r: "release" }

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- 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
49 changes: 49 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# All available hooks: https://pre-commit.com/hooks.html
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.3
hooks:
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style, --scope=tokens]
- id: parsable-R
- id: no-browser-statement
- id: no-debug-statement
- id: deps-in-desc
args: [--allow_private_imports]
- id: roxygenize
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: end-of-file-fixer
exclude: '\.Rd'
- id: detect-private-key
- id: check-ast
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
- id: check-case-conflict
# Check that there are no merge conflicts (could be generated by template sync)
- id: check-merge-conflict
args: [--assume-in-merge]
- repo: https://github.com/pre-commit-ci/pre-commit-ci-config
rev: v1.5.1
hooks:
# Only reuiqred when https://pre-commit.ci is used for config validation
- id: check-pre-commit-ci-config
- repo: local
hooks:
- id: forbid-to-commit
name: Don't commit common R artifacts
entry: Cannot commit .Rhistory, .RData, .Rds or .rds.
language: fail
files: '\.(Rhistory|RData|Rds|rds)$'
exclude: "(inst/extdata|data)/.*"
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v3.0.0-alpha.6
# hooks:
# - id: prettier
# language_version: "17.9.1"

ci:
autoupdate_schedule: monthly
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v0.4.3

### Improvements

- updated .Rbuildignore ignoring package redundant files
- added precommit configs
- included methods show
- set class of dsoParams object
- fixed R CMD check warnings

## v0.4.2

### Improvements
Expand Down
19 changes: 11 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
Package: dso
Type: Package
Title: dso R companion package
Version: 0.4.2
Title: dso R companion package
Version: 0.4.3
Author: Daniel Schreyer<[email protected]>,
Gregor Sturm<[email protected]>,
Gregor Sturm<[email protected]>,
Thomas Schwarzl<[email protected]>
Maintainer: Daniel Schreyer<[email protected]>,
Gregor Sturm<[email protected]>,
Gregor Sturm<[email protected]>,
Thomas Schwarzl<[email protected]>
Description: Collection of functions used with the DevOps dso application.
Description: Collection of functions used with the DevOps dso application.
License: GPL-3 + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
yaml,
glue,
here
RoxygenNote: 7.3.1
Suggests:
here,
stringr,
methods,
rlang
RoxygenNote: 7.3.2
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ export(read_params)
export(safe_get)
export(set_stage)
export(stage_here)
exportClasses(dsoParams)
exportMethods(as.list)
exportMethods(show)
importFrom(glue,glue)
importFrom(here,here)
importFrom(here,i_am)
importFrom(methods,show)
importFrom(rlang,caller_env)
importFrom(stringr,coll)
importFrom(stringr,str_match_all)
Expand Down
67 changes: 45 additions & 22 deletions R/class-dsoParams.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#' dsoParams class
#'
#' @slot params A list of lists containing parameters
#' @export
setClass("dsoParams",
slots = list(
params = "list"
)
)

#' A "dsoParams" and its constructor:
#'
#' @title dsoParams: list with safe access
#' @param x empty, or a recursive list of lists which is converted to dsoParams
#'
#' @examples
#' # initiating empty
#' params <- dsoParams()
Expand All @@ -15,25 +26,26 @@
#' params <- dsoParams(params)
#'
#' @export
dsoParams <- function( x = list()) {
if(! is.list(x))
dsoParams <- function(x = list()) {
if (!is.list(x)) {
stop("x needs to be a list or a list of lists.")

}
# recursively
x <- lapply(x, function(y) {
if(is.list(y)) {
dsoParams(y)
} else {
y
}
if (is.list(y)) {
dsoParams(y)
} else {
y
}
})
class(x) <- c("dsoParams", "list")
return(x)
}


#' overriding the the $ operator to add secure list calling so that
#' it cannot return NULL when call does not exist
#' @param x dsoParams object
#' @param name field name
#' @export
`$.dsoParams` <- function(x, name) {
if (!name %in% names(x)) {
Expand All @@ -45,44 +57,55 @@ dsoParams <- function( x = list()) {

#' And the [[ operator: to add secure list calling so that
#' it cannot return NULL when call does not exist
#' @param x dsoParams object
#' @param i index for `[[` operator
#' @param ... additional arguments passed to the `[[` operator
#' @export
`[[.dsoParams` <- function(x, i, ...) {
if (is.character(i) && !i %in% names(x)) {
stop(paste("Element '", i, "' does not exist in dsoParams", sep = ""))
} else if (is.numeric(i) && (i < 1 || i > length(x))) {
stop(paste("Index '", i, "' is out of bounds in dsoParams", sep = ""))
}


NextMethod()
}

#' Custom print method for dsoParams class
#' @param x dsoParams object
#' @param ... additional parameters are ignored
#' @export
print.dsoParams <- function(object, ...) {
cat(yaml::as.yaml(object))
print.dsoParams <- function(x, ...) {
cat(yaml::as.yaml(x))
}

#' Custom show method for dsoParams class
#' @importFrom methods show
#' @param object dsoParams object
#' @export
setMethod(f = "show",
signature = "dsoParams",
definition = function(object) {
cat(yaml::as.yaml(object))
})
setMethod(
f = "show",
signature = "dsoParams",
definition = function(object) {
cat(yaml::as.yaml(object))
}
)

# Custom as.list method for dsoParams class
#' Custom as.list method for dsoParams class
#' @param x dsoParams object
#' @return A list
#' @export
setMethod(
f = "as.list",
f = "as.list",
signature = "dsoParams",
definition = function(x) {
lapply(x, function(y) {
if("dsoParams" %in% class(y)) {
if ("dsoParams" %in% class(y)) {
as.list(unclass(y))
} else {
x
y
}
})
}
)


2 changes: 2 additions & 0 deletions R/compile_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#'
#' @keywords dso dvc yaml compile config
#'
#' @param dir directory (including subdirectories and relevant parent files) to compile. By default compiles the current working directory.
#'
#' @export
#'
#' @examples
Expand Down
Loading

0 comments on commit 1b7a290

Please sign in to comment.