From e378d87743727ba992e8c8b02e5d456a804e4078 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Thu, 15 Oct 2020 21:07:45 -0700 Subject: [PATCH] Switch to GitHub Actions --- .github/.gitignore | 1 + .github/workflows/build-book.yaml | 100 ++++++++++++++++++++++++++++++ .travis.yml | 34 ---------- README.md | 7 ++- 4 files changed, 107 insertions(+), 35 deletions(-) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/build-book.yaml delete mode 100644 .travis.yml diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 00000000..2d19fc76 --- /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 00000000..5c40e2ae --- /dev/null +++ b/.github/workflows/build-book.yaml @@ -0,0 +1,100 @@ +on: + push: + branches: + - master + pull_request: + branches: + - master + schedule: + # run every day at 11 PM + - cron: '0 23 * * *' + +name: build-book + + +jobs: + build: + runs-on: macOS-latest + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + isExtPR: ${{ github.event.pull_request.head.repo.fork == true }} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Setup R + uses: r-lib/actions/setup-r@master + with: + crayon.enabled: 'FALSE' + + - uses: r-lib/actions/setup-pandoc@master + + - name: Get R version + id: get-r-version + run: | + echo "::set-output name=version::$(Rscript -e 'cat(as.character(getRversion()))')" + shell: bash + + - name: Cache R packages + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ steps.get-r-version.outputs.version }}-1- + + - name: Cache bookdown results + uses: actions/cache@v2 + with: + path: _bookdown_files + key: bookdown-9-${{ hashFiles('**/*Rmd') }} + restore-keys: bookdown-9- + + - name: Install pak + run: | + install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/") + shell: Rscript {0} + + - name: Install macOS system dependencies + if: runner.os == 'macOS' + run: | + brew install libgit2 + + - name: Install dependencies + run: | + pak::local_install_dev_deps() + shell: Rscript {0} + + - name: Session info + run: | + options(width = 100) + pkgs <- installed.packages()[, "Package"] + sessioninfo::session_info(pkgs, include_base = TRUE) + shell: Rscript {0} + + - name: Configure Git user + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Build site + run: Rscript -e 'bookdown::render_book("index.Rmd", quiet = TRUE)' + + - name: Copy + run: cp _redirects _book/ + + - name: Deploy to Netlify + if: contains(env.isExtPR, 'false') + id: netlify-deploy + uses: nwtgck/actions-netlify@v1.1 + with: + publish-dir: './_book' + production-branch: master + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: + 'Deploy from GHA: ${{ github.event.pull_request.title || github.event.head_commit.message }} (${{ github.sha }})' + # these all default to 'true' + enable-pull-request-comment: false + enable-commit-comment: false + # enable-commit-status: true + #o verwrites-pull-request-comment: true + timeout-minutes: 1 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a8b00821..00000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: r -sudo: false -cache: - packages: true - directories: - - $HOME/.npm - -before_install: - - nvm install stable - - npm install netlify-cli -g - - export COMMIT_MSG=$(git log -1 --format='%h %<(50,trunc)%s') - - echo $COMMIT_MSG - - export DEPLOY_MSG=${COMMIT_MSG//[\'\"\`]/} - - echo $DEPLOY_MSG - -env: - - NETLIFY_SITE_ID=4e9fea2e-d99c-484e-be1a-9d8605393f4e - # NETLIFY_AUTH_TOKEN set in travis settings - -script: - - Rscript -e 'bookdown::render_book("index.Rmd")' - -deploy: - - provider: script - script: netlify deploy --dir _book --prod --message "$DEPLOY_MSG" - skip_cleanup: true - on: - branch: master - - provider: script - script: netlify deploy --dir _book --message "$DEPLOY_MSG" - skip_cleanup: true - on: - all_branches: true - condition: $TRAVIS_BRANCH != "master" diff --git a/README.md b/README.md index 07487acf..0ac86225 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ Rendered product: - + +[![R build status](https://github.com/jennybc/happy-git-with-r/workflows/build-book/badge.svg)](https://github.com/jennybc/happy-git-with-r/actions) +[![Netlify Status](https://api.netlify.com/api/v1/badges/4e9fea2e-d99c-484e-be1a-9d8605393f4e/deploy-status)](https://app.netlify.com/sites/happygitwithr/deploys) + + + Creative Commons License