-
Notifications
You must be signed in to change notification settings - Fork 2
159 lines (139 loc) · 5.22 KB
/
pkgdown.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
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
# Deploys pkgdown for Pull Requests, tags, and pushes to main branch
# PRs are deployed to /preview/pr<number>/
# Tags are deployed to /<tag>/
# copied from https://github.com/rstudio/education-workflows/blob/main/examples/pkgdown.yaml
# referred from https://github.com/r-lib/actions/issues/865
# more info: https://github.com/rstudio/education-workflows/tree/main/examples#deploy-pkgdown-to-github-pages-with-pr-previews-and-tagged-versions
on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- closed
paths:
- 'man/**'
- 'pkgdown/**'
- 'vignettes/**'
- '_quarto.yml'
- '.github/workflows/pkgdown.yaml'
- 'Readme.md'
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+' # build on version tags
- '!v[0-9]+.[0-9]+.[0-9]+.[0-9]+' # but not if version involves a dev component
branches:
- main
workflow_dispatch:
inputs:
tag:
description: Tag to deploy
required: true
default: ''
name: pkgdown
jobs:
pkgdown-build:
runs-on: ubuntu-latest
if: ${{ !(github.event_name == 'pull_request' && github.event.action == 'closed') }}
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- name: Configure git
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
- uses: r-lib/actions/pr-fetch@v2
if: ${{ github.event_name == 'pull_request' }}
with:
repo-token: ${{ github.token }}
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
needs: |
connect
website
extra-packages: |
local::.
r-lib/pkgdown
# If events is a PR, set subdir to 'preview/pr<pr_number>'
- name: "[PR] Set documentation subdirectory"
if: github.event_name == 'pull_request'
run: |
echo "PKGDOWN_DEV_MODE=unreleased" >> $GITHUB_ENV
echo "subdir=preview/pr${{ github.event.number }}" >> $GITHUB_ENV
# If event is a tag, set subdir to '<tag_name>'
- name: "[tag] Set documentation subdirectory"
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
run: |
echo "PKGDOWN_DEV_MODE=release" >> $GITHUB_ENV
echo "subdir=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
# If event is workflow_dispatch, set subdir to 'inputs.tag'
- name: '[dispatch] Set documentation subdirectory'
if: github.event_name == 'workflow_dispatch'
run: |
echo "subdir=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
- name: Debug subdir
run: |
echo "Subdir is set to: ${{ env.subdir }}"
- name: Deploy pkgdown site
id: deploy
shell: Rscript {0}
run: |
subdir <- "${{ env.subdir }}"
pkg <- pkgdown::as_pkgdown(".")
# Deploy pkgdown site to branch
pkgdown::deploy_to_branch(subdir = if (nzchar(subdir)) subdir, clean = nzchar(subdir))
# Report deployed site URL
deployed_url <- file.path(pkg$meta$url, subdir)
cat(sprintf('url=%s', deployed_url), file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE)
- name: Notify pkgdown deployment
if: github.event_name == 'pull_request'
uses: hasura/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: pkgdown-deploy
append: false
message: >
:book: ${{ steps.deploy.outputs.url }}
Preview documentation for this PR (at commit ${{ github.event.pull_request.head.sha }})
pkgdown-clean:
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }}
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
ref: "gh-pages"
- name: Clean up PR Preview
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
preview_dir="preview/pr${{ github.event.pull_request.number }}"
if [ -d "$preview_dir" ]; then
git rm -r $preview_dir
git commit -m "Remove $preview_dir (GitHub Actions)" || echo 'No preview to remove'
git push origin || echo 'No preview to remove'
else
echo 'No preview to remove'
fi
- name: Notify pkgdown cleanup
uses: hasura/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: pkgdown-deploy
message: |
_:closed_book: Preview documentation for this PR has been cleaned up._