Sync styles first (#494)
authorFrançois Michonneau <francois.michonneau@gmail.com>
Sat, 22 Aug 2020 05:11:22 +0000 (07:11 +0200)
committerGitHub <noreply@github.com>
Sat, 22 Aug 2020 05:11:22 +0000 (01:11 -0400)
Co-authored-by: Maxim Belkin <maxim.belkin@gmail.com>
.github/workflows/template.yml
Makefile
bin/dependencies.R
bin/install_r_deps.sh [new file with mode: 0755]

index 80a68aa69f07bc52de6617d50e7eb769982c8ca5..13f03bcf8b937c159513b823c75fa9d3997cc4a1 100644 (file)
@@ -16,6 +16,8 @@ jobs:
     defaults:
       run:
         shell: bash # forces 'Git for Windows' on Windows
+    env:
+      RSPM: 'https://packagemanager.rstudio.com/cran/__linux__/bionic/latest'
     steps:
       - name: Set up Ruby
         uses: actions/setup-ruby@main
@@ -46,6 +48,26 @@ jobs:
           path: lesson
           fetch-depth: 0
 
+      - name: Determine the proper reference to use
+        id: styles-ref
+        run: |
+          if [[ -n "${{ github.event.pull_request.number }}" ]]; then
+            echo "::set-output name=ref::refs/pull/${{ github.event.pull_request.number }}/head"
+          else
+            echo "::set-output name=ref::gh-pages"
+          fi
+
+      - name: Sync lesson with carpentries/styles
+        working-directory: lesson
+        run: |
+          git config --global user.email "team@carpentries.org"
+          git config --global user.name "The Carpentries Bot"
+          git remote add styles https://github.com/carpentries/styles.git
+          git config --local remote.styles.tagOpt --no-tags
+          git fetch styles ${{ steps.styles-ref.outputs.ref }}:styles-ref
+          git merge -s recursive -Xtheirs --no-commit styles-ref
+          git commit -m "Sync lesson with carpentries/styles"
+
       - name: Look for R-markdown files
         id: check-rmd
         working-directory: lesson
@@ -61,7 +83,7 @@ jobs:
       - name: Install needed packages
         if: steps.check-rmd.outputs.count != 0
         run: |
-          install.packages(c('remotes', 'rprojroot', 'renv', 'desc'))
+          install.packages(c('remotes', 'rprojroot', 'renv', 'desc', 'rmarkdown', 'knitr'))
         shell: Rscript {0}
 
       - name: Query dependencies
@@ -89,36 +111,8 @@ jobs:
         run: |
           while read -r cmd
           do
-            eval $cmd
+            eval sudo $cmd
           done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "18.04"), sep = "\n")')
 
-      - name: Install R lessons package dependencies
-        if: steps.check-rmd.outputs.count != 0
-        working-directory: lesson
-        run: |
-          remotes::install_deps(dependencies = TRUE)
-          file.remove("DESCRIPTION")
-        shell: Rscript {0}
-
-      - name: Determine the proper reference to use
-        id: styles-ref
-        run: |
-          if [[ -n "${{ github.event.pull_request.number }}" ]]; then
-            echo "::set-output name=ref::refs/pull/${{ github.event.pull_request.number }}/head"
-          else
-            echo "::set-output name=ref::gh-pages"
-          fi
-
-      - name: Sync lesson with carpentries/styles
-        working-directory: lesson
-        run: |
-          git config --global user.email "team@carpentries.org"
-          git config --global user.name "The Carpentries Bot"
-          git remote add styles https://github.com/carpentries/styles.git
-          git config --local remote.styles.tagOpt --no-tags
-          git fetch styles ${{ steps.styles-ref.outputs.ref }}:styles-ref
-          git merge -s recursive -Xtheirs --no-commit styles-ref
-          git commit -m "Sync lesson with carpentries/styles"
-
       - run: make site
         working-directory: lesson
index 1407962ca27c9a35a384463d41647f304bad7e9b..d35f08f59925c4f4cb352f424781878ed8b496fd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,7 @@ endif
 
 
 # Controls
-.PHONY : commands clean files install-rmd-deps
+.PHONY : commands clean files
 
 # Default target
 .DEFAULT_GOAL := commands
@@ -93,7 +93,7 @@ workshop-check :
 ## III. Commands specific to lesson websites
 ## =================================================
 
-.PHONY : lesson-check lesson-md lesson-files lesson-fixme
+.PHONY : lesson-check lesson-md lesson-files lesson-fixme install-rmd-deps
 
 # RMarkdown files
 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
@@ -121,12 +121,12 @@ HTML_DST = \
 
 ## * install-rmd-deps : Install R packages dependencies to build the RMarkdown lesson
 install-rmd-deps:
-       Rscript -e 'source("bin/dependencies.R"); install_dependencies(identify_dependencies())'
+       @${SHELL} bin/install_r_deps.sh
 
 ## * lesson-md        : convert Rmarkdown files to markdown
 lesson-md : ${RMD_DST}
 
-_episodes/%.md: _episodes_rmd/%.Rmd install-rmd-dependencies
+_episodes/%.md: _episodes_rmd/%.Rmd install-rmd-deps
        @mkdir -p _episodes
        @bin/knit_lessons.sh $< $@
 
index b710558f7f10989f4722d37a9014143edf4727cd..676b05055cdbcd29f654e097a55d3020a406c927 100644 (file)
@@ -1,23 +1,28 @@
-find_root <- function() {
-  if (!requireNamespace("rprojroot", quietly = TRUE)) {
-    install.packages("rprojroot", lib = lib, repos = repos)
+install_required_packages <- function(lib = NULL, repos = getOption("repos")) {
+
+  if (is.null(lib)) {
+    lib <- .libPaths()
   }
 
+  message("lib paths: ", paste(lib, collapse = ", "))
+  missing_pkgs <- setdiff(
+    c("rprojroot", "desc", "remotes", "renv"),
+    rownames(installed.packages(lib.loc = lib))
+  )
+
+  install.packages(missing_pkgs, lib = lib, repos = repos)
+
+}
+
+find_root <- function() {
+
   cfg  <- rprojroot::has_file_pattern("^_config.y*ml$")
   root <- rprojroot::find_root(cfg)
 
   root
 }
 
-identify_dependencies <- function(lib = NULL, repos = getOption("repos")) {
-
-  if (is.null(lib)) {
-    lib <- .libPaths()
-  }
-
-  if (!requireNamespace("renv", quietly = TRUE)) {
-    install.packages("renv", lib = lib, repos = repos)
-  }
+identify_dependencies <- function() {
 
   root <- find_root()
 
@@ -31,38 +36,20 @@ identify_dependencies <- function(lib = NULL, repos = getOption("repos")) {
   required_pkgs
 }
 
-install_dependencies <- function(required_pkgs,
-                                 lib = NULL, repos = getOption("repos"),
-                                 update = FALSE, ...) {
-
-  if (missing(lib))  {
-    lib <- .libPaths()
-  }
+create_description <- function(required_pkgs) {
+  d <- desc::description$new("!new")
+  lapply(required_pkgs, function(x) d$set_dep(x))
+  d$write("DESCRIPTION")
+}
 
-  missing_pkgs <- setdiff(required_pkgs, rownames(installed.packages()))
+install_dependencies <- function(required_pkgs, ...) {
 
-  if (length(missing_pkgs)) {
-    message("Installing missing required packages: ",
-      paste(missing_pkgs, collapse=", "))
-    install.packages(missing_pkgs, lib = lib, repos = repos)
-  }
-
-  if (update) {
-    update.packages(
-      lib.loc = lib, repos = repos,
-      ask = FALSE, checkBuilt = TRUE, ...
-    )
-  }
+  create_description(required_pkgs)
+  on.exit(file.remove("DESCRIPTION"))
+  remotes::install_deps(dependencies = TRUE, ...)
 
   if (require("knitr") && packageVersion("knitr") < '1.9.19') {
     stop("knitr must be version 1.9.20 or higher")
   }
 
 }
-
-create_description <- function(required_pkgs) {
-  require("desc")
-  d <- description$new("!new")
-  lapply(required_pkgs, function(x) d$set_dep(x))
-  d$write("DESCRIPTION")
-}
diff --git a/bin/install_r_deps.sh b/bin/install_r_deps.sh
new file mode 100755 (executable)
index 0000000..0280f24
--- /dev/null
@@ -0,0 +1 @@
+Rscript -e "source(file.path('bin', 'dependencies.R')); install_required_packages(); install_dependencies(identify_dependencies())"