From 10038b31359af613c3a1deffc993fec1c0c74faf Mon Sep 17 00:00:00 2001 From: Trevor Campbell Date: Sun, 24 Sep 2023 17:21:11 -0700 Subject: [PATCH] workflow improvements (auto pr / main deploy builds, PR commenting) from py --- .github/workflows/build_book.yml | 2 +- .github/workflows/deploy_main_preview.yml | 44 ++++++++++++++ .github/workflows/deploy_pr_preview.yml | 58 +++++++++++++++++++ .../workflows/update_build_environment.yml | 1 + 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy_main_preview.yml create mode 100644 .github/workflows/deploy_pr_preview.yml diff --git a/.github/workflows/build_book.yml b/.github/workflows/build_book.yml index 2d79130c2..4a5a87756 100644 --- a/.github/workflows/build_book.yml +++ b/.github/workflows/build_book.yml @@ -36,6 +36,6 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: docs/ - force_orphan: true + force_orphan: true # this will clean up all previous PR previews / main branch preview cname: datasciencebook.ca diff --git a/.github/workflows/deploy_main_preview.yml b/.github/workflows/deploy_main_preview.yml new file mode 100644 index 000000000..903e8b970 --- /dev/null +++ b/.github/workflows/deploy_main_preview.yml @@ -0,0 +1,44 @@ +name: Rebuild and deploy dev version of book to gh-pages branch in dev/ folder +on: + push: + branches: + - main + paths: + - 'index.Rmd' + - '_bookdown.yml' + - '_output.yml' + - 'source/*.Rmd' + - 'source/*.bib' + - 'source/*.css' + - 'data/**' + - 'img/**' + +jobs: + deploy-main-preview: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + + steps: + - name: checkout + uses: actions/checkout@v2 + with: + ref: 'main' + + - name: Build the book + run: | + ./build_html.sh + + # Push the book's HTML to github-pages + - name: GitHub Pages action + uses: peaceiris/actions-gh-pages@v3.8.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: docs/ + keep_files: true + destination_dir: dev + # force_orphan: true # once peaceiris updates to v4, change this to true and keep_files: true for the PR / main branch deploy previews + + + diff --git a/.github/workflows/deploy_pr_preview.yml b/.github/workflows/deploy_pr_preview.yml new file mode 100644 index 000000000..fd8e05279 --- /dev/null +++ b/.github/workflows/deploy_pr_preview.yml @@ -0,0 +1,58 @@ +name: "Rebuild and deploy PR version of book to gh-pages branch in pull###/ folder" +on: + pull_request: + types: [opened, synchronize] + paths: + - 'index.Rmd' + - '_bookdown.yml' + - '_output.yml' + - 'source/*.Rmd' + - 'source/*.bib' + - 'source/*.css' + - 'data/**' + - 'img/**' + +jobs: + deploy-pr-preview: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + pull-requests: write + + steps: + - name: Wait for potential build environment update + uses: fountainhead/action-wait-for-check@v1.1.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + checkName: "Rebuild docker image" + ref: ${{ github.event.pull_request.head.sha }} + + - name: Checkout the repo + uses: actions/checkout@v2 + with: + fetch-depth: '0' + ref: ${{ github.head_ref }} + + - name: Build the book + run: | + ./build_html.sh + + # Push the book's HTML to github-pages + - name: GitHub Pages action + uses: peaceiris/actions-gh-pages@v3.8.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: docs/ + keep_files: true + destination_dir: pull${{ github.event.number }} + # force_orphan: true # once peaceiris updates to v4, change this to true and keep_files: true for the PR / main branch deploy previews + + - name: Post URLS to PR thread + uses: mshick/add-pr-comment@v2.8.1 + with: + message: | + Hello! I've built a preview of your PR so that you can compare it to the current `main` branch. + * PR deploy preview available [here](https://datasciencebook.ca/pull${{ github.event.number }}/index.html) + * Current `main` deploy preview available [here](https://datasciencebook.ca/dev/index.html) + * Public production build available [here](https://datasciencebook.ca) diff --git a/.github/workflows/update_build_environment.yml b/.github/workflows/update_build_environment.yml index e027516d0..73809ca48 100644 --- a/.github/workflows/update_build_environment.yml +++ b/.github/workflows/update_build_environment.yml @@ -6,6 +6,7 @@ on: - Dockerfile jobs: rebuild-docker: + name: Rebuild docker image runs-on: ubuntu-latest permissions: contents: write