Commit 927cb0bc authored by Jean-Francois Rey's avatar Jean-Francois Rey
Browse files

First commit r template package

parents
Pipeline #796 passed with stages
^\.gitlab\-ci\.yml$
^\.git$
^\.gitignore$
^README\.md$
stages:
- create
- tests
- build
R-base-create:
stage: create
tags:
- "r-base-biosp"
script:
# generate Documentation
- "Rscript -e \"roxygen2::roxygenize('.', roclets=c('rd', 'collate', 'namespace'))\""
# create the package
- "R CMD build . --resave-data"
artifacts:
paths:
# keep the package for later jobs
- "$(ls -rt *_*.tar.gz |tail -1)"
# can use $CI_PROJECT_NAME if package name the same
R-devel-create:
stage: create
tags:
- "r-devel-biosp"
script:
- "Rscript -e \"roxygen2::roxygenize('.', roclets=c('rd', 'collate', 'namespace'))\""
- "R CMD build . --resave-data"
artifacts:
paths:
- "$(ls -rt *_*.tar.gz |tail -1)"
allow_failure: true
R-Mac-create:
stage: create
tags:
- "Mac"
- "R"
script:
- "Rscript -e \"roxygen2::roxygenize('.', roclets=c('rd', 'collate', 'namespace'))\""
- "R CMD build . --resave-data"
artifacts:
paths:
- "$(ls -rt *_*.tar.gz |tail -1)"
R-Windows-create:
stage: create
tags:
- "win10"
- "R"
- "binaries"
script:
- "Rscript -e \"roxygen2::roxygenize('.', roclets=c('rd', 'collate', 'namespace'))\""
- "R CMD build . --resave-data"
artifacts:
paths:
- "$(ls -rt *_*.tar.gz |tail -1)"
R-base-tests:
stage: tests
tags:
- "r-base-biosp"
script:
- "R CMD check --as-cran $(ls -rt *_*.tar.gz |tail -1)"
artifacts:
paths:
- "$(ls -rt *_*.tar.gz |tail -1)"
dependencies:
- R-base-create
R-devel-tests:
stage: tests
tags:
- "r-devel-biosp"
script:
- "R CMD check --as-cran $(ls -rt *_*.tar.gz |tail -1)"
artifacts:
paths:
- "$(ls -rt *_*.tar.gz |tail -1)"
allow_failure: true
dependencies:
- R-devel-create
R-Mac-tests:
stage: tests
tags:
- "Mac"
- "R"
script:
- "R CMD check --as-cran $(ls -rt *_* |tail -1)"
artifacts:
paths:
- "$(ls -rt *_*.tar.gz |tail -1)"
dependencies:
- R-Mac-create
R-Windows-tests:
stage: tests
tags:
- "win10"
- "R"
- "binaries"
script:
- "R CMD check --as-cran $(ls -rt *_*.tar.gz |tail -1)"
artifacts:
paths:
- "$(ls -rt *_*.tar.gz |tail -1)"
dependencies:
- R-Windows-create
release-R:
stage: build
tags:
- "r-base-biosp"
script:
- "echo \"Nothing to do\""
artifacts:
paths:
- "$(ls -rt *_* |tail -1)"
only:
- tags
dependencies:
- R-base-tests
release-Windows:
stage: build
tags:
- "win10"
- "R"
- "binaries"
script:
- "R CMD INSTALL --build --force-biarch $(ls -rt *_*.tar.gz |tail -1)"
artifacts:
paths:
- "$(ls -rt *_*.zip |tail -1)"
only:
- tags
dependencies:
- R-Windows-tests
release-MacOS:
stage: build
tags:
- "Mac"
- "R"
script:
- "R CMD INSTALL --build $(ls -rt *_*.tar.gz |tail -1)"
artifacts:
paths:
- "$(ls -rt *_*.tgz | tail -1)"
only:
- tags
dependencies:
- R-Mac-tests
Package: PackageRTemplate
Type: Package
Encoding: UTF-8
Title: R Template Package
Version: 0.1.0
Date: 2019-11-05
Authors@R: person("Jean-Francois", "Rey", role = c("aut","cre"), email = "jean-francois.rey@inra.fr")
Author: Jean-Francois Rey [cre, aut]
Maintainer: Jean-Francois Rey <jean-francois.rey@inra.fr>
Description: A R package template to manage the package and the CI/CD pipeline.
URL: https://gitlab.paca.inra.fr/r-ecosystem/cookbooks/r-packages-ci-cd
BugReports: https://gitlab.paca.inra.fr/r-ecosystem/cookbooks/r-packages-ci-cd/issues
License: GPL (>= 3) | file LICENSE
LazyData: true
BuildVignettes: true
Biarch: true
Depends:
methods,
utils,
grDevices (>= 3.0.0),
graphics (>= 3.0.0),
R (>= 3.3.0)
Imports:
stats (>= 3.0.2)
Collate:
'packagertemplate.R'
'awesomemethod.R'
LinkingTo: testthat
RoxygenNote: 6.1.1
Suggests:
testthat
This diff is collapsed.
# R Package Template fr CI/CD piepline.
# Copyright (C) 2016 Jean-François Rey <jean-françois.rey@inra.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#' An awesome method that return if the parameter is TRUE
#' @title Test parameter is TRUE
#' @name awesomemethod
#' @param bool a boolean (default TRUE)
#' @return TRUE if bool is TRUE otherwise FALSE
#' @include packagertemplate.R
#' @export
awesomemethod <- function(bool = TRUE) {
return(bool == TRUE)
}
# R Package Template fr CI/CD piepline.
# Copyright (C) 2016 Jean-François Rey <jean-françois.rey@inra.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#' @encoding UTF-8
#' @title R Package Template
#' @description A R package template to manage the package and the CI/CD piepline.
#' @aliases packagertemplate-package
#'
#' @author Jean-Francois Rey \email{jean-francois.rey@@inra.fr}
#'
#' Maintainer: Jean-Francois Rey \email{jean-francois.rey@@inra.fr}
#' @docType package
#' @name packagertemplate-package
#' @details \tabular{ll}{
#' Package: \tab PackageRTemplate\cr
#' Type: \tab Package\cr
#' Version: \tab 0.1.0\cr
#' Date: \tab 2019-11-05\cr
#' License: \tab GPL (>=3)\cr
#' }
#'
#' The PackageRTemplate package implements a R package template and how to manage CI/CD pipeline.
#' @keywords R package CI CD GitLab
#' @examples
#' \dontrun{
#' library("PackageRTemplate")
#' }
#' @import methods
#' @import graphics
#' @import stats
"_PACKAGE"
# R Packages Continuous Integration and Deployment (CI/CD) pipeline
This project hosts the repository of a Cookbook to manage a R package.
This template generate the documentation, build the package, run unit tests, check --as--cran, create package binaries for Windows and Mac OS...
[useR2019 poster __R package development using GitLab CI/CD pipeline__ , JF Rey, L Houde, 2019](inst/userR2019-poster_JF_REY.pdf)
** Table of Contents**
- [Prerequisites](#prerequisites)
- [Files](#files)
- [Principle](#principle)
- [Set GitLab](#set-gitlab)
- [The Project](#the-project-repository)
- [The Runners](#the-runners)
- [The .gitlab-ci.yml file](#the-gitlab-ciyml-file)
- [Author](#author)
- [License](#license)
## Prerequisites
* Have to know:
* GitLab project management
* R Packages
* Should to know:
* GitLab Runners principle
* GitLab CI/CD principle
* R Package CRAN policy
## Branches
There are severals version of this project, depending if the package need compilations, vignettes... :
* simple R package : [master](tree/master)
* R package and c++ code source : [Rcpp](tree/rcpp)
## Files
* __[.gitlab-ci.yml](.gitlab-ci.yml)__ : file configuring the CI/CD pipeline
* R Package stuff :
* __[DESCRIPTION](DESCRIPTION)__ : the DESCRIPTION file update by roxygen2
* __[NAMESPACE](NAMESPACE)__ : the NAMESPACE file generated by roxygen2
* __[.Rbuildignore](.Rbuildignore)__ : regex for files to not include in package
* __[R/](R)__ : R source code directory
* __[man/](man)__ : documentation directory generated by roxygen2
* __[test/](tests)__ : testthat direcotry, instruction for tests
* __[inst/](inst)__ : directory of files to add in package at install
* __[LICENSE](LICENSE)__ : the license file
## Principle
![GitLab CI/CD R Package pipeline](inst/GitLab_CI_CD_pipeline_RPackage.png)
* At push (and commit), in GitLab repository, the pipeline is trigger.
* GitLab use __[.gitlab-ci.yml](.gitlab-ci.yml)__ file to set the pipeline and run it on runners.
* First it generates the package
* Then it run tests
* And finally build binaries packages
## set up GitLab
### The project repository
You can fork this project and use it as a template.
* Files in the project: [Files](#files)
You need to enable __Pipelines__ in the project setting (_Setting -> General -> Visibility_)
and enable __Shared Runners__ (_Setting -> CI/CD -> Runners_).
### The runners
Four Runners are availables for R Packaging in the shared runners :
* r-base-biosp : it's the current version of R for Linux OS (nightly build as docker image). [See here](https://gitlab.paca.inra.fr/r-ecosystem/r-docker-images) for more information.
* r-devel-biosp : it's the in development version of R (the next version) for Linux OS (nightly build as docker image). [See here](https://gitlab.paca.inra.fr/r-ecosystem/r-docker-images) for more information.
* R win10 binaries : a Windows 10 Virtual Machine with the current R and Rtools version.
* R Mac : a Mac OS High Sierra with the current R and Rtools version.
If you need you can add your own runner or ask GitLab administrator to set up a new one.
## The .gitlab-ci.yml file
__[.gitlab-ci.yml](.gitlab-ci.yml)__ is the configuration file for the CI/CD pipeline.
It set up three stages (create, tests and build) and severals jobs by stages.
* create : update Description, NAMESPACE, and man (roxygen2). Create the package.
* tests : Test the package (--as-cran)
* build : Build the package source tar.gz and binary version for MacOS (.tgz) and Windows (.zip)
You need to set up this file for your project.
Each jobs produces artifacts mainly in _build_ stage it produces R packages delivery for Linux, Windows and Mac OS.
## Author
[Jean-François Rey](https://jeff.biosp.org) \<jean-francois.rey at inra dot fr\>
## License
See [LICENSE](LICENSE)
library(testthat)
library(PackageRTemplate)
test_check("PackageRTemplate")
context("test-method")
test_that("awesomemethod return values", {
expect_equal(awesomemethod(), TRUE)
expect_equal(awesomemethod(FALSE), FALSE)
expect_equal(awesomemethod(TRUE), TRUE)
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment