From b7a71495a5d485b0db7b1432268f57a86cbb9491 Mon Sep 17 00:00:00 2001 From: Trevor Campbell Date: Wed, 21 Aug 2024 09:31:38 -0700 Subject: [PATCH 1/2] no rebuild book on push to prod --- .github/workflows/build_book.yml | 78 ------------------------------- .github/workflows/update_book.yml | 39 ++++++++++++++++ 2 files changed, 39 insertions(+), 78 deletions(-) delete mode 100644 .github/workflows/build_book.yml create mode 100644 .github/workflows/update_book.yml diff --git a/.github/workflows/build_book.yml b/.github/workflows/build_book.yml deleted file mode 100644 index a1a872213..000000000 --- a/.github/workflows/build_book.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: Rebuild and deploy book to gh-pages branch -on: - push: - branches: - - production - paths: - - 'index.Rmd' - - '_bookdown.yml' - - '_output.yml' - - 'source/*.Rmd' - - 'source/*.bib' - - 'source/*.css' - - 'data/**' - - 'img/**' - - 'build_html.sh' - -jobs: - deploy-book: - runs-on: ubuntu-latest - permissions: - contents: write - packages: write - - steps: - - name: Get Actions user id - id: get_uid - run: | - actions_user_id=`id -u $USER` - echo $actions_user_id - echo "uid=$actions_user_id" >> $GITHUB_OUTPUT - - - name: checkout production - uses: actions/checkout@v2 - with: - ref: 'production' - - - name: Build the book - run: | - ./build_html.sh - - - name: Reset ownership of workspace after build - uses: peter-murray/reset-workspace-ownership-action@v1 - with: - user_id: ${{ steps.get_uid.outputs.uid }} - - # 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/ - force_orphan: true # this will clean up all previous PR previews / main branch preview - cname: datasciencebook.ca - - # rebuild the dev version after the previous copy was cleaned out - - name: checkout main - uses: actions/checkout@v2 - with: - ref: 'main' - - - name: Build the book - run: | - ./build_html.sh - - - name: Reset ownership of workspace after build - uses: peter-murray/reset-workspace-ownership-action@v1 - with: - user_id: ${{ steps.get_uid.outputs.uid }} - - # 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 - diff --git a/.github/workflows/update_book.yml b/.github/workflows/update_book.yml new file mode 100644 index 000000000..c71db2f4a --- /dev/null +++ b/.github/workflows/update_book.yml @@ -0,0 +1,39 @@ +name: Rebuild and deploy book to gh-pages branch +on: + push: + branches: + - production + paths: + - 'index.Rmd' + - '_bookdown.yml' + - '_output.yml' + - 'source/*.Rmd' + - 'source/*.bib' + - 'source/*.css' + - 'data/**' + - 'img/**' + - 'build_html.sh' + +jobs: + deploy-book: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + + steps: + - name: checkout gh-pages + uses: actions/checkout@v2 + with: + ref: 'gh-pages' + + - name: remove all pull and diff folders + run: | + rm -rf pull* diff* + + - name: copy dev website to root directory + run: | + yes | cp -rf dev/* . + + - name: push the result to gh-pages + uses: stefanzweifel/git-auto-commit-action@v5 From ad78100c3ca5a35eba6744ad0d51d76ab43e47f1 Mon Sep 17 00:00:00 2001 From: Trevor Campbell Date: Wed, 21 Aug 2024 09:46:31 -0700 Subject: [PATCH 2/2] update so that gh-pages is still orphaned properly --- .github/workflows/update_book.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update_book.yml b/.github/workflows/update_book.yml index c71db2f4a..c5a8de583 100644 --- a/.github/workflows/update_book.yml +++ b/.github/workflows/update_book.yml @@ -27,13 +27,22 @@ jobs: with: ref: 'gh-pages' - - name: remove all pull and diff folders + - name: Copy contents of dev/ to home folder run: | - rm -rf pull* diff* + yes | cp -rf dev ${{ runner.home }} - - name: copy dev website to root directory + # Push update website to dev/ and clean out old commits + - name: Update website to contents of dev, remove all old commits and subpages + uses: peaceiris/actions-gh-pages@v3.8.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: dev/ + force_orphan: true # this will clean up all previous PR previews / main branch preview + cname: datasciencebook.ca + + - name: copy dev/ website back in run: | - yes | cp -rf dev/* . + yes | cp -rf ${{ runner.home }}/dev dev - name: push the result to gh-pages uses: stefanzweifel/git-auto-commit-action@v5