Repository navigation
159 lines (140 loc) · 6.07 KB
/
Copy pathpreview.yml
File metadata and controls
159 lines (140 loc) · 6.07 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
name: Quarto Preview
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
- labeled
- unlabeled
paths:
- 'chapters/**'
- '_quarto.yml'
- '_quarto-*.yml'
- '.github/workflows/preview.yml'
- '.github/workflows/quarto-publish.yml'
- '*.qmd'
- '*.css'
- 'references.bib'
- '_extensions/**'
- 'latex-macros'
concurrency: preview-${{ github.ref }}
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
submodules: recursive
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
env:
# Authenticate the TinyTeX release lookup; unauthenticated calls hit
# GitHub API rate limits on shared runners (403).
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tinytex: true
- name: Install system dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y \
libnode-dev libglpk-dev \
libcurl4-openssl-dev libssl-dev libxml2-dev libgit2-dev \
libfontconfig1-dev libfreetype6-dev libharfbuzz-dev libfribidi-dev \
libpng-dev libtiff5-dev libjpeg-dev
- uses: r-lib/actions/setup-r@v2
with:
r-version: 'renv'
use-public-rspm: true
- uses: r-lib/actions/setup-renv@v2
with:
cache-version: 1
- name: Render
if: github.event.action != 'closed' # skip the build if the PR has been closed
uses: quarto-dev/quarto-actions/render@v2
# 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)
if: github.event.action != 'closed'
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: github.event.action != 'closed' && env.PREVIEW_SHOW_HIGHLIGHTS == 'true'
run: python3 .github/scripts/inject-preview-metadata.py
- name: Re-render with metadata
if: github.event.action != 'closed' && env.PREVIEW_SHOW_HIGHLIGHTS == 'true'
uses: quarto-dev/quarto-actions/render@v2
- name: Install python-docx for DOCX comparison
if: github.event.action != 'closed' && env.PREVIEW_SHOW_HIGHLIGHTS == 'true'
run: pip install python-docx
- name: Highlight HTML content changes
if: github.event.action != 'closed' && 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: github.event.action != 'closed'
run: python3 .github/scripts/create-docx-tracked-changes.py
env:
DOCX_DIR: ./_site
- name: Add home page banner
if: github.event.action != 'closed'
run: python3 .github/scripts/add-home-banner.py
env:
HTML_DIR: ./_site
PREVIEW_CHANGED_CHAPTERS: ${{ env.PREVIEW_CHANGED_CHAPTERS }}
- name: list files
if: github.event.action != 'closed'
shell: bash
run: |
echo "contents of _site:"
ls _site/ || echo "_site directory not found"
echo "contents of .:"
ls .
- 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 }}