generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 4
214 lines (178 loc) · 6.62 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
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
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, prod]
pull_request:
branches: [main, prod]
release:
types: [published]
workflow_dispatch:
name: pkgdown
jobs:
build:
strategy:
matrix:
version:
- 'release'
- 'devel'
name: pkgdown site build (${{ matrix.version }})
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}-${{ matrix.version }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
id-token: write
pages: write
steps:
##########################################################################
# Identifying the latest and corresponding tag/sha to download
#########################################################################
- name: Check the repo to download
id: commit
run: |
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/CDCgov/ww-inference-model/releases/latest > \
latest_release
echo -n "This job is running on tag/sha: "
if [ "${{ matrix.version }}" = "release" ]; then
echo $(jq -r '.tag_name' latest_release)
echo "tag=$(jq -r '.tag_name' latest_release)" >> $GITHUB_OUTPUT
else
echo "tag=${{ github.sha }}" >> $GITHUB_OUTPUT
echo ${{ github.sha }}
fi
- uses: actions/checkout@v4
with:
ref: ${{ steps.commit.outputs.tag }}
- name: Checkout the sha-associated repo
if: ${{ matrix.version == 'release' }}
uses: actions/checkout@v4
with:
sparse-checkout: './_pkgdown.yml'
path: pkgdown-${{ github.sha}}
- name: Overwriting the _pkgdown.yml
if: ${{ matrix.version == 'release' }}
run: |
cp pkgdown-${{ github.sha }}/_pkgdown.yml ./
rm -rf pkgdown-${{ github.sha }}
- name: Checking if the release is cached
if: ${{ matrix.version == 'release' }}
id: cache-hit
uses: actions/cache@v3
with:
key: pkgdown_site-${{ matrix.version }}-${{ steps.commit.outputs.tag }}-${{ hashFiles( './_pkgdown.yml' ) }}
path: './docs/'
# These steps only happen if the cache is not hit
- uses: r-lib/actions/setup-pandoc@v2
if: ${{ matrix.version != 'release' || steps.cache-hit.outputs.cache-hit != 'true' }}
with:
pandoc-version: "2.19.2"
- uses: r-lib/actions/setup-r@v2
if: ${{ matrix.version != 'release' || steps.cache-hit.outputs.cache-hit != 'true' }}
with:
r-version: "release"
use-public-rspm: true
install-r: false
extra-repositories: "https://mc-stan.org/r-packages/"
- uses: r-lib/actions/setup-r-dependencies@v2
if: ${{ matrix.version != 'release' || steps.cache-hit.outputs.cache-hit != 'true' }}
with:
pak-version: rc
extra-packages: any::pkgdown local::.
needs: website
- name: "Install cmdstan via cmdstanr"
uses: epinowcast/actions/install-cmdstan@v1
if: ${{ matrix.version != 'release' || steps.cache-hit.outputs.cache-hit != 'true' }}
with:
cmdstan-version: "latest"
- name: Build site
if: ${{ matrix.version != 'release' || steps.cache-hit.outputs.cache-hit != 'true' }}
run: |
# Changing the URL if it is a development build
if [ "${{ matrix.version }}" = "devel" ]; then
# Forcing the development mode
export PKGDOWN_DEV_MODE="devel"
else
# Setting the url
sed -i'' 's|url: https://cdcgov.github.io/ww-inference-model/|url: https://cdcgov.github.io/ww-inference-model/release/|' _pkgdown.yml
# Changing the navbar
sed -i'' 's|href: https://cdcgov.github.io/ww-inference-model/release|href: https://cdcgov.github.io/ww-inference-model/|' _pkgdown.yml
sed -i'' 's|text: (switch to release)|text: (switch to dev)|' _pkgdown.yml
sed -i'' 's|icon: fa-toggle-on|icon: fa-toggle-off|' _pkgdown.yml
# Forcing the release mode
export PKGDOWN_DEV_MODE="release"
fi
Rscript --vanilla -e \
"pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)"
if [ "${{ matrix.version }}" = "devel" ]; then
mv docs docs-tmp
mkdir docs
mv docs-tmp/dev/* docs
fi
- name: Upload artifact for GH pages deployment
id: upload-artifact
uses: actions/upload-artifact@v4
with:
path: "./docs/"
name: pkgdown-site-${{ matrix.version }}
combine:
outputs:
page_artifact_id: ${{ steps.upload-artifact.outputs.artifact_id }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Download dev artifact
uses: actions/download-artifact@v4
with:
name: pkgdown-site-devel
path: ./docs/
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
name: pkgdown-site-release
path: ./docs/release
- name: Upload pages artifact
id: upload-artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./docs/
name: github-pages
retention-days: 7
deploy:
# check builds on PRs but only deploy when main changes
if: ${{ github.event_name != 'pull_request' }}
needs: combine
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub pages
uses: actions/deploy-pages@v4
post-page-artifact:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
# This job depends on the `build` job
needs: combine
# Required permissions
permissions:
contents: read
pull-requests: write
steps:
# Post the artifact pulling the id from the `readme` step.
# The msg will refer to the arfitact as 'README file'.
- name: Post the artifact
uses: CDCgov/cfa-actions/[email protected]
with:
artifact-name: github-pages
gh-token: ${{ secrets.GITHUB_TOKEN }}