From bdb177f8f5d7279a6f8684806319efedbcbacf75 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Thu, 13 Aug 2020 16:23:34 -0700 Subject: [PATCH] Use GHA workflow from Mastering Shiny --- .Rbuildignore | 1 + .github/.gitignore | 1 + .github/workflows/build-book.yaml | 63 +++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/build-book.yaml diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf2f..3912071b4 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,3 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 000000000..2d19fc766 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/build-book.yaml b/.github/workflows/build-book.yaml new file mode 100644 index 000000000..f9ef1f10b --- /dev/null +++ b/.github/workflows/build-book.yaml @@ -0,0 +1,63 @@ +on: + push: + branches: '*' + schedule: + # run every day at 11 PM + - cron: '0 23 * * *' + +name: build-book + +jobs: + build: + runs-on: macOS-latest + steps: + - name: Checkout repo + uses: actions/checkout@master + + - name: Setup R + uses: r-lib/actions/setup-r@master + with: + r-version: 'release' + + - name: Install pandoc and pandoc citeproc + run: | + brew install pandoc + brew install pandoc-citeproc + + - name: Cache R packages + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: r-4-${{ hashFiles('DESCRIPTION') }} + restore-keys: r-4- + + - name: Cache bookdown results + uses: actions/cache@v1 + with: + path: _bookdown_files + key: bookdown-2-${{ hashFiles('**/*Rmd') }} + restore-keys: bookdown-2- + + - name: Install packages + run: | + R -e 'install.packages("remotes")' + R -e 'install.packages("ps", type = "binary")' + R -e 'remotes::install_deps(dependencies = TRUE)' + + - name: Install PhantomJS + run: R -e 'webshot::install_phantomjs()' + + - name: Build site + run: Rscript -e 'bookdown::render_book("index.Rmd", quiet = TRUE)' + + - name: Install npm + uses: actions/setup-node@v1 + + - name: Deploy to Netlify + # NETLIFY_AUTH_TOKEN added in the repo's secrets + env: + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + run: | + npm install netlify-cli -g + netlify deploy --prod --dir _book