caching R packages in workflow #116
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (C) 2022 Léo Gorman | |
# | |
# This file is part of rhomis-data-app. | |
# | |
# rhomis-data-app is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# rhomis-data-app is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with rhomis-data-app. If not, see <http://www.gnu.org/licenses/>. | |
name: Deploy Bookdown docs | |
on: | |
push: | |
branches: | |
- bookdown-docs | |
- main | |
jobs: | |
build-book: | |
name: Render-Book | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: r-lib/actions/setup-r@v2 | |
- uses: r-lib/actions/setup-pandoc@v1 | |
- if: runner.os == 'linux' | |
run: | | |
sudo apt-get install libcurl4-openssl-dev libssl-dev libsasl2-dev libharfbuzz-dev libfribidi-dev -y | |
- 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: Restore R package cache | |
uses: actions/cache@v2 | |
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 system dependencies | |
run: | | |
while read -r cmd | |
do | |
eval sudo $cmd | |
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') | |
- name: Install dependencies | |
run: | | |
remotes::install_deps(dependencies = TRUE) | |
shell: Rscript {0} | |
- name: Render and build book | |
run: | | |
renv::restore() | |
devtools::load_all() | |
setwd("./book") | |
bookdown::render_book(".") | |
shell: Rscript {0} | |
- name: Init new repo in book/_book folder and commit generated files | |
run: | | |
cd book/_book | |
git init | |
git add -A | |
git config --local user.email "[email protected]" | |
git config --local user.name "l-gorman" | |
git commit -m 'deploy' | |
- name: Force push to destination branch | |
uses: ad-m/github-push-action@master | |
with: | |
# Token for the repo | |
# Can be passed in using $\{{ secrets.GITHUB_TOKEN }} | |
github_token: ${{ secrets.PUBLISHBOOKDOWN }} | |
# Destination branch to push changes | |
branch: gh-pages | |
# Force the changes through | |
force: true | |
# Change to the build directory before pushing | |
directory: ./book/_book | |
repository: "rhomis/rhomis-R-package" |