Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add use_makefile() and use_jenkinsfile(). #501

Merged
merged 11 commits into from
May 3, 2019
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ export(use_github_links)
export(use_github_release)
export(use_gitlab_ci)
export(use_gpl3_license)
export(use_jenkins)
export(use_lgpl_license)
export(use_lifecycle_badge)
export(use_logo)
export(use_make)
export(use_mit_license)
export(use_namespace)
export(use_news_md)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# usethis (development version)

* `use_make()` and `use_jenkins()` add a Makefile and Jenkinsfile, respectively
(@ryapric, #501)

# usethis 1.5.0

## Git, GitHub (and GitLab)
Expand Down
19 changes: 19 additions & 0 deletions R/jenkins.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Create Jenkinsfile for Jenkins CI Pipelines
#'
#' `use_jenkins()` adds a basic Jenkinsfile for R packages to the project root
#' directory. The Jenkinsfile stages take advantage of calls to `make`, and so
#' calling this function will also run `use_make()` if a Makefile does not
#' already exist at the project root.
#'
#' @seealso The [documentation on Jenkins
#' Pipelines](https://jenkins.io/doc/book/pipeline/jenkinsfile).
#' @seealso [use_make()]
#' @export
use_jenkins <- function() {
use_make()
use_template(
"Jenkinsfile",
data = list(name = project_name())
)
use_build_ignore("Jenkinsfile")
}
19 changes: 19 additions & 0 deletions R/make.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Create Makefile
#'
#' `use_make()` adds a basic Makefile to the project root directory.
#'
#' @seealso The [documentation for GNU
#' Make](https://www.gnu.org/software/make/manual/html_node).
#' @export
use_make <- function() {
use_template(
"Makefile",
data = list(name = project_name())
)
use_build_ignore("Makefile")
}

uses_make <- function(base_path = proj_get()) {
makefile_path <- proj_path("Makefile")
file_exists(makefile_path)
}
21 changes: 21 additions & 0 deletions inst/templates/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pipeline {
agent any {
stages {
stage('Build') {
steps {
make build
}
}
stage('Check') {
steps {
make check
}
}
stage('Clean') {
steps {
make clean
}
}
}
}
}
26 changes: 26 additions & 0 deletions inst/templates/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# h/t to @jimhester and @yihui for this parse block:
# https://github.com/yihui/knitr/blob/dc5ead7bcfc0ebd2789fe99c527c7d91afb3de4a/Makefile#L1-L4
# Note the portability change as suggested in the manual:
# https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Writing-portable-packages
PKGNAME = `sed -n "s/Package: *\([^ ]*\)/\1/p" DESCRIPTION`
PKGVERS = `sed -n "s/Version: *\([^ ]*\)/\1/p" DESCRIPTION`


all: check

build:
R CMD build .

check: build
R CMD check --no-manual $(PKGNAME)_$(PKGVERS).tar.gz

install_deps:
Rscript \
-e 'if (!requireNamespace("remotes") install.packages("remotes")' \
-e 'remotes::install_deps(dependencies = TRUE)'

install: install_deps build
R CMD INSTALL $(PKGNAME)_$(PKGVERS).tar.gz

clean:
@rm -rf $(PKGNAME)_$(PKGVERS).tar.gz $(PKGNAME).Rcheck
19 changes: 19 additions & 0 deletions man/use_jenkins.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/use_make.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/test-use-jenkins.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
context("use_jenkins")

test_that("use_jenkins() creates a Makefile AND a Jenkinsfile at project root", {
pkg <- scoped_temporary_package()
use_jenkins()
expect_proj_file("Makefile")
expect_proj_file("Jenkinsfile")
})
7 changes: 7 additions & 0 deletions tests/testthat/test-use-make.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
context("use_makefile")

test_that("use_make() creates a Makefile at project root", {
pkg <- scoped_temporary_package()
use_make()
expect_proj_file("Makefile")
})