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

Address ropensci review #213

Merged
merged 51 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
efa078d
save changes
pat-s Oct 2, 2019
814d31d
check for valid DESCRIPTION
pat-s Jan 7, 2020
27dca9e
merge master
pat-s Jan 7, 2020
06323ab
merge master
pat-s Jan 7, 2020
7048575
mention how deps are installed
pat-s Jan 7, 2020
37598fa
add vignette .org vs .com
pat-s Jan 7, 2020
34c3a94
Merge branch 'master' into ropensci-review
pat-s Jan 7, 2020
0d4647b
do not use deps-in-desc hook
pat-s Jan 7, 2020
e58b719
only run steps and macros interactively
pat-s Jan 7, 2020
f7e8a40
ensure that tic.R exists when calling dsl_init()
pat-s Jan 7, 2020
4a6b195
fix checking for DESCRIPTION
pat-s Jan 7, 2020
e8f9d71
file_exists -> file.exists
pat-s Jan 7, 2020
cd333e6
fix stage.R
pat-s Jan 7, 2020
f0efa80
path_file() -> file.path()
pat-s Jan 7, 2020
1d66ea7
forgot usethis::
pat-s Jan 7, 2020
7f1896b
fix doc
pat-s Jan 7, 2020
cd722cb
try running tic functions within repo dir
pat-s Jan 8, 2020
f2f9980
run tests in repo dir
pat-s Jan 8, 2020
84fa09b
dont run bookdown example
pat-s Jan 8, 2020
044dd38
try to solve warninsg about unimported funs
pat-s Jan 8, 2020
7d02908
upd desc
pat-s Jan 8, 2020
12bf148
dontrun do_* examples
pat-s Jan 8, 2020
ab4598a
more dontrun
pat-s Jan 8, 2020
5f659ea
ignore temp pkg dir in tests
pat-s Jan 8, 2020
c917315
more dontrun
pat-s Jan 8, 2020
69d1021
dontrun all examples
pat-s Jan 8, 2020
5dab654
more dontrun
pat-s Jan 8, 2020
c209c87
usethis: imports instead of suggests
pat-s Jan 8, 2020
834b30f
clean
pat-s Jan 8, 2020
67e59e3
Merge branch 'master' into ropensci-review
krlmlr Jan 12, 2020
4740c90
Undo code changes
krlmlr Jan 12, 2020
82c223f
Document
krlmlr Jan 12, 2020
18cb1ee
Undo
krlmlr Jan 12, 2020
94b179f
Undo tests
krlmlr Jan 12, 2020
009dd81
Add new output
krlmlr Jan 12, 2020
bb3fa1a
Best effort
krlmlr Jan 12, 2020
2045cbe
Info
krlmlr Jan 12, 2020
ba86b1a
Typos
krlmlr Jan 12, 2020
da5988c
Show link to help page when creating a clean stage config
krlmlr Jan 12, 2020
2648c5c
Check DESCRIPTION file for steps that need it
krlmlr Jan 12, 2020
8269778
Finale
krlmlr Jan 12, 2020
1b95ccd
Tweak
krlmlr Jan 12, 2020
8c1fd73
Explain
krlmlr Jan 15, 2020
0f7e58d
Pretty error message
krlmlr Jan 15, 2020
1bc4699
Link to vignettes for setup
krlmlr Jan 15, 2020
1adacd0
ropenscilabs -> ropensci
pat-s Jan 15, 2020
3272e18
add review to DESC
pat-s Jan 15, 2020
9cf0e6f
use tidy desc
pat-s Jan 15, 2020
a45bf8d
update links in README
pat-s Jan 15, 2020
4e045f0
add codemetar file
pat-s Jan 15, 2020
0c066f7
acknowledge reviewers
pat-s Jan 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
^\.circleci/config\.yml$
^\.pre-commit-config\.yaml$
^\.lintr$
^tests/testthat/tic$
^\.vscode$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
inst/doc
.DS_Store
.vscode
tests/testthat/tic
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
# R package development
- id: roxygenize
- id: use-tidy-description
- id: deps-in-desc
# - id: deps-in-desc
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
Expand Down
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ Suggests:
git2r,
knitr,
openssl,
pkgdown,
rcmdcheck,
rmarkdown,
rprojroot,
testthat (>= 2.1.0),
travis (>= 0.2.11.9001),
usethis
Expand Down
23 changes: 18 additions & 5 deletions R/dsl-storage.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,24 @@ dslobj_init <- function(envir = parent.frame()) {
}


#' Storage for stages and steps
#' Stages and steps
#'
#' @description
#' \pkg{tic} works in a declarative way, centered around the `tic.R` file
#' created by [use_tic()].
#' This file contains the *definition* of the steps to be run in each stage:
#' calls to [get_stage()] and [add_step()], or macros like
#' [do_package_checks()].
#'
#' Normally, this file is never executed directly.
#' Running these functions in an interactive session will **not** carry out
#' the respective actions.
#' Instead, a description of the code that would have been run is printed
#' to the console.
#' Edit `tic.R` to configure your CI builds.
#' See `vignette("build-lifecycle", package = "tic")` for more details.
#'
#' @details
#' Stages and steps defined using tic's [DSL] are stored in an
#' internal object in the package.
#' The stages are accessible through `dsl_get()`.
Expand Down Expand Up @@ -119,10 +134,8 @@ dsl_load <- function(path = "tic.R", force = FALSE, quiet = FALSE) {
#' @export
dsl_init <- function(quiet = FALSE) {
if (!quiet) {
cat_bullet(
"Creating a blank tic stage configuration",
bullet = "tick", bullet_col = "green"
)
cli_alert_success("Creating a clean tic stage configuration")
cli_alert_info("See {.code ?tic::dsl_get} for details")
}

env <- asNamespace(packageName())
Expand Down
17 changes: 11 additions & 6 deletions R/local.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ LocalCI <- R6Class(

public = list(
get_branch = function() {
system2("git", "rev-parse --abbrev-ref HEAD", stdout = TRUE)
suppressWarnings(system2("git", "rev-parse --abbrev-ref HEAD", stdout = TRUE))
Copy link
Member Author

Choose a reason for hiding this comment

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

Can we add a comment what we are suppressing here?

},
get_tag = function() {
system2("git", "describe", stdout = TRUE)
suppressWarnings(system2("git", "describe", stdout = TRUE))
},
is_tag = function() {
length(system2("git", c("tag", "--points-at", "HEAD"), stdout = TRUE)) > 0
suppressWarnings(length(system2("git", c("tag", "--points-at", "HEAD"), stdout = TRUE)) > 0)
},
get_slug = function() {
remote <- gh::gh_tree_remote()
paste0(remote$username, "/", remote$repo)
tryCatch(
{
remote <- gh::gh_tree_remote()
paste0(remote$username, "/", remote$repo)
},
error = ""
)
Comment on lines +20 to +26
Copy link
Member Author

Choose a reason for hiding this comment

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

What motivated this tryCatch?

},
get_build_number = function() {
"local build"
Expand All @@ -23,7 +28,7 @@ LocalCI <- R6Class(
NULL
},
get_commit = function() {
git2r::revparse_single(revision = "HEAD")$sha
tryCatch(git2r::revparse_single(revision = "HEAD")$sha, error = "")
Copy link
Member Author

Choose a reason for hiding this comment

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

What motivated this tryCatch?

},
can_push = function(name = "TRAVIS_DEPLOY_KEY") {
TRUE
Expand Down
2 changes: 2 additions & 0 deletions R/macro-bookdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,6 @@ do_bookdown <- function(...,
#' @description
#' By default, the `_book/` directory is deployed
#' to the `gh-pages` branch, keeping the history.

dsl_get()
}
2 changes: 2 additions & 0 deletions R/macro-package-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ do_package_checks <- function(...,
get_stage("after_success") %>%
add_code_step(covr::codecov(quiet = FALSE))
}

dsl_get()
}

#' Deprecated functions
Expand Down
2 changes: 2 additions & 0 deletions R/macro-pkgdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,6 @@ do_pkgdown <- function(...,
#' @description
#' By default, the `docs/` directory is deployed to the `gh-pages` branch,
#' keeping the history.

dsl_get()
}
2 changes: 2 additions & 0 deletions R/print.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#' @import cli
#' @export
print.TicStages <- function(x, ...) {
cli_h1("tic configuration")

if (all(vlapply(x, stage_is_empty))) {
cat_bullet(
"No steps defined in any stage",
Expand Down
3 changes: 3 additions & 0 deletions R/stage.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ TicStage <- R6Class( # nolint
},

prepare_all = function() {
# We don't necessarily require a DESCRIPTION file.
# Steps that need one can check beforehand and warn the user with a
# legible message.
lapply(private$steps, private$prepare_one)
invisible()
},
Expand Down
3 changes: 3 additions & 0 deletions R/steps-install.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ InstallDeps <- R6Class(
},

prepare = function() {
if (!file.exists("DESCRIPTION")) {
stopc("No DESCRIPTION file found. The step_install_deps step and the do_package_checks macro are only available for packages.")
Copy link
Member Author

Choose a reason for hiding this comment

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

I recently like to format error messages as

cli_alert_danger("<extended descriptive message>")
stopc("No DESCRIPTION file found.")

The advantage is that you can wrap the extended description and also use cli formatting in it. The plain message in the stop call is then just to state the main reason of the error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

rlang conditions are better here, see ?rlang::cnd_body . Here I'm using the pattern you're suggesting, for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, looks promising.

}
verify_install("remotes")
},

Expand Down
3 changes: 3 additions & 0 deletions R/steps-pkgdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ BuildPkgdown <- R6Class(
},

prepare = function() {
if (!file.exists("DESCRIPTION")) {
stopc("No DESCRIPTION file found. The step_build_pkgdown step and the do_pkgdown macro are only available for packages.")
}
verify_install(c("pkgdown", "remotes"))
super$prepare()
}
Expand Down
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The goal of tic is to enhance and simplify working with continuous integration (

The following ones are supported:

- [Travis CI](https://travis-ci.org) (Linux, macOS)
- [Travis CI](https://travis-ci.org) (both https://travis-ci.org and https://travis-ci.com) (Linux, macOS)
- [AppVeyor](https://www.appveyor.com/) (Windows)
- [Circle CI](https://circleci.com/) (Linux)

Expand All @@ -32,34 +32,47 @@ The most important improvements over existing solutions are:

## Installation

It can be installed from GitHub with:
{tic} can be installed from GitHub with:

```r
# install.packages("remotes")
``` r
remotes::install_github("ropenscilabs/tic")
```

## Setup

By calling `tic::use_tic()` a production ready CI setup is initialized, tailored to your specific R project.
The created templates will use the providers https://travis-ci.org, https://appveyor.com and https://circleci.com.
The created templates will use the providers https://travis-ci.com, https://appveyor.com and https://circleci.com.
For more information about the difference between https://travis-ci.org and https://travis-ci.com see the vignette about [Travis CI '.org' vs '.com'](https://ropenscilabs.github.io/tic/articles/org-vs-com.html).

If only the CI YAML templates from _tic_ are desired, the `use_<provider>_yml()` functions can be used.
If only the CI YAML templates from {tic} are desired, the `use_<provider>_yml()` functions can be used.
Refer to [the complete list of options](https://docs.ropensci.org/tic/reference/yaml-templates.html).

For an R package, the following steps will be set up for the CI workflow:

- Installation of required dependencies for the project
- Satisfying build-time dependencies of steps to be run in all CI stages
- Running `rcmdcheck::rcmdcheck()`
- Building of a `pkgdown` site with deployment GitHub
- Running a code coverage and uploading it to [codecov.io](https://codecov.io/)
- Installation of required dependencies for the project (by checking the mandatory(!) DESCRIPTION file)
- Satisfying build-time dependencies of steps to be run in all CI stages (by scraping `pkg::fun` calls in `tic.R`)
- Checking of package via `rcmdcheck::rcmdcheck()`
- Creation of a `pkgdown` site including Github deployment
- Running a code coverage and upload to [codecov.io](https://codecov.io/)

See the [Getting Started](https://ropenscilabs.github.io/tic/articles/tic.html) vignette for more information and links to [minimal example repositories](https://ropenscilabs.github.io/tic/articles/tic.html#examples-projects) for various R projects (package, blogdown, bookdown and more).

## Good to know

We would like to mention that {tic} is a choice and sits on top of existing community efforts providing R support for various CI providers.
While {tic} will prevent you from dealing/learning every CIs YAML syntax, you will have to learn {tic}'s way of specifying your tasks on CI systems.

Also, there is no way around familiarizing yourself with the basics of CI systems in general.
Without this knowledge, you will also have a hard way understanding {tic}.

There is not yet an automated way of updating the templates installed by {tic}, hence you need to manually check every once in a while if we made some changes to the templates.

We also recommend to take a look at the projects providing the direct R support for each CI system (which {tic} builds upon) to gain a deeper understanding of the whole concept.

## Examples

All examples listed here work with Travis, some work with AppVeyor too. The badges link to the most recent build of the master branch.
All examples listed here work with Travis, some work with AppVeyor too.
The badges link to the most recent build of the master branch.

- [tic.blogdown](https://github.com/ropenscilabs/tic.blogdown): Blogs with [_blogdown_](https://bookdown.org/yihui/blogdown/)

Expand Down Expand Up @@ -120,9 +133,13 @@ All examples listed here work with Travis, some work with AppVeyor too. The badg

- [Custom Steps](https://ropenscilabs.github.io/tic/articles/custom-steps.html)

- [Travis CI '.org' vs '.com'](https://ropenscilabs.github.io/tic/articles/org-vs-com.html)

## Limitations

The setup functions in this package assume Git as version control system, and GitHub as platform. Automated setup works best if the project under test is located in the root of the Git repository. Multi-project repositories are not supported, see [the comment by @jwijffels](https://github.com/ropenscilabs/tic/issues/117#issuecomment-460814990) for guidance to work around this limitation.
The setup functions in this package assume Git as version control system, and GitHub as platform.
Automated setup works best if the project under test is located in the root of the Git repository.
Multi-project repositories are not supported, see [the comment by @jwijffels](https://github.com/ropenscilabs/tic/issues/117#issuecomment-460814990) for guidance to work around this limitation.

---

Expand Down
17 changes: 16 additions & 1 deletion man/dsl_get.Rd

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

4 changes: 2 additions & 2 deletions man/step_build_pkgdown.Rd

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

2 changes: 2 additions & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ navbar:
href: articles/deployment.html
- text: Custom Steps
href: articles/custom-steps.html
- text: Travis CI .org vs .com
href: articles/org-vs-com.html
- text: Changelog
href: news/index.html

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/out/bookdown.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
── install ──────────────────────────────────────────────────────────── stage ──
▶ step_install_deps(repos = repo_default())
── deploy ───────────────────────────────────────────────────────────── stage ──
▶ step_build_bookdown()
7 changes: 7 additions & 0 deletions tests/testthat/out/pkgdown.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
── install ──────────────────────────────────────────────────────────── stage ──
▶ step_install_deps()
▶ step_install_deps(repos = repo_default())
── script ───────────────────────────────────────────────────────────── stage ──
▶ step_rcmdcheck()
── deploy ───────────────────────────────────────────────────────────── stage ──
▶ step_build_pkgdown()
23 changes: 21 additions & 2 deletions vignettes/advanced.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,36 @@ $install
▶ step_install_deps(repos = repo_default())
```


### Emulating a CI run locally

`run_all_stages()` emulates a CI run on your local machine by executing all stages and their corresponding steps as defined in `tic.R`.
A tic configuration can be emulated locally.

First, ensure that all prerequisites are met:

```{r eval = FALSE}
prepare_all_stages()
```

This might install additional packages, or even fail with a descriptive message.

Then, run all steps defined in `tic.R`:

```{r}
run_all_stages()
```

This emulates a CI run on your local machine by executing all stages and their corresponding steps.
Note that this action this will use your local system libraries and not the CI environment.
Only the steps that are shown with `dsl_get()` are executed.
Some steps will not be executed as they are conditioned to run on non-interactive environments only, e.g. `add_step(covr::codcov())` added by the macro `do_package_checks()`.

```{r, eval = FALSE}
run_all_stages()
ℹ Using existing tic stage configuration, use `force = TRUE` to reload
```

```
✓ Loading tic stage configuration from tic.R
Running install: step_install_github("ropensci/rotemplate")
Skipping install of 'rotemplate' from a github remote, the SHA1 (bec3e6eb) has not changed since last install.
Use `force = TRUE` to force installation
Expand Down
2 changes: 1 addition & 1 deletion vignettes/build-lifecycle.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Some important points:
It also does not trigger a CI build.
All commands just define the workflow of the CI build.
- The workflow can be loaded using `dsl_load()`, however this will not run any of the commands defined.
- For testing purposes, all stages and steps defined in `tic.R` can be executed by calling `run_all_stages()`.
- For testing purposes, all stages and steps defined in `tic.R` can be executed by calling `run_all_stages()`.
This emulates a CI build on your local system.
See [Troubleshooting: Running tic locally](advanced#troubleshooting-running-tic-locally) for more information.

Expand Down
Loading