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

Refactor use_tic() #193

Merged
merged 18 commits into from
Nov 27, 2019
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ before_install:
- R -q -e 'remotes::install_local(getwd(), force = TRUE); print(tic::dsl_load()); tic::prepare_all_stages()'
- R -q -e 'tic::before_install()'
install: R -q -e 'tic::install()'
after_install: R -q -e 'tic::after_install()'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stage is not supported (anymore) by Travis. Discovered this by running the official Travis lintr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintaining multiple .yml templates for each CI platform seems like a nightmare in the long run. Is there any chance to generalize this?

We could trim it down to one file for "build", "deploy" and "meta" (matrix, libs) and cat them together when building the template. This way, we would only have to maintain three files at max per CI provider.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

before_script: R -q -e 'tic::before_script()'
script: R -q -e 'tic::script()'
after_success: R -q -e 'tic::after_success()'
Expand All @@ -30,8 +29,7 @@ after_script: R -q -e 'tic::after_script()'

# Header
language: r
sudo: false
dist: xenial
dist: bionic
cache: packages
latex: false

Expand Down Expand Up @@ -61,11 +59,8 @@ jobs:
- r: 3.4
- r: 3.3
- r: 3.2


#matrix: Early abortion of failed builds
matrix:
fast_finish: true


#services
services:
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ Description: Provides a way to describe common build and
deployment workflows for R-based projects: packages, websites (e.g.
blogdown, pkgdown), or data processing (e.g. research compendia). The
recipe is described independent of the continuous integration tool
used for processing the workflow (e.g. 'Travis CI' or
'AppVeyor').
used for processing the workflow (e.g. 'Travis CI' or 'AppVeyor').
License: GPL (>= 2)
URL: https://github.com/ropenscilabs/tic
BugReports: https://github.com/ropenscilabs/tic/issues
Expand All @@ -54,6 +53,7 @@ Suggests:
base64enc,
bookdown,
callr,
circle,
covr,
devtools,
drat,
Expand All @@ -67,8 +67,9 @@ Suggests:
travis (>= 0.2.11.9001),
usethis
VignetteBuilder:
knitr
knitr
Remotes:
pat-s/circle,
ropenscilabs/travis
ByteCompile: No
Encoding: UTF-8
Expand Down Expand Up @@ -107,5 +108,6 @@ Collate:
'steps-write-text-file.R'
'tic-package.R'
'travis.R'
'use-yaml.R'
'use_tic.R'
'utils.R'
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ export(step_setup_push_deploy)
export(step_setup_ssh)
export(step_test_ssh)
export(step_write_text_file)
export(use_appveyor_yml)
export(use_circle_yml)
export(use_tic)
export(use_travis_deploy)
export(use_travis_yml)
import(backports)
import(cli)
import(rlang)
Expand Down
95 changes: 95 additions & 0 deletions R/use-yaml.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#' @title Use CI YAML templates
#' @description Installs YAML templates for various CI providers.
#'
#' @param type `[character]`\cr
#' Which template to use. The string should be given following the logic
#' `<provider>-<platform>-<action>`. See details for more.
#'
#' @section Type:
#' `tic` supports a variety of different YAML templates which follow the
#' `<provider>-<platform>-<action>` pattern. The first one is mandatory, the
#' others are optional.
#'
#' * Possible values for `<provider>` are `travis`, and `circle`
#' * Possible values for `<platform>` are `linux`, and `macos`, `windows`.
#' * Possible values for `<action>` are `matrix` and `deploy`.
#'
#' Not every combinations is supported on all CI systems.
#' For example, for `use_appveyor_yaml()` only `windows` and `windows-matrix` are valid.
#'
#' @name yaml-templates
#' @export
use_travis_yml <- function(type) {
if (type == "linux") {
template = "travis-linux.yml"
} else if (type == "linux-matrix") {
template = "travis-linux-matrix.yml"
} else if (type == "linux-deploy") {
template = "travis-linux-deploy.yml"
} else if (type == "linux-deploy-matrix") {
template = "travis-linux-deploy-matrix.yml"
} else if (type == "macos") {
template = "travis-macos.yml"
} else if (type == "macos-matrix") {
template = "travis-macos-matrix.yml"
} else if (type == "macos-deploy") {
template = "travis-macos-deploy.yml"
} else if (type == "macos-deploy-matrix") {
template = "travis-macos-deploy-matrix.yml"
}
use_tic_template(
template,
save_as = ".travis.yml",
data = list(install_tic = double_quotes(get_install_tic_code()))
)
}

#' @rdname yaml-templates
#' @export
use_appveyor_yml <- function(type) {
if (type == "windows") {
template = "appveyor.yml"
} else if (type == "windows-matrix") {
template = "appveyor-matrix.yml"
}
use_tic_template(
template,
save_as = "appveyor.yml",
data = list(install_tic = get_install_tic_code())
)
}

#' @rdname yaml-templates
#' @export
use_circle_yml <- function(type) {
if (type == "linux") {
template = "circle.yml"
} else if (type == "linux-matrix") {
template = "circle-matrix.yml"
} else if (type == "linux-deploy") {
template = "circle-deploy.yml"
} else if (type == "linux-deploy-matrix") {
template = "circle-deploy-matrix.yml"
}
dir.create(".circleci", showWarnings = FALSE)
use_tic_template(
template,
save_as = ".circleci/config.yml",
data = list(install_tic = get_install_tic_code())
)

# FIXME: upstream issue in _whisker_ pkg which cannot handle curly braces
# https://github.com/edwindj/whisker/issues/20
tx <- readLines(sprintf("%s/.circleci/config.yml", usethis::proj_path()))
tx2 <- gsub(pattern = "checksum", replacement = "{{ checksum", x = tx)
tx2 <- gsub(pattern = '_tmp_file"', replacement = '_tmp_file" }}', x = tx2)
writeLines(tx2, con=sprintf("%s/.circleci/config.yml", usethis::proj_path()))
}

use_tic_template <- function(template, save_as = template, open = FALSE,
ignore = TRUE, data = NULL) {
usethis::use_template(
template, save_as,
package = "tic", open = open, ignore = ignore, data = data
)
}
Loading