-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (140 loc) · 6.03 KB
/
Copy pathpreview.yml
File metadata and controls
162 lines (140 loc) · 6.03 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Quarto Preview
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
- labeled
- unlabeled
jobs:
build-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for git diff
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
with:
tinytex: true
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
any::knitr
any::rmarkdown
any::tibble
- name: Restore Quarto freezer
id: quarto-freezer-cache
uses: actions/cache/restore@v4
with:
path: _freeze
key: ${{ runner.os }}-quarto-freezer-${{ github.event.pull_request.head.sha }}-${{ github.run_attempt }}
restore-keys: |
${{ runner.os }}-quarto-freezer-${{ github.event.pull_request.head.sha }}-
${{ runner.os }}-quarto-freezer-main-
${{ runner.os }}-quarto-freezer-
- name: Render HTML
uses: quarto-dev/quarto-actions/render@v2
with:
to: html
- name: Render RevealJS
if: contains(github.event.pull_request.labels.*.name, 'revealjs')
uses: quarto-dev/quarto-actions/render@v2
with:
to: revealjs
- name: Render PDF
if: contains(github.event.pull_request.labels.*.name, 'pdf')
uses: quarto-dev/quarto-actions/render@v2
with:
to: pdf
- name: Render DOCX
if: contains(github.event.pull_request.labels.*.name, 'docx')
uses: quarto-dev/quarto-actions/render@v2
with:
to: docx
# Detect which chapters have changed and optionally disable highlighting
# based on the 'no-preview-highlights' PR label
- name: Detect changed chapters (based on rendered files)
run: python3 .github/scripts/detect-changed-chapters.py
env:
HTML_DIR: ./_site
# Set to 'true' if PR has 'no-preview-highlights' label
DISABLE_PREVIEW_HIGHLIGHTS: ${{ contains(github.event.pull_request.labels.*.name, 'no-preview-highlights') }}
- name: Inject preview metadata
if: env.PREVIEW_SHOW_HIGHLIGHTS == 'true'
run: python3 .github/scripts/inject-preview-metadata.py
- name: Re-render with metadata
if: env.PREVIEW_SHOW_HIGHLIGHTS == 'true'
uses: quarto-dev/quarto-actions/render@v2
with:
to: html
- name: Install python-docx for DOCX comparison
if: contains(github.event.pull_request.labels.*.name, 'docx')
run: pip install python-docx
- name: Highlight HTML content changes
if: env.PREVIEW_SHOW_HIGHLIGHTS == 'true'
run: |
echo "Changed chapters:"
echo "${{ env.PREVIEW_CHANGED_CHAPTERS }}"
python3 .github/scripts/highlight-html-changes.py
env:
HTML_DIR: ./_site
PREVIEW_CHANGED_CHAPTERS: ${{ env.PREVIEW_CHANGED_CHAPTERS }}
- name: Create DOCX with tracked changes
if: contains(github.event.pull_request.labels.*.name, 'docx')
run: python3 .github/scripts/create-docx-tracked-changes.py
env:
DOCX_DIR: ./_site
- name: Add home page banner
run: python3 .github/scripts/add-home-banner.py
env:
HTML_DIR: ./_site
PREVIEW_CHANGED_CHAPTERS: ${{ env.PREVIEW_CHANGED_CHAPTERS }}
- name: Save Quarto freezer
uses: actions/cache/save@v4
with:
path: _freeze
key: ${{ runner.os }}-quarto-freezer-${{ github.event.pull_request.head.sha }}-${{ github.run_attempt }}
- name: Deploy PR Preview
id: preview-step
if: github.event_name == 'pull_request'
uses: rossjrw/pr-preview-action@v1
with:
source-dir: ./_site/
# Deploy on label changes too, not just open/reopen/synchronize
# The 'auto' action ignores label events, so we explicitly set 'deploy' for non-closed PRs
action: ${{ github.event.action == 'closed' && 'remove' || 'deploy' }}
preview-branch: gh-pages
comment: "false"
wait-for-pages-deployment: false
# Create sticky comment with preview link
# Following https://github.com/rossjrw/pr-preview-action?tab=readme-ov-file#customise-the-sticky-comment
- uses: marocchino/sticky-pull-request-comment@v2
if: steps.preview-step.outputs.deployment-action == 'deploy' && env.deployment_status == 'success'
with:
header: pr-preview
recreate: true
message: |
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
:---:
| <p><img src="https://qr.rossjrw.com/?url=${{ steps.preview-step.outputs.preview-url }}" height="100" align="right" alt="QR code for preview link"></p> :rocket: View preview at <br> ${{ steps.preview-step.outputs.preview-url }} <br><br>
| <h6>Built to branch [`gh-pages`](${{ github.server_url }}/${{ github.repository }}/tree/gh-pages) at ${{ steps.preview-step.outputs.action-start-time }}. <br> Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete. <br><br> </h6>
- uses: marocchino/sticky-pull-request-comment@v2
if: steps.preview-step.outputs.deployment-action == 'remove' && env.deployment_status == 'success'
with:
header: pr-preview
recreate: true
message: |
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
:---:
Preview removed because the pull request was closed.
${{ steps.preview-step.outputs.action-start-time }}