-
Notifications
You must be signed in to change notification settings - Fork 24
366 lines (348 loc) · 14.8 KB
/
docs.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
# Build the main or dev websites
#########
# IMPORTANT: it is also responsible for merging the `tmp_evaluated_fghgf_{PRBranchName}` branch
# into `evaluated` and PUSHING that change to `evaluated`.
# This happens whenever a PR is merged.
########
# Runs on:
# - merged PRs: merge `tmp_evaluated_fghgf_{PRBranchName}` into`evaluated
# ,push to `evaluated` and build main site
# - workflow_call (from pr_flow.yml):
# - at least one project built: pull the `tmp_evaluated_fghgf_{PRBranchName}`
# and `evaluated` branches, merge locally (NOT pushed), and build the dev site
# - no project built, checkout `evaluated` and build main site
# - workflow_dispatch: checkout `evaluated` and build main or dev site
# - schedule: checkout `evaluated`, don't build any site
name: docs
on:
pull_request:
branches:
- "main"
types:
- closed
workflow_call:
inputs:
target:
description: Site to build and deploy, dev or main
type: string
required: true
default: dev
branch:
description: Branch suffix to pull the evaluated projects from
type: string
required: true
default: ''
type:
description: hack
required: true
type: string
changedprojects:
description: Projects that have been built on the temp branch
type: string
required: false
removedprojects:
description: Projects that should be removed
type: string
required: false
workflow_dispatch:
inputs:
target:
description: Site to build and deploy
type: choice
options:
- dev
- main
- dryrun
required: true
default: dryrun
schedule:
- cron: '0 2 * * SUN'
jobs:
build_docs:
# On merged PRs, workflow_call (pull_request event) or other events that can trigger this workflow (see above)
if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && inputs.type == 'workflow_call') || github.event.pull_request.merged == true
name: Documentation
runs-on: 'ubuntu-latest'
timeout-minutes: 30
defaults:
run:
shell: bash -el {0}
steps:
- uses: actions/checkout@v3
with:
# Needed to compute the diff between the head and the latest commit on main
fetch-depth: 2
- uses: hmarr/debug-action@v2
- name: debug
run: |
echo ${{ github.ref_name }}
echo ${{ github.event_name }}
echo ${{ inputs.type }}
echo ${{ inputs.branch }}
- uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
auto-activate-base: false
activate-environment: examples-gallery-manage
environment-file: envs/environment-ubuntu-latest.lock
- name: infer evaluated branch name and deployment target
id: set-vars
run: |
EVENTNAME="${{ github.event_name }}"
# Called by pr_flow.yml, uses the tmp evaluated branch,
# github.event_name doesn't matter as we're using inputs.type to
# define the context.
if [ "${{ inputs.type }}" == "workflow_call" ]; then
NAME="tmp_evaluated_fghgf_${{ inputs.branch }}"
TARGET="dev"
# Merged PRs, use the evaluated branch
elif [ "$EVENTNAME" == "pull_request" -a "${{ github.event.pull_request.merged }}" == "true" ]; then
NAME="tmp_evaluated_fghgf_${{ github.event.pull_request.head.ref }}"
TARGET="main"
elif [ "$EVENTNAME" == "workflow_dispatch" ]; then
NAME="evaluated"
TARGET="${{ inputs.target }}"
elif [ "$EVENTNAME" == "schedule" ]; then
NAME="evaluated"
# schedule events do not deploy a dev site, they're dry run
TARGET=""
fi
echo "Evaluated branch: $NAME"
echo "Target: $TARGET"
echo "NAME=$NAME" >> $GITHUB_OUTPUT
echo "TARGET=$TARGET" >> $GITHUB_OUTPUT
- name: sync evaluated on merged PRs
# The `evaluated` branch is only updated when a PR is merged.
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
run: |
# We are on 'main' and the PR has just been merged into it.
# We need to:
# - find out which projects were changed/removed. If none, there's nothing to do, skip.
# - if some projects changed:
# - checkout the evaluated branch
# - add to that branch the projects than changed (we do it from the dev temp branch
# but could also do it from the main branch)
# - commit changes to evaluated
# - delete the dev tmp branch
# - checkout main back
git config user.email "travis@travis.org"
git config user.name "travis"
# git fetch and git diff
CHANGES=$(doit util_list_changed_dirs_with_last_commit | tail -n -1)
CHANGEDPROJECTS=$(echo $CHANGES | jq -c -r '.changed')
REMOVEDPROJECTS=$(echo $CHANGES | jq -c -r '.removed')
if [ "$CHANGEDPROJECTS" != "[]" -a "$REMOVEDPROJECTS" != "[]" ]; then
echo "No support for removing and updating projects together"
echo "Open a PR that just remove project"
exit 1
fi
if [ "$CHANGEDPROJECTS" != "[]" ]; then
# Some changes were made, the evaluated branch needs to be updated
# with new data stored in the tmp dev branch.
DEVBRANCH=${{ steps.set-vars.outputs.name }}
echo "Projects changed since last commit on main: $CHANGEDPROJECTS"
echo "Merging the $DEVBRANCH branch into the evaluated branch "
git fetch https://github.com/${GITHUB_REPOSITORY}.git evaluated:refs/remotes/evaluated
git fetch https://github.com/${GITHUB_REPOSITORY}.git $DEVBRANCH:refs/remotes/$DEVBRANCH
echo "Checkout the evaluated branch"
git checkout evaluated
git checkout -b evaluated
# Important: assumes there's no whitespace in the project names
echo "Parse projects to remove them"
items=$(echo $CHANGEDPROJECTS | jq -c -r '.[]')
for item in ${items[@]}; do
echo "Removing doc/$item..."
rm -rf doc/$item/
echo "Removed doc/$item"
done
echo "Pull evaluated docs from the deb branch"
git checkout $DEVBRANCH -- doc/
git diff
git add './doc/'
git commit -m "Add $CHANGEDPROJECTS"
git log -n 10 --oneline
echo "Push changes to evaluated"
git push "https://pyviz-developers:${{ secrets.GITHUB_TOKEN }}@github.com/holoviz-topics/examples.git" HEAD:evaluated
echo "Delete the dev evaluated branch $DEVBRANCH"
git push "https://pyviz-developers:${{ secrets.GITHUB_TOKEN }}@github.com/holoviz-topics/examples.git" --delete $DEVBRANCH
git checkout main
elif [ "$REMOVEDPROJECTS" != "[]" ]; then
# One of more projects have been removed, they need to be removed from
# the evaluated branch.
git config user.email "travis@travis.org"
git config user.name "travis"
git fetch https://github.com/${GITHUB_REPOSITORY}.git evaluated:refs/remotes/evaluated
echo "Checkout the evaluated branch"
git checkout evaluated
git checkout -b evaluated
echo "Parse projects to remove them"
items=$(echo $REMOVEDPROJECTS | jq -c -r '.[]')
for item in ${items[@]}; do
echo "Removing doc/$item..."
rm -rf doc/$item/
echo "Removed doc/$item"
git add './doc/$item'
done
git commit -m "Remove $REMOVEDPROJECTS"
git log -n 10 --oneline
echo "Push changes to evaluated"
git push "https://pyviz-developers:${{ secrets.GITHUB_TOKEN }}@github.com/holoviz-topics/examples.git" HEAD:evaluated
fi
- name: checkout evaluated
# any event that isn't workflow_call (coming from pr_flow.yml)
# workflow_call events that didn't update any project at all
if: inputs.type != 'workflow_call' || (inputs.type == 'workflow_call' && inputs.changedprojects == '[]')
run: |
# Work from a temporary branch
git checkout -b deploy--temp-asdfghjkl
git fetch https://github.com/${GITHUB_REPOSITORY}.git evaluated:refs/remotes/evaluated
# Checkout only the /doc folder than contains the evaluated artefacts
git checkout evaluated -- ./doc
tree doc -L 2
- name: sync dev evaluated
# workflow_call events (coming from pr_flow.yml) that did update at least one project
if: inputs.type == 'workflow_call' && (inputs.changedprojects != '[]' || inputs.removedprojects != '[]' )
run: |
CHANGEDPROJECTS='${{ inputs.changedprojects }}'
REMOVEDPROJECTS='${{ inputs.removedprojects }}'
if [ "$CHANGEDPROJECTS" != "[]" ]; then
# We setup the repo so that it has the doc from the dev evaluated branch
# and from the evaluated branch
echo "Merging the $DEVBRANCH branch into the evaluated branch "
DEVBRANCH=${{ steps.set-vars.outputs.name }}
git config user.email "travis@travis.org"
git config user.name "travis"
git fetch https://github.com/${GITHUB_REPOSITORY}.git evaluated:refs/remotes/evaluated
git fetch https://github.com/${GITHUB_REPOSITORY}.git $DEVBRANCH:refs/remotes/$DEVBRANCH
git fetch https://github.com/${GITHUB_REPOSITORY}.git ${{ inputs.branch }}:refs/remotes/${{ inputs.branch }}
git fetch https://github.com/${GITHUB_REPOSITORY}.git main:refs/remotes/main
git checkout evaluated
git checkout -b evaluated
# Important: assumes there's no whitespace in the project names
echo "Parse projects to remove them"
items=$(echo $CHANGEDPROJECTS | jq -c -r '.[]')
for item in ${items[@]}; do
echo "Removing doc/$item..."
rm -rf doc/$item/
echo "Removed doc/$item"
done
# Checkout only the /doc folder than contains the evaluated artefacts
# we want to add to the evaluated branch, albeit just temporarily for this docs build
git checkout $DEVBRANCH -- doc/
git diff
# This isn't meant to be pushed, it's just for this docs build
git add './doc/'
git commit -m "Add $CHANGEDPROJECTS"
git checkout ${{ inputs.branch }}
# Checkout only the /doc folder than contains the evaluated artefacts
git checkout evaluated -- ./doc
git diff
git log -n 10 --oneline
tree doc -D -h
ls
elif [ "$REMOVEDPROJECTS" != "[]" ]; then
# We setup the repo so that it has the doc from the dev evaluated branch
# and from the evaluated branch
git config user.email "travis@travis.org"
git config user.name "travis"
git fetch https://github.com/${GITHUB_REPOSITORY}.git evaluated:refs/remotes/evaluated
git fetch https://github.com/${GITHUB_REPOSITORY}.git ${{ inputs.branch }}:refs/remotes/${{ inputs.branch }}
git fetch https://github.com/${GITHUB_REPOSITORY}.git main:refs/remotes/main
git checkout evaluated
git checkout -b evaluated
# Important: assumes there's no whitespace in the project names
echo "Parse projects to remove them"
items=$(echo $REMOVEDPROJECTS | jq -c -r '.[]')
for item in ${items[@]}; do
echo "Removing doc/$item..."
rm -rf doc/$item/
echo "Removed doc/$item"
git add './doc/$item'
done
git diff
# This isn't meant to be pushed, it's just for this docs build
git commit -m "Remove $REMOVEDPROJECTS"
git checkout ${{ inputs.branch }}
# Checkout only the /doc folder than contains the evaluated artefacts
git checkout evaluated -- ./doc
git diff
git log -n 10 --oneline
tree doc -D -h
ls
fi
- name: archive projects
run: |
doit doc_archive_projects
- name: move thumbnails
run: doit doc_move_thumbnails
- name: make assets
run: doit doc_move_assets
- name: "temp: remove non evaluated projects"
run: doit doc_remove_not_evaluated
- name: build dev website
if: steps.set-vars.outputs.target == 'dev'
env:
EXAMPLES_HOLOVIZ_DEV_SITE: 'true'
run: doit doc_build_website
- name: build main website
if: steps.set-vars.outputs.target == 'main'
run: doit doc_build_website
- name: build index redirects
run: doit doc_index_redirects
# ZIP and upload the built site:
# Only when called from pr_flow.yml. Done as multiple PRs can update the dev website
# concurrently, this offers a way to download the site and see it locally.
- name: zip built site
if: inputs.type == 'workflow_call'
run: zip -r builtdocs.zip builtdocs/
- uses: actions/upload-artifact@v3
if: inputs.type == 'workflow_call'
with:
name: website
path: builtdocs.zip
retention-days: 3
- name: delete zip
if: inputs.type == 'workflow_call'
run: rm builtdocs.zip
- name: Deploy dev
# workflow_call, by pr_flow.yml
# workflow_dispatch and dev target
if: steps.set-vars.outputs.target == 'dev'
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.ACCESS_TOKEN }}
external_repository: holoviz-dev/examples
publish_dir: ./builtdocs
force_orphan: true
- name: Deploy main
# merged PR
# workflow_dispatch and main target
if: steps.set-vars.outputs.target == 'main'
run: echo Deploy main
# TODO: uncomment this
# uses: peaceiris/actions-gh-pages@v3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: ./builtdocs
# cname: examples.holoviz.org
# force_orphan: true
- name: Clean up
run: doit clean --clean-dep doc_full
- name: debug
run: |
ls -hla
# TODO: re-enable git diff --quiet --exit-code
# - name: Check clean up
# run: git diff
# - name: Check clean up
# run: git diff --quiet --exit-code
- name: Comment PR
# Only display the comment in a pr_flow context
if: inputs.type == 'workflow_call'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Your changes were successfully integrated in the dev site, make sure to review
the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/.
You can also download an archive of the site from the workflow summary page which comes in handy
when your dev site built was overriden by another PR (we have a single dev site!).