Pachadotdev patch 1 #63
Workflow file for this run
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
on: | |
push: | |
branches: | |
- traduccion | |
pull_request: | |
branches: | |
- traduccion | |
# schedule: | |
# # run every day at 11 PM | |
# - cron: '0 23 * * *' | |
name: Build book | |
env: | |
isExtPR: ${{ github.event.pull_request.head.repo.fork == true }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
- name: Setup pandoc | |
uses: r-lib/actions/setup-pandoc@v2 | |
- name: Get R version | |
id: get-r-version | |
run: echo "version=$(Rscript -e 'cat(as.character(getRversion()))')" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Cache R packages | |
uses: actions/cache@v3 | |
with: | |
path: ${{ env.R_LIBS_USER }} | |
key: ${{ runner.os }}-${{ steps.get-r-version.outputs.version }}-3- | |
- name: Install pak | |
run: | | |
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/") | |
shell: Rscript {0} | |
- name: Install dependencies | |
run: | | |
pak::local_install_dev_deps() | |
shell: Rscript {0} | |
- name: Cache bookdown results | |
uses: actions/cache@v3 | |
with: | |
path: _bookdown_files | |
key: bookdown-3-${{ hashFiles('**/*Rmd') }} | |
restore-keys: bookdown-3- | |
- name: Build site | |
run: | | |
# Allows [implcit heading links] to work; will need to convert | |
# to explicit before switching to visual editor | |
options(bookdown.render.file_scope = FALSE) | |
bookdown::render_book("index.Rmd") | |
shell: Rscript {0} | |
- name: Set SSH key | |
if: github.event_name != 'pull_request' | |
uses: webfactory/ssh-agent@v0.7.0 | |
with: | |
ssh-private-key: ${{ secrets.SSH_KEY }} | |
- name: Push to gh-pages | |
if: github.event_name != 'pull_request' | |
run: | | |
# configure git | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "noemail@cienciade.datos" | |
# clone gh-pages branch to gh-pages/ | |
git clone --single-branch --branch gh-pages git@github.com:cienciadedatos/r4ds.git gh-pages | |
# remove everything inside gh-pages except .git/ | |
find gh-pages -maxdepth 1 ! -name .git ! -name gh-pages -exec rm -rf {} \; | |
# copy docs/ to gh-pages/ | |
cp -r docs/* gh-pages/ | |
# copy CNAME to gh-pages/ | |
cp -r CNAME gh-pages/ | |
# commit and push | |
cd gh-pages | |
# count the modified files | |
modified=$(git status --porcelain | wc -l) | |
# if there are changes, push them | |
if [ $modified -gt 0 ]; then | |
git add . | |
git commit -m "Update gh-pages" | |
git push origin gh-pages | |
fi | |
shell: bash |