From c118b9b69d12345b23fa619900989340774f9a4b Mon Sep 17 00:00:00 2001 From: Immanuel Abdi Date: Thu, 24 Oct 2024 14:42:18 -0700 Subject: [PATCH] [r] add automatic website building --- .github/workflows/deploy-docs.yml | 50 +++++++++++++++++++++++ .github/workflows/deploy-full-website.yml | 48 ++++++++++++++++++++++ .github/workflows/deploy-reference.R | 25 ++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 .github/workflows/deploy-docs.yml create mode 100644 .github/workflows/deploy-full-website.yml create mode 100644 .github/workflows/deploy-reference.R diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml new file mode 100644 index 00000000..b2aeaf1d --- /dev/null +++ b/.github/workflows/deploy-docs.yml @@ -0,0 +1,50 @@ +name: Build Docs and Create a PR with Docs Changes +on: + push: + branches: + - main +jobs: + build_docs: + name: Build and Deploy Documentation + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # to ensure other branches are available for build + - name: Install system dependencies + run: sudo apt-get install -y libhdf5-dev + - name: Set r compilation options + run: bash -c 'echo -e "MAKEFLAGS=--jobs=3\nCXXFLAGS += -O1 -UNDEBUG" > "$GITHUB_WORKSPACE/Makevars.user" && echo "R_MAKEVARS_USER=$GITHUB_WORKSPACE/Makevars.user" >> "$GITHUB_ENV"' + - name: Setup R + uses: r-lib/actions/setup-r@v2 + - name: Install R dependencies + uses: r-lib/actions/setup-r-dependencies@v2 + with: + cache-version: 1 + working-directory: 'r' + extra-packages: | + any::pkgdown + any::devtools + - name: Create git worktree with docs branch + run: git worktree add r/docs docs-html + - name: Build documentation + run: | + Rscript .github/workflows/deploy-reference.R FALSE + - name: Configure Git + run: | + git config --global user.name "GitHub Action" + git config --global user.email "action@github.com" + - name: Create new branch + run: | + git checkout -b update-docs-$(git rev-parse --short=6 ${{ github.sha }}) + git add . + git commit -m "Update documentation for commit $(git rev-parse --short=6 ${{ github.sha }})" + working-directory: r/docs + - name: Push changes to new branch + run: git push origin update-docs-$(git rev-parse --short=6 ${{ github.sha }}) + - name: Create Pull Request # use message with last commit + run: | + gh pr create --title "Update docs for commit: $(git log -n 1 --pretty=%B)" --body "$(git log -n 1 main)" --base docs-html --head update-docs-$(git rev-parse --short=6 ${{ github.sha }}) + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/deploy-full-website.yml b/.github/workflows/deploy-full-website.yml new file mode 100644 index 00000000..f4fe5d67 --- /dev/null +++ b/.github/workflows/deploy-full-website.yml @@ -0,0 +1,48 @@ +name: Manually Rebuild All Docs and Create a PR with Docs Changes +on: + workflow_dispatch: +jobs: + build_docs: + name: Build and Deploy Documentation + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # to ensure other branches are available for build + - name: Install system dependencies + run: sudo apt-get install -y libhdf5-dev + - name: Set r compilation options + run: bash -c 'echo -e "MAKEFLAGS=--jobs=3\nCXXFLAGS += -O1 -UNDEBUG" > "$GITHUB_WORKSPACE/Makevars.user" && echo "R_MAKEVARS_USER=$GITHUB_WORKSPACE/Makevars.user" >> "$GITHUB_ENV"' + - name: Setup R + uses: r-lib/actions/setup-r@v2 + - name: Install R dependencies + uses: r-lib/actions/setup-r-dependencies@v2 + with: + cache-version: 1 + working-directory: 'r' + extra-packages: | + any::pkgdown + any::devtools + - name: Create git worktree with docs branch + run: git worktree add r/docs docs-html + - name: Build documentation + run: | + Rscript .github/workflows/deploy-reference.R TRUE + - name: Configure Git + run: | + git config --global user.name "GitHub Action" + git config --global user.email "action@github.com" + - name: Create new branch + run: | + git checkout -b update-docs-$(git rev-parse --short=6 ${{ github.sha }}) + git add . + git commit -m "Update documentation for commit $(git rev-parse --short=6 ${{ github.sha }})" + working-directory: r/docs + - name: Push changes to new branch + run: git push origin update-docs-$(git rev-parse --short=6 ${{ github.sha }}) + - name: Create Pull Request # use message with last commit + run: | + gh pr create --title "Update docs for commit: $(git log -n 1 --pretty=%B)" --body "$(git log -n 1 main)" --base docs-html --head update-docs-$(git rev-parse --short=6 ${{ github.sha }}) + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/deploy-reference.R b/.github/workflows/deploy-reference.R new file mode 100644 index 00000000..6e499ed9 --- /dev/null +++ b/.github/workflows/deploy-reference.R @@ -0,0 +1,25 @@ +# get_vignette_changes <- function() { +# vignettes_folder <- "r/vignettes/" +# # Get all changes in the last commit +# changed_files <- system("git diff --name-only HEAD~1", intern = TRUE) +# # split to only get files in r/vignettes +# changed_vignettes <- changed_files[grepl(vignettes_folder, changed_files)] +# # get all vignettes in the vignettes folder +# all_vignettes <- paste0("r/vignettes/", list.files('r/vignettes', recursive = TRUE, pattern = "\\.Rmd$")) +# # get the ones that are not changed and change the extension so they're not rendered +# unchanged_vignettes <- setdiff(all_vignettes, changed_vignettes) +# unchanged_vignettes <- gsub("\\.Rmd$", ".Rmd_", unchanged_vignettes) +# pkgdown::build_articles('r', lazy = TRUE) +# # build vignettes +# } +args = commandArgs(TRUE) +# First argument is whether to rebuild the entire site. +rebuild <- as.logical(args[1]) +if (rebuild) { + pkgdown::build_site_github_pages('r') +} else { + pkgdown::build_reference('r') + pkgdown::build_articles('r', lazy = TRUE) + pkgdown::build_news('r') + pkgdown::build_home('r') +} \ No newline at end of file