Skip to content

Commit

Permalink
copied over from Roche/respectables (#43)
Browse files Browse the repository at this point in the history
* copied over from Roche/respectables

* Use R 4.1.0 for pkgdown

* Add staged.deps install logic

* Update working dir

Co-authored-by: Adrian Waddell <[email protected]>
Co-authored-by: Dinakar <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2021
1 parent d4a1f2c commit 3a79593
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 1 deletion.
1 change: 0 additions & 1 deletion .github/workflows/build-check-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ jobs:
} else {
remotes::install_deps(dependencies = TRUE, upgrade = "never", Ncpus = ncores)
}
if (file.exists("staged_dependencies.yaml")) {
cat("\nInstall Staged Dependencies\n\n\n")
if (!require("staged.dependencies")) {
Expand Down
134 changes: 134 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Pkgdown Docs

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
pkgdown:
name: Generate
runs-on: ubuntu-latest
container:
image: ghcr.io/insightsengineering/rstudio_4.1.0_bioc_3.13:latest
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Gather info from PR
uses: actions/github-script@v4
id: get-pr
if: github.event_name == 'pull_request'
with:
script: |
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
}
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
try {
const result = await github.pulls.get(request)
return result.data
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
- name: Install remotes R package if needed
run: |
options(repos = c(CRAN = "https://cloud.r-project.org/"))
ncores <- parallel::detectCores(all.tests = FALSE, logical = TRUE)
cat(paste("\n\nnumber of cores detected:", ncores, "\n\n"))
if (!require("remotes")) install.packages("remotes", upgrade = "never", Ncpus = ncores)
shell: Rscript {0}
env:
GITHUB_PAT: ${{ secrets.REPO_GITHUB_TOKEN }} # or ${{ secrets.GITHUB_TOKEN }}


- name: Checkout repo during PR
uses: actions/checkout@v2
if: github.event_name == 'pull_request'
with:
repository: ${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }}
ref: ${{ fromJSON(steps.get-pr.outputs.result).head.ref }}
path: ${{ github.event.repository.name }}

- name: Checkout repo from push
uses: actions/checkout@v2
if: github.event_name == 'push'
with:
path: ${{ github.event.repository.name }}

- name: Install system dependencies for R package
run: |
ubuntu_info <- read.csv("/etc/os-release", sep = "=", header = FALSE)
v_ubuntu_info <- setNames(ubuntu_info$V2, ubuntu_info$V1)
if (v_ubuntu_info[['NAME']] != "Ubuntu") stop("only works on ubuntu")
ubuntu_version <- v_ubuntu_info[['VERSION_ID']]
sys_deps_for_pkg <- remotes::system_requirements("ubuntu", ubuntu_version, path = "${{ github.event.repository.name }}")
sys_pgks <- gsub("^apt-get install -y ", "", sys_deps_for_pkg)
has_pkgs <- vapply(sys_pgks, function(pkg) system2("dpkg", c("-l", pkg), stdout = NULL, stderr = NULL) == 0, logical(1))
if (any(!has_pkgs)) {
system2("apt-get", "update")
system2("apt-get", c("install", "-y", sys_pgks[!has_pkgs]))
}
shell: Rscript {0}

- name: Install R package dependencies
run: |
setwd("${{ github.event.repository.name }}")
options(repos = c(CRAN = "https://cloud.r-project.org/"))
ncores <- parallel::detectCores(all.tests = FALSE, logical = TRUE)
cat(paste("\n\nnumber of cores detected:", ncores, "\n\n"))
if (file.exists("renv.lock")) {
renv::restore()
} else {
remotes::install_deps(dependencies = TRUE, upgrade = "never", Ncpus = ncores)
}
if (file.exists("staged_dependencies.yaml")) {
cat("\nInstall Staged Dependencies\n\n\n")
if (!require("staged.dependencies")) {
remotes::install_github("openpharma/staged.dependencies", ref = "v0.2", Ncpus = ncores, upgrade = "never")
}
cat("\nCalculating Staged Dependency Table...\n\n")
x <- staged.dependencies::dependency_table()
print(x, width = 120)
cat("\n\n")
staged.dependencies::install_deps(dep_structure = x, install_project = FALSE, verbose = TRUE)
}
shell: Rscript {0}
env:
GITHUB_PAT: ${{ secrets.REPO_GITHUB_TOKEN }}

- name: Install R package
run: R CMD INSTALL ${{ github.event.repository.name }}
shell: bash

- name: Build docs
run: |
options(repos = c(CRAN = "https://cloud.r-project.org/"))
"pkgdown" %in% installed.packages() || install.packages("pkgdown", upgrade = "never")
pkgdown::build_site("${{ github.event.repository.name }}", devel = TRUE)
shell: Rscript {0}

- name: Upload docs for review
if: github.ref != 'refs/heads/main' # Only during PR
uses: actions/upload-artifact@v2
with:
name: docs
path: ${{ github.event.repository.name }}/docs/

- name: Publish docs
if: github.ref == 'refs/heads/main' # Only after merge or push to master
run: |
cd ${{ github.event.repository.name }}
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'

0 comments on commit 3a79593

Please sign in to comment.