-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (108 loc) · 4.97 KB
/
pr-diff-and-deploy-preview.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: "Rebuild and deploy PR and diff versions of a website to gh-pages branch"
# YOUR_FILES below should be replaced with a list of files that, when changed in a PR, will trigger the PR deploy preview
on:
pull_request:
types: [opened, synchronize]
paths:
- 'textbook/**'
branches:
- 'main'
jobs:
deploy-pr-preview:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
pull-requests: write
steps:
# - uses: actions/checkout@v4
# - uses: conda-incubator/setup-miniconda@v3
# with:
# environment-file: environment.yaml
# activate-environment: viz-oer
# auto-activate-base: false
# - uses: r-lib/actions/setup-r@v2
# with:
# use-public-rspm: true
# - uses: r-lib/actions/setup-r-dependencies@v2
# with:
# cache-version: 2
# extra-packages: |
# any::ggplot2
# any::rcmdcheck
# Checkout a copy of the repository on the PR branch
- name: Checkout the PR version of the website repository
uses: actions/checkout@v4
with:
fetch-depth: '0'
ref: ${{ github.head_ref }}
- name: Setup the environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yaml
init-shell: bash
cache-environment: true
# Build the PR version of the website
# YOUR_BUILD_CODE below should be replaced with code that builds your website
# - name: Build the PR version of the website
# - uses: conda-incubator/setup-miniconda@v3
# with:
# environment-file: environment.yaml
# activate-environment: viz-oer
# auto-activate-base: false
- name: Build the PR version of the website
run: quarto render textbook; ls -al textbook; tree
shell: bash -el {0} # Required to see the mamba init env
# - uses: quarto-dev/quarto-actions/setup@v2
# - uses: quarto-dev/quarto-actions/render@v2
# with:
# path: textbook
# Push the PR version of the website to the gh-pages branch
# the PR version will be stored in a folder named pull### (where ### is the PR number)
# WEBSITE_FOLDER below should be replaced with the folder in which the newly built website was stored
- name: Push the PR version of the website to gh-pages branch
uses: peaceiris/actions-gh-pages@v3.8.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./
keep_files: true
destination_dir: pull${{ github.event.number }}
- run: ls -al
- run: tree
# Now that the website was built and pushed to gh-pages, checkout the gh-pages branch
- name: Checkout the gh-pages branch
uses: actions/checkout@v2
with:
fetch-depth: '0'
ref: 'gh-pages'
# Compute the diff of the new PR website (which is stored in the pull### folder)
# Store the diff version of the website in a folder named diff### (where ### is the PR number)
# OLD_SITE_FOLDER below should be replaced with the folder where the "base" version of the website is stored
- name: Run website diff to compare the old site to the PR version
run: |
rustup update
pip install --upgrade pip
pip install website_diff
ls -la
website_diff --old . --new pull${{ github.event.number }} --diff diff${{ github.event.number }}
# Push the diff version of the website to the gh-pages branch
# the diff version will be stored in a folder named diff### (where ### is the PR number)
- name: Push the diff version of the website to the gh-pages branch
uses: peaceiris/actions-gh-pages@v3.8.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: diff${{ github.event.number }}
keep_files: true
destination_dir: diff${{ github.event.number }}
# Post a message on the PR thread with links to the PR preview, the diff, the base version, and the production version of the website
# YOUR_SITE below should be replaced with your website's URL
# OLD_SITE_FOLDER should be replaced with the folder where the "base" version of the website is stored
- name: Post PR preview, diff, current main, and production 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://joelostblom.github.io/viz-oer/pull${{ github.event.number }}/index.html)
* PR diff with `main` available [here](https://joelostblom.github.io/viz-oer/diff${{ github.event.number }}/index.html)
* Current `main` deploy preview available [here](https://joelostblom.github.io/viz-oer/index.html)
* Public production build available [here](https://joelostblom.github.io/viz-oer/)