Skip to content

Commit

Permalink
Merge pull request #8 from inbo/more_work
Browse files Browse the repository at this point in the history
Version 0.1.1
  • Loading branch information
ThierryO authored Jul 12, 2020
2 parents af4eb0f + 6dd14fb commit ebe67ab
Show file tree
Hide file tree
Showing 41 changed files with 1,126 additions and 90 deletions.
6 changes: 5 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
^checklist.yml$
^Dockerfile$
^.dockerignore$
^entrypoint.sh$
^entrypoint_package.sh$
^entrypoint_source.sh$
^.github$
^README\.Rmd$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
14 changes: 14 additions & 0 deletions .github/workflows/check_on_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on:
push:
branches-ignore:
- master
- ghpages

name: "check package"

jobs:
check-package:
runs-on: ubuntu-latest
name: "check package"
steps:
- uses: inbo/actions/check_pkg@master
93 changes: 93 additions & 0 deletions .github/workflows/check_on_different_r_os.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
on:
push:
branches:
- master
pull_request:
branches:
- 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: 'devel'}
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-16.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}

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

- 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}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
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-

- name: Install system dependencies
if: runner.os == 'Linux'
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: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
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: Check
env:
_R_CHECK_CRAN_INCOMING_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@master
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
15 changes: 15 additions & 0 deletions .github/workflows/check_on_master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
push:
branches:
- master
schedule:
- cron: '6 0 * * 1'

name: "check package on master"

jobs:
check-package:
runs-on: ubuntu-latest
name: "check package"
steps:
- uses: inbo/actions/check_pkg@master
20 changes: 13 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: checklist
Title: A Thorough and Strict Set of Checks for R Packages
Version: 0.1.0
Version: 0.1.1
Authors@R:
c(person(given = "Thierry",
family = "Onkelinx",
Expand All @@ -13,13 +13,19 @@ Authors@R:
email = "[email protected]"))
Description: An opinated set of rules for R packages and code.
License: GPL-3
Imports:
assertthat,
devtools,
git2r,
lintr,
R6,
rcmdcheck,
rmarkdown,
usethis,
yaml
Suggests:
testthat
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
Imports:
assertthat,
lintr,
rcmdcheck,
R6,
yaml
20 changes: 18 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ RUN apt-get update \
libxml2-dev \
&& Rscript --no-save --no-restore -e 'remotes::install_cran("devtools")'

## install git2r
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("git2r")'

## install hunspell
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("hunspell")'

Expand All @@ -68,15 +71,27 @@ RUN Rscript --no-save --no-restore -e 'remotes::install_cran("lintr")'
## install microbenchmark
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("microbenchmark")'

## install pillar
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("pillar")'

## install Rcpp
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("Rcpp")'

## install rcmdcheck
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("rcmdcheck")'

## install rlang
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("rlang")'

## install R6
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("R6")'

## install spelling
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("spelling")'

## install tibble
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("tibble")'

## install tidyverse
RUN Rscript --no-save --no-restore -e 'remotes::install_cran("tidyverse")'

Expand All @@ -90,5 +105,6 @@ RUN Rscript --no-save --no-restore -e 'install.packages("INLA", repos = c(getOpt
COPY . /checklist/
RUN Rscript --no-save --no-restore -e 'remotes::install_local("checklist", dependencies = FALSE)'

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
COPY entrypoint_package.sh /entrypoint_package.sh
COPY entrypoint_package.sh /entrypoint_source.sh
ENTRYPOINT ["/entrypoint_package.sh"]
27 changes: 26 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
# Generated by roxygen2: do not edit by hand

export(check_cran)
export(check_description)
export(check_documentation)
export(check_filename)
export(check_lintr)
export(check_package)
export(check_source)
export(checklist)
export(checklist_template)
export(is_workdir_clean)
export(read_checklist)
export(write_checklist)
export(yesno)
importFrom(R6,R6Class)
importFrom(assertthat,assert_that)
importFrom(assertthat,has_name)
importFrom(assertthat,is.flag)
importFrom(assertthat,is.string)
importFrom(assertthat,noNA)
importFrom(devtools,document)
importFrom(git2r,branch_target)
importFrom(git2r,branches)
importFrom(git2r,commits)
importFrom(git2r,in_repository)
importFrom(git2r,ls_tree)
importFrom(git2r,repository)
importFrom(git2r,repository_head)
importFrom(git2r,reset)
importFrom(git2r,sha)
importFrom(git2r,status)
importFrom(lintr,lint_dir)
importFrom(lintr,lint_package)
importFrom(rcmdcheck,rcmdcheck)
importFrom(rmarkdown,github_document)
importFrom(rmarkdown,render)
importFrom(stats,na.omit)
importFrom(usethis,use_tidy_description)
importFrom(utils,file_test)
importFrom(utils,head)
importFrom(utils,menu)
importFrom(utils,tail)
importFrom(yaml,read_yaml)
importFrom(yaml,write_yaml)
22 changes: 22 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# checklist 0.1.1

* Added a `NEWS.md` file to track changes to the package.
* Added a `README.Rmd` file with installation instructions.
* Rework `checklist_template()` into `write_checklist()`.
* Add `check_description()`.
* Add `check_documentation()`.
* Add `check_filename()`.
* Add `check_source()`.
* `check_lintr()` also works on source code repositories.
* Activate GitHub action `inbo/check_package`.

# checklist 0.1.0

* Initital version.
* Create `checklist` R6 class.
* Add `check_cran()`.
* Add `check_lintr()`.
* Add `check_package()`.
* Add `read_checklist()`.
* Add `checklist_template()`.
* Add Dockerimage for GitHub actions.
6 changes: 6 additions & 0 deletions R/check_cran.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#' Run the package checks required by CRAN
#' @inheritParams read_checklist
#' @return A `Checklist` object.
#' @importFrom assertthat assert_that
#' @importFrom rcmdcheck rcmdcheck
#' @export
check_cran <- function(x = ".") {
if (!inherits(x, "Checklist") || !"checklist" %in% x$get_checked) {
x <- read_checklist(x = x)
}
assert_that(
x$package,
msg = "`check_cran()` is only relevant for packages.
`checklist.yml` indicates this is not a package."
)

check_output <- rcmdcheck(
path = x$get_path,
Expand Down
70 changes: 70 additions & 0 deletions R/check_description.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#' Check the DESCRIPTION file
#' @inheritParams read_checklist
#' @importFrom assertthat has_name
#' @importFrom git2r branches branch_target commits repository repository_head
#' reset sha
#' @importFrom stats na.omit
#' @importFrom usethis use_tidy_description
#' @importFrom utils head tail
#' @export
check_description <- function(x = ".") {
if (!inherits(x, "Checklist") || !"checklist" %in% x$get_checked) {
x <- read_checklist(x = x)
}
assert_that(
x$package,
msg = "`check_description()` is only relevant for packages.
`checklist.yml` indicates this is not a package."
)

repo <- repository(x$get_path)
description <- file.path(x$get_path, "DESCRIPTION")
assert_that(file_test("-f", description), msg = "DESCRIPTION file missing")

version <- read.dcf(description)[, "Version"]
"Incorrect version tag format. Use `0.0`, `0.0.0`"[
!grepl("^[0-9]+\\.[0-9]+(\\.[0-9]+)?$", version)
] -> desc_error

branch_sha <- vapply(branches(repo, "all"), branch_target, character(1))
head_sha <- sha(repository_head(repo))
current_branch <- head(names(which(branch_sha == head_sha)), 1)
if (current_branch == "master") {
old_sha <- vapply(
tail(commits(repo, ref = "master", n = 2), 1), sha, character(1)
)
desc_diff <- system2(
"git", args = c("diff", old_sha, head_sha, "DESCRIPTION"),
stdout = TRUE
)
} else {
desc_diff <- system2(
"git", args = c("diff", "origin/master", "--", "DESCRIPTION"),
stdout = TRUE
)
}
clean <- is_workdir_clean(repo)
use_tidy_description()
if (clean && !is_workdir_clean(repo)) {
desc_error <- c(
desc_error,
"DESCRIPTION not tidy. use `usethis::use_tidy_description()`"
)
reset(repo)
}
old_version <- desc_diff[grep("\\-Version: ", desc_diff)]
old_version <- gsub("-Version: ", "", old_version)
version_bump <- ifelse(
length(old_version),
ifelse(
package_version(old_version) < package_version(version),
NA,
"Package version not increased"
),
"Package version not updated"
)
desc_error <- c(desc_error, na.omit(version_bump))

x$add_error(desc_error, "DESCRIPTION")
return(x)
}
Loading

0 comments on commit ebe67ab

Please sign in to comment.