Skip to content

Commit 10038b3

Browse files
workflow improvements (auto pr / main deploy builds, PR commenting) from py
1 parent 44b29ee commit 10038b3

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

.github/workflows/build_book.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ jobs:
3636
with:
3737
github_token: ${{ secrets.GITHUB_TOKEN }}
3838
publish_dir: docs/
39-
force_orphan: true
39+
force_orphan: true # this will clean up all previous PR previews / main branch preview
4040
cname: datasciencebook.ca
4141

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Rebuild and deploy dev version of book to gh-pages branch in dev/ folder
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'index.Rmd'
8+
- '_bookdown.yml'
9+
- '_output.yml'
10+
- 'source/*.Rmd'
11+
- 'source/*.bib'
12+
- 'source/*.css'
13+
- 'data/**'
14+
- 'img/**'
15+
16+
jobs:
17+
deploy-main-preview:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
packages: write
22+
23+
steps:
24+
- name: checkout
25+
uses: actions/checkout@v2
26+
with:
27+
ref: 'main'
28+
29+
- name: Build the book
30+
run: |
31+
./build_html.sh
32+
33+
# Push the book's HTML to github-pages
34+
- name: GitHub Pages action
35+
uses: peaceiris/[email protected]
36+
with:
37+
github_token: ${{ secrets.GITHUB_TOKEN }}
38+
publish_dir: docs/
39+
keep_files: true
40+
destination_dir: dev
41+
# force_orphan: true # once peaceiris updates to v4, change this to true and keep_files: true for the PR / main branch deploy previews
42+
43+
44+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "Rebuild and deploy PR version of book to gh-pages branch in pull###/ folder"
2+
on:
3+
pull_request:
4+
types: [opened, synchronize]
5+
paths:
6+
- 'index.Rmd'
7+
- '_bookdown.yml'
8+
- '_output.yml'
9+
- 'source/*.Rmd'
10+
- 'source/*.bib'
11+
- 'source/*.css'
12+
- 'data/**'
13+
- 'img/**'
14+
15+
jobs:
16+
deploy-pr-preview:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
packages: write
21+
pull-requests: write
22+
23+
steps:
24+
- name: Wait for potential build environment update
25+
uses: fountainhead/[email protected]
26+
with:
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
checkName: "Rebuild docker image"
29+
ref: ${{ github.event.pull_request.head.sha }}
30+
31+
- name: Checkout the repo
32+
uses: actions/checkout@v2
33+
with:
34+
fetch-depth: '0'
35+
ref: ${{ github.head_ref }}
36+
37+
- name: Build the book
38+
run: |
39+
./build_html.sh
40+
41+
# Push the book's HTML to github-pages
42+
- name: GitHub Pages action
43+
uses: peaceiris/[email protected]
44+
with:
45+
github_token: ${{ secrets.GITHUB_TOKEN }}
46+
publish_dir: docs/
47+
keep_files: true
48+
destination_dir: pull${{ github.event.number }}
49+
# force_orphan: true # once peaceiris updates to v4, change this to true and keep_files: true for the PR / main branch deploy previews
50+
51+
- name: Post URLS to PR thread
52+
uses: mshick/[email protected]
53+
with:
54+
message: |
55+
Hello! I've built a preview of your PR so that you can compare it to the current `main` branch.
56+
* PR deploy preview available [here](https://datasciencebook.ca/pull${{ github.event.number }}/index.html)
57+
* Current `main` deploy preview available [here](https://datasciencebook.ca/dev/index.html)
58+
* Public production build available [here](https://datasciencebook.ca)

.github/workflows/update_build_environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- Dockerfile
77
jobs:
88
rebuild-docker:
9+
name: Rebuild docker image
910
runs-on: ubuntu-latest
1011
permissions:
1112
contents: write

0 commit comments

Comments
 (0)