-
Notifications
You must be signed in to change notification settings - Fork 8
399 lines (373 loc) · 17.1 KB
/
_shared-docs-build-pr.yml
File metadata and controls
399 lines (373 loc) · 17.1 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
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
395
396
397
398
399
---
name: Ansible collection docs build (PR)
on:
workflow_call:
inputs:
collection-name:
description: The collection name in the form namespace.collection.
required: false
type: string
default: ${{ github.event.repository.name }}
collection-path:
description: This is the relative path component of the collection in question, for example community/general.
required: false
type: string
python:
description: The version of Python to install.
required: false
type: string
default: '3.13'
ansible-ref:
description: The ref from which to install ansible, for example "stable-2.14" or "milestone".
required: false
type: string
default: stable-2.18
init-dest-dir:
description: A directory relative to the checkout where the init process has already been run.
required: false
type: string
init-lenient:
description: |
Use the lenient option during build init. Has no effect if init-dest-dir is supplied.
This is only passed to the HEAD build. The BASE build always runs with `true`.
required: false
type: boolean
default: false
init-fail-on-error:
description: |
Use the fail-on-error option during build init. Has no effect if init-dest-dir is supplied.
This is only passed to the HEAD build. The BASE build always runs with `false`.
required: false
type: boolean
default: false
init-antsibull-docs-version:
description: |
The version of antsibull-docs to use during build init. Has no effect if init-dest-dir is supplied.
If not supplied, the latest version from PyPI is used. If supplied, must be a git ref from the antsibull-docs repository.
required: false
type: string
init-antsibull-docs-repository:
description: |
When init-antsibull-docs-version is specified, this is the GitHub repository to which init-antsibull-docs-version refers.
Has no effect if init-dest-dir is supplied, or if init-antsibull-docs-version is not supplied.
required: false
type: string
default: ansible-community/antsibull-docs
init-index-rst-source:
description: |
Copy the provided file to `rst/index.rst` intead of templating a default one.
required: false
type: string
init-project:
description: |
Sets the `project` value in the Sphinx configuration.
required: false
type: string
init-copyright:
description: |
Sets the `copyright` value in the Sphinx configuration.
required: false
type: string
init-title:
description: |
Sets the `title` and `html_short_title` values in the Sphinx configuration.
If `init-html-short-title` is also specified, only `title` will be set to the value
specified here.
required: false
type: string
init-html-short-title:
description: |
Sets the `html_short_title` value in the Sphinx configuration. If not specified,
the value of `init-title` will be used.
required: false
type: string
init-extra-conf:
description: |
A newline separated list of `key=value` entries that will be added to the generated
`conf.py`.
required: false
type: string
init-extra-html-context:
description: |
A newline separated list of `key=value` entries that will be added to the generated
`conf.py` in `html_context`
required: false
type: string
init-extra-html-theme-options:
description: |
A newline separated list of `key=value` entries that will be added to the generated
`conf.py` in `html_theme_options`
required: false
type: string
init-append-conf-py:
description: |
If provided, this text will be appended to the generated `conf.py` as-is.
required: false
type: string
artifact-name:
description: The name of the artifact to upload.
required: false
type: string
default: ${{ github.event.repository.name }}_docs_${{ github.event.pull_request.head.sha }}
diff-size-limit:
description: The max size of the diff, past which it will be truncated.
required: false
type: number
default: 60000
sort-files:
description: If true, sort the trimmed and rendered list of files.
required: false
default: true
type: boolean
render-file-line:
description: |
A template used to render each line of the file list as markdown. This will be processed as a JavaScript regex replace string,
and the following named capture groups can be referenced:
- $<status> -- the single character "status" letter in the file list, like "A" or an added file or "M" for a modified file.
- $<path_stub> -- the part of the path that will be discarded in the "trimmed" file list.
- $<path_tail> -- the relative part of the path; this can be used to concatenate to a URL to create links to the published site.
Note that literal $ characters must be escaped as $$ and literal backslashes must be escaped as \\
required: false
default: '> * `$<status>` $<path_tail>'
type: string
render-diff-truncate-text:
description: Markdown text to be used if the diff text was truncated. It will be available in the render-diff template.
required: false
default: '**The diff output was truncated because it exceeded the maximum size.**'
type: string
render-diff:
description: |
A template used to render the diff output as markdown. It will be interpreted as a pseudo-JavaScript template literal and the following
variables are available for ${var} interpolation:
- ${diff} -- the diff text
- ${truncated_msg} -- empty if the diff is not truncated, otherwise the value of render-diff-truncate-text
required: false
type: string
default: |
<details>
<summary>Click to see the diff comparison.</summary>
**NOTE:** only file modifications are shown here. New and deleted files are excluded.
See the file list and check the published docs to see those files.
${truncated_msg}
```diff
${diff}
```
</details>
extra-collections:
description: A space separated list of additional collections to install prior to building the documentation.
required: false
type: string
provide-link-targets:
description: A newline separated list of link targets that should not cause reference errors. A small RST file will be created during the build which contains these labels.
required: false
type: string
intersphinx-links:
description: |
A newline separated list of entries to add to the intersphinx_mapping in the generated conf.py.
Use the syntax `identifier:https://server/path` to add the identifier `identifier` with URL
`https://server/path`.
required: false
type: string
squash-hierarchy:
description: |
If 'true', the collection documentation will be created at top-level and not in a subdirectory `namespace/collection_name/`.
Has no effect if init-dest-dir is supplied.
required: false
type: boolean
default: false
outputs:
artifact-name:
description: The same artifact name as passed in, available as an output.
value: ${{ inputs.artifact-name }}
artifact-url:
description: The URL to the build artifacts.
value: ${{ jobs.build-ansible-docs.outputs.artifact-url }}
changed:
description: If false, the PR does not change the documentation.
value: ${{ jobs.build-ansible-docs.outputs.changed }}
diff:
description: The diff between the base and head of the PR.
value: ${{ jobs.build-ansible-docs.outputs.diff }}
diff-truncated:
description: If true, the diff was truncated because it exceeded the max size.
value: ${{ jobs.build-ansible-docs.outputs.diff-truncated }}
diff-rendered:
description: The markdownr rendered diff between the base and head of the PR.
value: ${{ jobs.build-ansible-docs.outputs.diff-rendered }}
diff-files:
description: The raw file list from the diff output.
value: ${{ jobs.build-ansible-docs.outputs.diff-files }}
diff-files-trimmed:
description: The file list from the diff with the paths trimmed.
value: ${{ jobs.build-ansible-docs.outputs.diff-files-trimmed }}
diff-files-rendered:
description: The markdown rendered file list from the diff.
value: ${{ jobs.build-ansible-docs.outputs.diff-files-rendered }}
jobs:
build-ansible-docs:
name: Build Ansible Docs
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
artifact-url: ${{ steps.build-head.outputs.artifact-url }}
changed: ${{ steps.build-base.outputs.hash != steps.build-head.outputs.hash }}
diff: ${{ steps.diff.outputs.diff }}
diff-truncated: ${{ steps.diff.outputs.truncated }}
diff-rendered: ${{ steps.diff.outputs.diff-rendered }}
diff-files: ${{ steps.diff.outputs.files-raw }}
diff-files-trimmed: ${{ steps.diff.outputs.files-trimmed }}
diff-files-rendered: ${{ steps.diff.outputs.files-rendered }}
steps:
- name: Variable setup
id: vars
uses: actions/github-script@v9
env:
RUNNER_TEMP: ${{ runner.temp }}
EVENT_ACTION: ${{ github.event.action }}
MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }}
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
with:
script: |
const inputs = ${{ toJSON(inputs) }}
var colpath = inputs['collection-path']
if (colpath == '') {
colpath = inputs['collection-name'].replace('.', '/')
}
core.exportVariable('ANSIBLE_COLLECTIONS_PATH', process.env.GITHUB_WORKSPACE)
const checkoutPath = `ansible_collections/${colpath}`
core.setOutput('col-path', colpath)
core.setOutput('checkout-path', checkoutPath)
const { RUNNER_TEMP, EVENT_ACTION, MERGE_COMMIT_SHA, GITHUB_EVENT_NUMBER } = process.env
var initPath = `${RUNNER_TEMP}/docsbuild`
var skipInit = false
if (inputs['init-dest-dir'] != '') {
initPath = `${checkoutPath}/${inputs['init-dest-dir']}`
skipInit = true
core.setOutput('init-dir-base', initPath)
core.setOutput('init-dir-head', initPath)
} else {
core.setOutput('init-dir-base', `${initPath}/base`)
core.setOutput('init-dir-head', `${initPath}/head`)
}
core.setOutput('skip-init', skipInit)
// The merge branch is what we want, but it doesn't exist
// on closed events. The merge SHA does exist though and
// should be correct. The merge SHA does not exist when a
// PR is first opened, and on subsequent updates it is
// tricky to use; used directly it is probably stale, and
// would need additional API calls to get the correct value.
// See also:
// - https://github.com/ansible-community/github-docs-build/issues/36
if (`${EVENT_ACTION}` == 'closed') {
core.setOutput('pr-checkout-ref', `${MERGE_COMMIT_SHA}`)
} else {
core.setOutput('pr-checkout-ref', `refs/pull/${GITHUB_EVENT_NUMBER}/merge`)
}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python }}
- name: Install Ansible
env:
ANSIBLE_REF: ${{ inputs.ansible-ref }}
run: pip install "https://github.com/ansible/ansible/archive/${ANSIBLE_REF}.tar.gz" --disable-pip-version-check
- name: Install extra collections
shell: bash
env:
EXTRA_COLLECTIONS: ${{ inputs.extra-collections }}
run: |
if [[ "${EXTRA_COLLECTIONS}" != "" ]] ; then
ansible-galaxy collection install ${EXTRA_COLLECTIONS}
fi
- name: Checkout BASE
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.sha }}
path: ${{ steps.vars.outputs.checkout-path }}
persist-credentials: false
- name: Initialize the build environment (BASE)
id: init-base
uses: ansible-community/github-docs-build/actions/ansible-docs-build-init@main
with:
collections: ${{ inputs.collection-name }}
dest-dir: ${{ steps.vars.outputs.init-dir-base }}
skip-init: ${{ steps.vars.outputs.skip-init }}
antsibull-docs-version: '${{ inputs.init-antsibull-docs-version }}'
antsibull-docs-repository: '${{ inputs.init-antsibull-docs-repository }}'
lenient: true
fail-on-error: false
provide-link-targets: ${{ inputs.provide-link-targets }}
intersphinx-links: ${{ inputs.intersphinx-links }}
squash-hierarchy: ${{ inputs.squash-hierarchy }}
index-rst-source: ${{ inputs.init-index-rst-source }}
project: ${{ inputs.init-project }}
copyright: ${{ inputs.init-copyright }}
title: ${{ inputs.init-title }}
html-short-title: ${{ inputs.init-html-short-title }}
extra-conf: ${{ inputs.init-extra-conf }}
extra-html-context: ${{ inputs.init-extra-html-context }}
extra-html-theme-options: ${{ inputs.init-extra-html-theme-options }}
append-conf-py: ${{ inputs.init-append-conf-py }}
- name: Build BASE
id: build-base
uses: ansible-community/github-docs-build/actions/ansible-docs-build-html@main
with:
build-script: ${{ steps.init-base.outputs.build-script }}
build-html: ${{ steps.init-base.outputs.build-html }}
copy-build: ${{ github.workspace }}/docsbuild/base
artifact-upload: 'false'
- name: Checkout HEAD
uses: actions/checkout@v6
with:
# It would be better to use
#
# ref: ${{ github.event.pull_request.head.sha }}
#
# since that also works when re-running this action for older commits of
# a PR, **but** then we get https://github.com/ansible-community/github-docs-build/issues/3 back...
ref: ${{ steps.vars.outputs.pr-checkout-ref }}
path: ${{ steps.vars.outputs.checkout-path }}
persist-credentials: false
- name: Initialize the build environment (HEAD)
id: init-head
uses: ansible-community/github-docs-build/actions/ansible-docs-build-init@main
with:
collections: ${{ inputs.collection-name }}
dest-dir: ${{ steps.vars.outputs.init-dir-head }}
skip-init: ${{ steps.vars.outputs.skip-init }}
antsibull-docs-version: '${{ inputs.init-antsibull-docs-version }}'
antsibull-docs-repository: '${{ inputs.init-antsibull-docs-repository }}'
lenient: ${{ inputs.init-lenient }}
fail-on-error: ${{ inputs.init-fail-on-error }}
provide-link-targets: ${{ inputs.provide-link-targets }}
intersphinx-links: ${{ inputs.intersphinx-links }}
squash-hierarchy: ${{ inputs.squash-hierarchy }}
index-rst-source: ${{ inputs.init-index-rst-source }}
project: ${{ inputs.init-project }}
copyright: ${{ inputs.init-copyright }}
title: ${{ inputs.init-title }}
html-short-title: ${{ inputs.init-html-short-title }}
extra-conf: ${{ inputs.init-extra-conf }}
extra-html-context: ${{ inputs.init-extra-html-context }}
extra-html-theme-options: ${{ inputs.init-extra-html-theme-options }}
append-conf-py: ${{ inputs.init-append-conf-py }}
- name: Build HEAD
id: build-head
uses: ansible-community/github-docs-build/actions/ansible-docs-build-html@main
with:
build-script: ${{ steps.init-head.outputs.build-script }}
build-html: ${{ steps.init-head.outputs.build-html }}
copy-build: ${{ github.workspace }}/docsbuild/head
artifact-name: ${{ inputs.artifact-name }}
- name: Get a diff of the changes
if: steps.build-base.outputs.hash != steps.build-head.outputs.hash
id: diff
uses: ansible-community/github-docs-build/actions/ansible-docs-build-diff@main
with:
build-html-a: ${{ steps.build-base.outputs.build-html }}
build-html-b: ${{ steps.build-head.outputs.build-html }}
diff-size-limit: ${{ inputs.diff-size-limit }}
render-file-line: ${{ inputs.render-file-line }}
render-diff-truncate-text: ${{ inputs.render-diff-truncate-text }}
render-diff: ${{ inputs.render-diff }}