Skip to content

Commit 755f366

Browse files
committed
added github action support
1 parent 5bb0cf5 commit 755f366

File tree

9 files changed

+111
-21
lines changed

9 files changed

+111
-21
lines changed

.buildlibrary

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
ValidationKey: '1303260'
1+
ValidationKey: '1489520'
22
AcceptedWarnings:
33
- 'Warning: package ''.*'' was built under R version'
44
- 'Warning: namespace ''.*'' is not available and has been replaced'
55
AcceptedNotes: unable to verify current time
66
AutocreateReadme: yes
7+
UseGithubActions: yes

.zenodo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"title": "lucode2: Code Manipulation and Analysis Tools",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"description": "<p>A collection of tools which allow to manipulate and analyze code.<\/p>",
55
"creators": [
66
{

DESCRIPTION

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
Package: lucode2
22
Type: Package
33
Title: Code Manipulation and Analysis Tools
4-
Version: 0.7.0
5-
Date: 2020-12-22
4+
Version: 0.8.0
5+
Date: 2020-12-23
66
Authors@R: c(person("Jan Philipp", "Dietrich", email = "[email protected]", role = c("aut","cre")),
77
person("David", "Klein", role = "aut"),
88
person("Anastasis", "Giannousakis", role = "aut"),
99
person("Markus", "Bonsch", role = "aut"),
1010
person("Benjamin Leon", "Bodirsky", role = "aut"),
1111
person("Lavinia", "Baumstark", role = "aut"))
1212
Description: A collection of tools which allow to manipulate and analyze code.
13-
Imports: citation, data.table, desc, dplyr, rlang, yaml
14-
Suggests: devtools, ggplot2, gtools, lusweave, magclass, testthat
13+
Imports:
14+
citation,
15+
data.table,
16+
desc,
17+
dplyr,
18+
rlang,
19+
usethis,
20+
yaml
21+
Suggests:
22+
devtools,
23+
ggplot2,
24+
gtools,
25+
lusweave,
26+
magclass,
27+
testthat,
28+
covr
1529
URL: https://github.com/pik-piam/lucode2
1630
BugReports: https://github.com/pik-piam/lucode2/issues
1731
License: BSD_2_clause + file LICENSE
1832
LazyData: no
1933
Encoding: UTF-8
2034
RoxygenNote: 7.1.1
21-

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export(SystemCommandAvailable)
44
export(addEOF)
5+
export(addGitHubActions)
56
export(buildLibrary)
67
export(findCoupledruns)
78
export(findIterations)
@@ -42,6 +43,8 @@ importFrom(dplyr,mutate)
4243
importFrom(dplyr,rename)
4344
importFrom(dplyr,summarize)
4445
importFrom(rlang,.data)
46+
importFrom(usethis,use_coverage)
47+
importFrom(usethis,use_github_action)
4548
importFrom(utils,available.packages)
4649
importFrom(utils,capture.output)
4750
importFrom(utils,citation)

R/addGitHubActions.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#' addGitHubActions
2+
#'
3+
#' adds GitHubActions with a standard workflow including codecov to the package. It will add a standard
4+
#' Github action "test-buildlibrary.yml" to the project which performs standard tests as well as
5+
#' creates a coverage report. This file is overwritten automatically each time this function is run and
6+
#' should not be edited by hand. But additional Github actions can be added as separate files.
7+
#'
8+
#' In addition, this function adds a codecov.yml to the repository, if not already existing. This file
9+
#' is only created, if missing and can be edited manually.
10+
#'
11+
#' @param lib Path to the package
12+
#'
13+
#' @author Jan Philipp Dietrich
14+
#' @seealso \code{\link{buildLibrary}}
15+
#' @importFrom usethis use_github_action use_coverage
16+
#' @examples
17+
#' \dontrun{addGitHubActions()}
18+
#' @export
19+
addGitHubActions <- function(lib="."){
20+
standardactionfile <- paste0(lib,"/.github/workflows/test-buildlibrary.yaml")
21+
if(file.exists(standardactionfile)) file.remove(standardactionfile)
22+
usethis::use_github_action(url=system.file("extdata/test-buildlibrary.yaml",package="lucode2"),
23+
save_as="test-buildlibrary.yaml")
24+
if(!file.exists(paste0(lib,"/codecov.yml"))) {
25+
usethis::use_coverage("codecov")
26+
file.copy(system.file("extdata/codecov.yml", package="lucode2"),paste0(lib,"/codecov.yml"), overwrite = TRUE)
27+
}
28+
}
29+

R/buildLibrary.R

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,20 @@ buildLibrary<-function(lib=".",cran=TRUE, update_type=NULL){
4646
return(s);
4747
}
4848

49-
didYouPull <- function() {
50-
cat("Is your repository up-to-date? Did you pull immediately before running this check? (yes/no)")
49+
askYesNo <- function(question) {
50+
cat(paste(question,"(yes/no)"))
5151
s <- get_line()
52-
if(!(tolower(s) %in% c("y","yes"))) stop("Please update your repository first, before you proceed!")
52+
if(!(tolower(s) %in% c("y","yes"))) return(FALSE)
53+
return(TRUE)
54+
}
55+
56+
didYouPull <- function() {
57+
if(!askYesNo("Is your repository up-to-date? Did you pull immediately before running this check?")){
58+
stop("Please update your repository first, before you proceed!")
59+
}
5360
}
5461
didYouPull()
5562

56-
OS<-Sys.info()["sysname"]
5763
thisdir<-getwd()
5864
if(lib!=".") setwd(lib)
5965
on.exit(setwd(thisdir))
@@ -78,7 +84,6 @@ buildLibrary<-function(lib=".",cran=TRUE, update_type=NULL){
7884
############################################################
7985
#check the library
8086
############################################################
81-
ck <- devtools::check(".",cran=cran)
8287

8388
if(!file.exists(".buildlibrary")) {
8489
# if not yet available, add .buildlibrary and add to .Rbuildignore
@@ -99,11 +104,30 @@ buildLibrary<-function(lib=".",cran=TRUE, update_type=NULL){
99104
}
100105

101106
cfg <- read_yaml(".buildlibrary")
107+
102108
if(is.null(cfg$AutocreateReadme)) cfg$AutocreateReadme <- TRUE
109+
if(is.null(cfg$UseGithubActions) &&
110+
askYesNo("Do you want to use GitHub Actions for package testing?")) cfg$UseGithubActions <- TRUE
111+
112+
if(isTRUE(cfg$UseGithubActions)) {
113+
addGitHubActions(lib)
114+
# remove travis related parts
115+
travisfile <- paste0(lib,"/.travis.yml")
116+
if(file.exists(travisfile)) {
117+
file.remove(travisfile)
118+
rbuildignore <- paste0(lib,"/.Rbuildignore")
119+
if(file.exists(rbuildignore)) {
120+
a <- readLines(rbuildignore)
121+
writeLines(grep("travis",a,value=TRUE,invert=TRUE), rbuildignore)
122+
}
123+
travistest <- paste0(lib,"/tests/testthat/test-travisCI.R")
124+
if(file.exists(travistest)) file.remove(travistest)
125+
}
126+
}
127+
128+
ck <- devtools::check(".",cran=cran)
103129

104130
#Filter warnings and notes which are accepted
105-
accepted_warnings <- c("Warning: package '.*' was built under R version",
106-
"Warning: namespace '.*' is not available and has been replaced")
107131
for(aw in cfg$AcceptedWarnings) {
108132
ck$warnings <- grep(aw, ck$warnings, value=TRUE,invert=TRUE)
109133
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code Manipulation and Analysis Tools
22

3-
R package **lucode2**, version **0.7.0**
3+
R package **lucode2**, version **0.8.0**
44

55
[![CRAN status](https://www.r-pkg.org/badges/version/lucode2)](https://cran.r-project.org/package=lucode2) [![R build status](https://github.com/pik-piam/lucode2/workflows/check/badge.svg)](https://github.com/pik-piam/lucode2/actions) [![codecov](https://codecov.io/gh/pik-piam/lucode2/branch/master/graph/badge.svg)](https://codecov.io/gh/pik-piam/lucode2)
66

@@ -39,7 +39,7 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi
3939
To cite package **lucode2** in publications use:
4040

4141
Dietrich J, Klein D, Giannousakis A, Bonsch M, Bodirsky B, Baumstark L (2020). _lucode2: Code Manipulation and
42-
Analysis Tools_. R package version 0.7.0.
42+
Analysis Tools_. R package version 0.8.0.
4343

4444
A BibTeX entry for LaTeX users is
4545

@@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
4848
title = {lucode2: Code Manipulation and Analysis Tools},
4949
author = {Jan Philipp Dietrich and David Klein and Anastasis Giannousakis and Markus Bonsch and Benjamin Leon Bodirsky and Lavinia Baumstark},
5050
year = {2020},
51-
note = {R package version 0.7.0},
51+
note = {R package version 0.8.0},
5252
}
5353
```
5454

inst/extdata/codecov.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
coverage:
3+
precision: 2
4+
round: down
5+
range: "0...95"
6+
status:
7+
project:
8+
default:
9+
target: auto
10+
threshold: 1%
11+
informational: true
12+
patch:
13+
default:
14+
target: auto
15+
threshold: 1%
16+
informational: true

inst/extdata/test-buildlibrary.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
- uses: r-lib/actions/setup-r@v1
2222

2323
- uses: r-lib/actions/setup-pandoc@v1
24+
25+
- name: Install dependencies
26+
run: |
27+
sudo apt-get install libcurl4-openssl-dev libgit2-dev
2428
2529
- name: Query dependencies
2630
run: |
@@ -36,12 +40,12 @@ jobs:
3640
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
3741
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
3842

39-
- name: Install dependencies
43+
- name: Install R dependencies
4044
run: |
4145
repos <- c("https://cloud.r-project.org","https://rse.pik-potsdam.de/r/packages/")
42-
install.packages(c("remotes","lucode2"), repos=repos)
46+
install.packages(c("remotes"), repos=repos)
4347
remotes::install_deps(dependencies = TRUE, repos=repos)
44-
remotes::install_cran("covr")
48+
remotes::install_cran(c("covr","lucode2"), repos=repos)
4549
shell: Rscript {0}
4650

4751
- name: Test coverage
@@ -51,4 +55,4 @@ jobs:
5155
- name: Validation key
5256
run: if(!lucode2:::validkey()$valid) stop("Invalid build key!")
5357
shell: Rscript {0}
54-
58+

0 commit comments

Comments
 (0)