Skip to content

Commit

Permalink
Use GitHub actions instead of Travis (#396)
Browse files Browse the repository at this point in the history
* Add R-CMD-check and linting workflows

* Update CI login helper functions

Rather than checking whether they run on travis, check whether they're run on
CI. Both travis and github actions have a "CI" env var set to "true".

* Use API key from secret

* Remove .travis.yml

* Try different way to get python packages installed

* Update .Rprofile to check for CI

Also removes repos; we don't use synapser anymore so I don't think this is needed

* Turn off reticulate autoconfigure

* Put CRAN mirror back

* Put synapseclient name in quotes
  • Loading branch information
karawoo authored Jul 9, 2020
1 parent 560729f commit f73c62b
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 52 deletions.
5 changes: 2 additions & 3 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
.First <- function() {
options(
repos = c(
CRAN = "https://cran.rstudio.com/",
Sage = "http://ran.synapse.org"
CRAN = "https://cran.rstudio.com/"
)
)
}

if (!identical(Sys.getenv("TRAVIS"), "true")) { # don't run on travis
if (!identical(Sys.getenv("CI"), "true")) { # don't run on travis
source("renv/activate.R")
}
105 changes: 105 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
on:
push:
branches:
- master
pull_request:
branches:
- master

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'devel'}
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-16.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.4', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
SYNAPSE_USER: ${{ secrets.SYNAPSE_USER }}
SYNAPSE_APIKEY: ${{ secrets.SYNAPSE_APIKEY }}
RETICULATE_AUTOCONFIGURE: 'FALSE'

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), "depends.Rds", version = 2)
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('depends.Rds') }}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-

- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get -y update
sudo apt-get install -y make python-minimal pandoc pandoc-citeproc git-core libv8-dev libxml2-dev libcurl4-openssl-dev libssl-dev libssh2-1-dev zlib1g-dev
- name: Install system dependencies (macOS)
if: runner.os == 'macOS' && matrix.config.r == 'devel'
run: |
brew install V8
- name: Install dependencies
run: |
library(remotes)
deps <- readRDS("depends.Rds")
deps[["installed"]] <- vapply(deps[["package"]], remotes:::local_sha, character(1))
update(deps)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Install Miniconda
run: |
Rscript -e "remotes::install_github('rstudio/reticulate')"
Rscript -e "reticulate::install_miniconda()"
- name: Add Miniconda to .Rprofile on macOS
if: runner.os == 'macOS'
run: echo "options(reticulate.conda_binary = reticulate:::miniconda_conda())" >> .Rprofile

- name: Install Python deps
run: |
Rscript -e "reticulate::conda_create('r-reticulate', packages = c('python==3.7.0'))"
Rscript -e "remotes::install_local()"
Rscript -e "reticulate::py_install('pandas', pip = TRUE)"
Rscript -e "reticulate::py_install('synapseclient', pip = TRUE)"
- name: Check
run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@master
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
44 changes: 44 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
push:
branches:
- master
pull_request:
branches:
- master

name: lint

jobs:
lint:
runs-on: macOS-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install dependencies
run: |
install.packages(c("remotes"))
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("lintr")
shell: Rscript {0}

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

18 changes: 9 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Check if we are running on travis
on_travis <- function() {
if (identical(Sys.getenv("TRAVIS"), "true")) {
on_ci <- function() {
if (identical(Sys.getenv("CI"), "true")) {
return(TRUE)
# nocov start
} else {
Expand All @@ -10,11 +10,11 @@ on_travis <- function() {
}

## Look up env vars and log in to Synapse
syn_travis_login <- function(syn) {
## Credentials are encrypted on travis
user <- Sys.getenv("SYNAPSE_USER")
pass <- Sys.getenv("SYNAPSE_PASSWORD")
syn$login(email = user, password = pass)
syn_ci_login <- function(syn) {
## Credentials are encrypted
user <- Sys.getenv("SYNAPSE_USER")
apikey <- Sys.getenv("SYNAPSE_APIKEY")
syn$login(email = user, apiKey = apikey)
}

attempt_instantiate <- function() {
Expand All @@ -29,8 +29,8 @@ attempt_instantiate <- function() {
## org, or with regular synLogin() if not on travis. If on travis but not within
## Sage, do nothing.
attempt_login <- function(syn, ...) {
if (on_travis() & !is.null(syn)) {
try(syn_travis_login(syn), silent = TRUE)
if (on_ci() & !is.null(syn)) {
try(syn_ci_login(syn), silent = TRUE)
} else if (reticulate::py_module_available("synapseclient") & !is.null(syn)) {
syn$login(...)
} else {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ context("utils.R")
syn <- attempt_instantiate()
attempt_login(syn)

test_that("on_travis() returns TRUE on Travis", {
expect_equal(on_travis(), isTRUE(as.logical(Sys.getenv("TRAVIS"))))
test_that("on_ci() returns TRUE on Travis", {
expect_equal(on_ci(), isTRUE(as.logical(Sys.getenv("CI"))))
})

test_that("login works on travis in main repo", {
## Lots of other things will fail too if it doesn't, but doesn't hurt to have
## a dedicated test
skip_if_not(on_travis())
skip_if_not(on_ci())

## In this one we do need to ensure it only runs for builds on upstream repo,
## not forks
Expand All @@ -20,7 +20,7 @@ test_that("login works on travis in main repo", {
)
skip_if_not(owner == "Sage-Bionetworks", "Testing on upstream repo")

login <- try(syn_travis_login(syn), silent = TRUE)
login <- try(syn_ci_login(syn), silent = TRUE)
expect_false(inherits(login, "try-error"))
})

Expand Down

0 comments on commit f73c62b

Please sign in to comment.