-
-
Notifications
You must be signed in to change notification settings - Fork 0
394 lines (370 loc) Β· 15 KB
/
pkgdown-multi.yml
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
name: Pkgdown Multi
on:
push:
tags:
- "v*"
branches:
- main
- develop
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
paths:
- inst/templates/**
- _pkgdown.yaml
- DESCRIPTION
- "**.md"
- "**.Rmd"
- man/**
- LICENSE.*
- NAMESPACE
workflow_dispatch:
workflow_call:
secrets:
REPO_GITHUB_TOKEN:
description: |
Github token with read access to repositories, required for staged.dependencies installation
required: false
inputs:
install-system-dependencies:
description: Check for and install system dependencies
required: false
default: false
type: boolean
fail-pkgdown-on-warnings:
description: Fail the pkgdown workflow if warnings are generated while generating docs
required: false
default: false
type: boolean
enable-staged-dependencies-check:
description: Enable staged dependencies YAML check
required: false
default: false
type: boolean
additional-env-vars:
description: |
Extra environment variables, as a 'key=value' pair, with each pair on a new line.
Example usage:
additional-env-vars: |
ABC=123
XYZ=456
required: false
default: ""
type: string
refs-order:
description: |
The order in which refs should appear in the drop-down list. Versions not in the vector
will appear below refs listed here.
If docs have never been generated for the ref, the ref will not appear in the
drop-down. Similarly, if docs have been generated for the ref, but the ref is not
listed in the vector, it will not appear in the drop-down.
required: false
default: c("devel", "pre-release", "main", "latest-tag")
type: string
default-landing-page:
description:
The default branch or tag on gh-pages that corresponds to the landing page.
For instance, if your root index page on gh-pages is built using the 'main'
branch, then the root page of the website will correspond to this page.
If 'latest-tag' is selected, then the latest version will become the default.
required: false
default: main
type: string
sd-direction:
description: The direction to use to install staged dependencies. Choose between 'upstream', 'downstream' and 'all'
required: false
type: string
default: upstream
# If you provide latest-tag-alt-name and/or release-candidate-alt-name inputs
# to this workflow in some repo, you should also provide these inputs in
# R CMD check and Coverage workflows in order to make the unit test report
# and coverage report available in pkgdown documentation for the alt-names.
# Additionally, branches-or-tags-to-list input should be overridden with
# the additional alt-name inputs.
latest-tag-alt-name:
description: An alternate name for the 'latest-tag' documentation item
required: false
type: string
default: ""
release-candidate-alt-name:
description: An alternate name for the 'release-candidate' documentation item
required: false
type: string
default: ""
branches-or-tags-to-list:
description: Which branches or tags should be listed under the
'Versions' dropdown menu on the landing page?
This input should be a regular expression in R.
required: false
type: string
default: >-
^main$|^devel$|^pre-release$|^latest-tag$|^release-candidate$|^develop$|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)(-rc[0-9]+)$
package-subdirectory:
description: Subdirectory in the repository, where the R package is located.
required: false
type: string
default: "."
additional-unit-test-report-directories:
description: |
If any *additional* unit test report directories are generated by the build-check-install workflow,
they should be listed as comma-separated directory list. If this input is empty, only coverage-report
and unit-test-report directories will be retained in the generated documentation directory.
Example:
unit-test-report-as-cran,unit-test-report-not-cran
required: false
type: string
default: ""
concurrency:
group: docs-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
docs:
name: Generate π£
runs-on: ubuntu-latest
if: >
!contains(github.event.commits[0].message, '[skip docs]')
&& github.event.pull_request.draft == false
container:
image: ghcr.io/insightsengineering/rstudio:latest
steps:
- name: Setup token π
id: github-token
run: |
if [ "${{ secrets.REPO_GITHUB_TOKEN }}" == "" ]; then
echo "REPO_GITHUB_TOKEN is empty. Substituting it with GITHUB_TOKEN."
echo "token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
else
echo "Using REPO_GITHUB_TOKEN."
echo "token=${{ secrets.REPO_GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Get branch names πΏ
id: branch-name
uses: tj-actions/branch-names@v8
- name: Get current branch or tag π·οΈ
id: current-branch-or-tag
run: |
if [ "${{ steps.branch-name.outputs.is_tag }}" == "true" ]; then
echo "Current tag: ${{ steps.branch-name.outputs.tag }}"
echo "ref-name=${{ steps.branch-name.outputs.tag }}" >> $GITHUB_OUTPUT
else
echo "Current branch: ${{ steps.branch-name.outputs.current_branch }}"
echo "ref-name=${{ steps.branch-name.outputs.current_branch }}" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Checkout repo (PR) π
uses: actions/[email protected]
if: github.event_name == 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
path: ${{ github.event.repository.name }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Checkout repo π
uses: actions/[email protected]
if: github.event_name != 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
path: ${{ github.event.repository.name }}
- name: Check commit message π¬
run: |
git config --global --add safe.directory $(pwd)
export head_commit_message="$(git show -s --format=%B | tr '\r\n' ' ' | tr '\n' ' ')"
echo "head_commit_message = $head_commit_message"
if [[ $head_commit_message == *"$SKIP_INSTRUCTION"* ]]; then
echo "Skip instruction detected - cancelling the workflow."
exit 1
fi
shell: bash
working-directory: ${{ github.event.repository.name }}
env:
SKIP_INSTRUCTION: "[skip docs]"
- name: Restore SD cache π°
uses: actions/cache@v4
with:
key: sd-${{ runner.os }}-${{ github.event.repository.name }}
path: ~/.staged.dependencies
- name: Run Staged dependencies π¦
uses: insightsengineering/staged-dependencies-action@v2
env:
GITHUB_PAT: ${{ steps.github-token.outputs.token }}
with:
path: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}
enable-check: ${{ inputs.enable-staged-dependencies-check }}
run-system-dependencies: ${{ inputs.install-system-dependencies }}
direction: ${{ inputs.sd-direction }}
- name: Install R package π§
run: |
if (file.exists("renv.lock")) renv::restore()
install.packages(".", repos=NULL, type="source")
shell: Rscript {0}
working-directory: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}
- name: Build docs π
if: >
github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/v')
|| github.event_name == 'push'
run: |
repo="${{ github.event.repository.name }}"
if [ "${{ inputs.additional-env-vars }}" != "" ]
then {
echo -e "${{ inputs.additional-env-vars }}" > /tmp/dotenv.env
export $(tr '\n' ' ' < /tmp/dotenv.env)
}
fi
Rscript - <<EOF 2>&1 | tee pkgdown_${repo}.log
if (file.exists("renv.lock")) renv::restore()
pkgdown::build_site(devel = TRUE)
EOF
if [ "${{ inputs.fail-pkgdown-on-warnings }}" == "true" ]; then {
grep "Warning message" pkgdown_${repo}.log > pkgdown_warnings_${repo}.log
if [[ $(wc -l <pkgdown_warnings_${repo}.log) -gt 0 ]]; then {
echo "----------------------------------------"
echo "β One or more warnings were generated during the pkgdown build."
echo "Please π fix the warnings shown above π"
exit 1
}
fi
}
fi
shell: bash
working-directory: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}
- name: Checkout gh-pages π
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'push'
uses: actions/[email protected]
with:
path: "gh-pages"
fetch-depth: 0
ref: "gh-pages"
- name: Upload docs to gh-pages π
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'push'
run: |
GH_PAGES_DIR="gh-pages/${{ steps.current-branch-or-tag.outputs.ref-name }}"
mkdir -p $GH_PAGES_DIR
echo "Current contents of $GH_PAGES_DIR:"
ls -l $GH_PAGES_DIR
# Remove any existing documentation for the git tag, but retain coverage report and
# unit test reports which might have already been pushed to the gh-pages branch
# by the coverage and build-check-install workflows respectively.
directories_to_retain="coverage-report,unit-test-report"
if [[ "${{ inputs.additional-unit-test-report-directories }}" != "" ]]; then
directories_to_retain="${directories_to_retain},${{ inputs.additional-unit-test-report-directories }}"
fi
IFS=',' read -ra DIRECTORIES_TO_RETAIN <<< "$directories_to_retain"
echo "The following directories will be retained:"
for dir in "${DIRECTORIES_TO_RETAIN[@]}"; do
echo "$dir"
done
# Remove all files from GH_PAGES_DIR, except any DIRECTORIES_TO_RETAIN.
find $GH_PAGES_DIR -mindepth 1 -maxdepth 1 -print0 | while IFS= read -r -d '' file; do
file_to_be_removed="true"
# Check if the file/directory matches any directory to be retained.
for dir in "${DIRECTORIES_TO_RETAIN[@]}"; do
if [[ "$GH_PAGES_DIR/$dir" == "$file" ]]; then
echo "Not removing $file"
file_to_be_removed="false"
fi
done
if [[ "$file_to_be_removed" == "true" ]]; then
echo "Removing $file"
rm -rf "$file"
fi
done
echo "::group::gh-pages contents"
echo "Current contents of $GH_PAGES_DIR:"
ls -l $GH_PAGES_DIR
echo "::endgroup::"
# Copy generated pkgdown documentation to gh-pages branch.
cp -a ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}/docs/. $GH_PAGES_DIR
echo "::group::gh-pages contents"
echo "Current contents of $GH_PAGES_DIR:"
ls -l $GH_PAGES_DIR
echo "::endgroup::"
cd gh-pages
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git config pull.rebase false
git status
# Random delay
sleep $((RANDOM % 10))
git pull origin gh-pages || true
git add -f .
git commit -m "Update pkgdown documentation ${{ github.sha }}" || true
git push origin gh-pages
shell: bash
- name: Create documentation artifact π
if: github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/v')
run: |
pushd ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}/docs/
zip -r9 $OLDPWD/pkgdown.zip *
popd
shell: bash
- name: Upload docs for review β¬
if: github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
with:
name: pkgdown.zip
path: pkgdown.zip
multi-version-docs:
name: Multi-version docs π
needs: docs
runs-on: ubuntu-latest
if: >
(github.event_name == 'push' || github.event_name == 'workflow_dispatch')
&& !contains(github.event.commits[0].message, '[skip docs]')
steps:
- name: Checkout repo π
uses: actions/[email protected]
with:
path: ${{ github.event.repository.name }}
ref: "gh-pages"
- name: Normalize inputs π
id: normalize
run: |
DEFAULT_LANDING_PAGE="${{ inputs.default-landing-page }}"
if [ "$DEFAULT_LANDING_PAGE" == "" ]
then {
DEFAULT_LANDING_PAGE=main
}
fi
echo "default-landing-page=$DEFAULT_LANDING_PAGE" >> "$GITHUB_ENV"
shell: bash
- name: Create and publish docs βοΈ
uses: insightsengineering/r-pkgdown-multiversion@v2
with:
path: ${{ github.event.repository.name }}
default-landing-page: ${{ env.default-landing-page }}
refs-order: ${{ inputs.refs-order }}
latest-tag-alt-name: ${{ inputs.latest-tag-alt-name }}
release-candidate-alt-name: ${{ inputs.release-candidate-alt-name }}
branches-or-tags-to-list: ${{ inputs.branches-or-tags-to-list }}
upload-release-assets:
name: Upload documentation assets πΌ
needs: docs
runs-on: ubuntu-latest
if: >
startsWith(github.ref, 'refs/tags/v')
&& !contains(github.event.commits[0].message, '[skip docs]')
steps:
- name: Checkout repo π
uses: actions/[email protected]
- name: Download artifact β¬
uses: actions/download-artifact@v4
with:
name: pkgdown.zip
- name: Check if release exists β
id: check-if-release-exists
uses: insightsengineering/release-existence-action@v1
- name: Upload binaries to release ‴
if: >-
steps.check-if-release-exists.outputs.release-exists == 'true'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: pkgdown.zip
asset_name: pkgdown.zip
tag: ${{ github.ref }}
overwrite: true