Skip to content

Commit

Permalink
Merge pull request #525 from moderndive/test-ga-master-build
Browse files Browse the repository at this point in the history
Test ga master build
  • Loading branch information
ismayc authored Oct 2, 2024
2 parents 0998e78 + 502f2fe commit ea76964
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 17 deletions.
148 changes: 132 additions & 16 deletions .github/workflows/deploy_bookdown.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,166 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help

# Set up renv following instructions at https://www.emilhvitfeldt.com/post/bookdown-netlify-github-actions/
on:
push:
branches: [main, master]
branches: [main, master, v2]
pull_request:
branches: [main, master]
branches: [main, master, v2]
workflow_dispatch:

name: bookdown

jobs:
bookdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GH_PAT }}
GITHUB_PAT: ${{ secrets.GITHUB_PAT }}
EMAIL: ${{ secrets.EMAIL }}
steps:
- uses: actions/checkout@v3
# Checkout repository
- uses: actions/checkout@v4

# Setup Pandoc
- uses: r-lib/actions/setup-pandoc@v2

# Setup R environment with RSPM enabled
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

# Restore cached package and TinyTeX state files
- name: Cache package state
uses: actions/cache@v4
with:
path: |
installed_packages.rds
tinytex_packages.rds
key: package-state-${{ runner.os }}-${{ hashFiles('**/renv.lock') }}
restore-keys: package-state-${{ runner.os }}-

# Check and install R packages if needed
- name: Check and Install R Packages
run: |
R -e '
if (file.exists("installed_packages.rds")) {
saved_pkgs <- readRDS("installed_packages.rds");
current_pkgs <- installed.packages();
if (!identical(saved_pkgs[,1], current_pkgs[,1])) {
missing_pkgs <- setdiff(rownames(saved_pkgs), rownames(current_pkgs));
if (length(missing_pkgs) > 0) install.packages(missing_pkgs);
} else {
cat("No package changes detected.\n");
}
} else {
install.packages(c("tidyverse", "bookdown"));
}'
env:
GITHUB_PAT: ${{ secrets.GITHUB_PAT }}

# Install and cache TinyTeX only if needed
- name: Install TinyTeX if Needed
run: |
if ! command -v tlmgr &> /dev/null; then
R -e 'install.packages("tinytex"); tinytex::install_tinytex()';
R -e 'tinytex::tlmgr_install(c("xetex", "fontspec", "xunicode", "geometry", "fancyhdr", "titlesec", "titling", "tocloft", "sectsty", "environ", "trimspaces", "wrapfig", "multirow", "colortbl", "tabularx", "varwidth", "footnote", "threeparttable", "enumitem", "footmisc", "fncychap", "hyphenat", "biblatex", "biber"))';
else
echo "TinyTeX is already installed";
fi
shell: bash

# Cache TinyTeX installation
- name: Cache TinyTeX installation
uses: actions/cache@v4
with:
path: ~/.TinyTeX
key: tinytex-${{ runner.os }}-${{ hashFiles('**/*.tex') }}
restore-keys: tinytex-

# Install fonts only if needed
- name: Check and Install Fonts
run: |
if ! fc-list | grep -q "Inconsolata"; then
sudo apt-get update;
sudo apt-get install -y fonts-inconsolata fonts-nanum;
sudo fc-cache -fv;
else
echo "Fonts are already installed";
fi
shell: bash

# Setup renv if needed
- uses: r-lib/actions/setup-renv@v2

# Ensure _bookdown_files directory exists
- name: Ensure _bookdown_files directory exists
run: mkdir -p _bookdown_files

# Cache bookdown results
- name: Cache bookdown results
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: _bookdown_files
key: bookdown-${{ hashFiles('**/*Rmd') }}
restore-keys: bookdown-

- name: Build site
run: bookdown::render_book("index.Rmd", quiet = TRUE)
shell: Rscript {0}
# Check if bookdown::pdf_book is enabled (not commented out) in _output.yml
- name: Check for uncommented pdf_book in _output.yml
id: check_pdf
run: |
if grep -qE '^[^#]*bookdown::pdf_book' _output.yml; then
echo "PDF book is enabled.";
echo "build_pdf=true" >> $GITHUB_ENV;
else
echo "PDF book is not enabled.";
echo "build_pdf=false" >> $GITHUB_ENV;
fi
# Build PDF book if enabled
- name: Build PDF book
if: env.build_pdf == 'true'
run: |
R -e 'bookdown::render_book("index.Rmd", "bookdown::pdf_book")'
# Build HTML books
- name: Build HTML gitbook book
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') || github.event_name == 'pull_request'
run: |
R -e 'bookdown::render_book("index.Rmd", "bookdown::gitbook")'
- name: Build HTML bs4_book book
if: github.ref == 'refs/heads/v2' || github.event_name == 'pull_request'
run: |
R -e 'bookdown::render_book("index.Rmd", "bookdown::bs4_book")'
# Save R package state and TinyTeX installation to RDS files
- name: Save R Package and TinyTeX State
run: |
R -e 'saveRDS(installed.packages(), file = "installed_packages.rds")';
R -e 'tinytex_packages <- tinytex::tl_pkgs(); saveRDS(tinytex_packages, file = "tinytex_packages.rds")'
# Deploy HTML to GitHub Pages if on main or master branch
- name: Deploy to GitHub pages from main/master 🚀
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: docs
clean: false

# Deploy to v2-publish if on v2 branch
- name: Deploy to v2-publish branch from v2 🚀
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/v2'
uses: JamesIves/[email protected]
with:
branch: v2-publish
folder: docs
clean: false

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
# Deploy to /v2 subdirectory of gh-pages from v2 branch
- name: Deploy to v2 subdirectory of gh-pages 🚀
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/v2'
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: docs
target-folder: v2 # Specify the target subdirectory
clean: false
2 changes: 1 addition & 1 deletion 00-preface.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Chester Ismay | Albert Y. Kim
:-------------------------:|:-------------------------:
`r include_image(path = "images/ismay.png", html_opts = "height=220px", latex_opts = "width=46%")` | `r include_image(path = "images/kim.png", html_opts = "height=220px", latex_opts = "width=46%")`

**Chester Ismay** is Director of Data Science Education at Flatiron School, working remotely from Portland, OR, USA. In this role, he leads the data science curriculum and instructional coordination teams at Flatiron School. He completed his PhD in statistics from Arizona State University in 2013. He has previously worked in a variety of roles including as an actuary at Scottsdale Insurance Company (now Nationwide E&S/Specialty), as a freelance data science consultant, and at Ripon College, Reed College, and Pacific University. Prior to joining Flatiron School, he was a Data Science Evangelist at DataRobot, where he led data science, machine learning, and data engineering in-person and virtual workshops for DataRobot University. In addition to his work for *ModernDive*, he also contributed as initial developer of the [`infer`](https://cran.r-project.org/package=infer) R package and is author and maintainer of the [`thesisdown`](https://github.com/ismayc/thesisdown) R package.
**Chester Ismay** is Vice President of Data and Automation at MATE Seminars and is a freelance data science consultant and instructor. He also teaches in the Center for Executive and Professional Education at Portland State University. He completed his PhD in statistics from Arizona State University in 2013. He has previously worked in a variety of roles including as an actuary at Scottsdale Insurance Company (now Nationwide E&S/Specialty) and at Ripon College, Reed College, and Pacific University. He has experience working in online education and was previously a Data Science Evangelist at DataRobot, where he led data science, machine learning, and data engineering in-person and virtual workshops for DataRobot University. In addition to his work for *ModernDive*, he also contributed as initial developer of the [`infer`](https://cran.r-project.org/package=infer) R package and is author and maintainer of the [`thesisdown`](https://github.com/ismayc/thesisdown) R package.

* Email: `[email protected]`
* Webpage: <https://chester.rbind.io/>
Expand Down

0 comments on commit ea76964

Please sign in to comment.