-
Notifications
You must be signed in to change notification settings - Fork 0
367 lines (347 loc) · 14.8 KB
/
Copy pathdocs.yml
File metadata and controls
367 lines (347 loc) · 14.8 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
name: reusable-docs
on:
workflow_call:
inputs:
python_version:
description: Python version used to build the documentation
required: true
type: string
dependency_group:
description: Optional uv dependency group installed before the build
required: false
default: dev
type: string
locked:
description: Require the checked-in uv lockfile to remain unchanged
required: false
default: true
type: boolean
generated_docs_check_task:
description: Optional client-owned Poe task that checks generated documentation
required: false
default: ''
type: string
site_path:
description: Directory containing the rendered static site
required: false
default: site
type: string
artifact_name:
description: Name of the uploaded documentation artifact
required: false
default: docs-site
type: string
deploy_github_pages:
description: Deploy the rendered site to GitHub Pages
required: false
default: false
type: boolean
publish_cloudflare:
description: Publish an internal pull request to Cloudflare Pages
required: false
default: false
type: boolean
cloudflare_project_name:
description: Cloudflare Pages Direct Upload project to create when absent and deploy previews to
required: false
default: ''
type: string
cloudflare_production_branch:
description: Production branch assigned if the Cloudflare Pages project is created
required: false
default: main
type: string
cloudflare_preview_domain:
description: Base custom domain for pull-request previews, such as preview.example.com
required: false
default: ''
type: string
cloudflare_preview_zone:
description: Cloudflare DNS zone containing the preview domain; defaults to the preview domain
required: false
default: ''
type: string
secrets:
cloudflare_account_id:
description: Cloudflare account containing the Pages project
required: false
cloudflare_api_token:
description: Cloudflare API token with Pages write access
required: false
outputs:
preview_url:
description: Stable Cloudflare Pages branch alias when a preview was published
value: ${{ jobs.build.outputs.preview_url }}
jobs:
build:
name: Build documentation
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pages: write
outputs:
preview_url: ${{ steps.preview_url.outputs.url }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up Python ${{ inputs.python_version }}
uses: actions/setup-python@v7
with:
python-version: ${{ inputs.python_version }}
- name: Set up uv
uses: astral-sh/setup-uv@v10.0.1
- name: Install dependencies
env:
DEPENDENCY_GROUP: ${{ inputs.dependency_group }}
LOCKED: ${{ inputs.locked }}
run: |
args=(sync)
if [[ "$LOCKED" == "true" ]]; then
args+=(--locked)
fi
if [[ -n "$DEPENDENCY_GROUP" ]]; then
args+=(--group "$DEPENDENCY_GROUP")
fi
uv "${args[@]}"
- name: Check generated documentation
if: inputs.generated_docs_check_task != ''
env:
GENERATED_DOCS_CHECK_TASK: ${{ inputs.generated_docs_check_task }}
run: |
if [[ ! "$GENERATED_DOCS_CHECK_TASK" =~ ^[A-Za-z0-9_-]+$ ]]; then
echo "Invalid generated documentation check task: $GENERATED_DOCS_CHECK_TASK" >&2
exit 2
fi
uv run poe "$GENERATED_DOCS_CHECK_TASK"
- name: Build documentation site
run: uv run poe docs-build
- name: Upload documentation artifact
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact_name }}
path: ${{ inputs.site_path }}/
if-no-files-found: error
- name: Validate Cloudflare preview configuration
if: inputs.publish_cloudflare
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.cloudflare_account_id }}
CLOUDFLARE_API_TOKEN: ${{ secrets.cloudflare_api_token }}
CLOUDFLARE_PROJECT_NAME: ${{ inputs.cloudflare_project_name }}
run: |
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
echo "Cloudflare documentation previews require a pull request event." >&2
exit 2
fi
if [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]]; then
echo "Cloudflare publication is unavailable for fork pull requests." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
if [[ -z "$CLOUDFLARE_PROJECT_NAME" || -z "$CLOUDFLARE_ACCOUNT_ID" || -z "$CLOUDFLARE_API_TOKEN" ]]; then
echo "Cloudflare project name, account ID, and API token are required." >&2
exit 2
fi
- name: Ensure Cloudflare Pages project
if: >-
inputs.publish_cloudflare &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.cloudflare_account_id }}
CLOUDFLARE_API_TOKEN: ${{ secrets.cloudflare_api_token }}
CLOUDFLARE_PROJECT_NAME: ${{ inputs.cloudflare_project_name }}
CLOUDFLARE_PRODUCTION_BRANCH: ${{ inputs.cloudflare_production_branch }}
run: |
project_url="https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/$CLOUDFLARE_PROJECT_NAME"
project_status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"$project_url")"
case "$project_status" in
200)
echo "Cloudflare Pages project already exists."
;;
404)
create_status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header 'Content-Type: application/json' \
--data "$(jq --null-input \
--arg name "$CLOUDFLARE_PROJECT_NAME" \
--arg production_branch "$CLOUDFLARE_PRODUCTION_BRANCH" \
'{name: $name, production_branch: $production_branch}')" \
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects")"
case "$create_status" in
200|201)
echo "Created Cloudflare Pages project."
;;
409)
project_status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"$project_url")"
if [[ "$project_status" != "200" ]]; then
echo "Cloudflare Pages project creation conflicted and the project is unavailable." >&2
exit 1
fi
echo "Cloudflare Pages project was created by another workflow run."
;;
*)
echo "Could not create Cloudflare Pages project (HTTP $create_status)." >&2
exit 1
;;
esac
;;
*)
echo "Could not retrieve Cloudflare Pages project (HTTP $project_status)." >&2
exit 1
;;
esac
- name: Publish Cloudflare Pages preview
id: cloudflare
if: >-
inputs.publish_cloudflare &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
uses: cloudflare/wrangler-action@v4
with:
accountId: ${{ secrets.cloudflare_account_id }}
apiToken: ${{ secrets.cloudflare_api_token }}
command: >-
pages deploy ${{ inputs.site_path }}
--project-name=${{ inputs.cloudflare_project_name }}
--branch=pr-${{ github.event.pull_request.number }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Cloudflare Pages custom preview domain
id: custom_preview_domain
if: >-
steps.cloudflare.outputs.pages-deployment-alias-url != '' &&
inputs.cloudflare_preview_domain != ''
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.cloudflare_account_id }}
CLOUDFLARE_API_TOKEN: ${{ secrets.cloudflare_api_token }}
CLOUDFLARE_PREVIEW_BRANCH: pr-${{ github.event.pull_request.number }}
CLOUDFLARE_PREVIEW_DOMAIN: ${{ inputs.cloudflare_preview_domain }}
CLOUDFLARE_PREVIEW_ZONE: ${{ inputs.cloudflare_preview_zone }}
CLOUDFLARE_PROJECT_NAME: ${{ inputs.cloudflare_project_name }}
run: |
custom_domain="$CLOUDFLARE_PREVIEW_BRANCH.$CLOUDFLARE_PREVIEW_DOMAIN"
pages_target="$CLOUDFLARE_PREVIEW_BRANCH.$CLOUDFLARE_PROJECT_NAME.pages.dev"
if [[ -z "$CLOUDFLARE_PREVIEW_ZONE" ]]; then
CLOUDFLARE_PREVIEW_ZONE="$CLOUDFLARE_PREVIEW_DOMAIN"
fi
zone_response="$(curl --fail --silent --show-error \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/zones?name=$CLOUDFLARE_PREVIEW_ZONE")"
zone_id="$(jq --raw-output '.result[0].id // empty' <<< "$zone_response")"
if [[ -z "$zone_id" ]]; then
echo "No Cloudflare zone exists for $CLOUDFLARE_PREVIEW_ZONE." >&2
exit 1
fi
domain_url="https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/$CLOUDFLARE_PROJECT_NAME/domains/$custom_domain"
domain_status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"$domain_url")"
case "$domain_status" in
200)
echo "Cloudflare Pages custom domain already exists."
;;
404)
create_status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header 'Content-Type: application/json' \
--data "$(jq --null-input --arg name "$custom_domain" '{name: $name}')" \
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/$CLOUDFLARE_PROJECT_NAME/domains")"
case "$create_status" in
200|201)
echo "Added Cloudflare Pages custom domain."
;;
409)
echo "Cloudflare Pages custom domain was added concurrently."
;;
*)
echo "Could not add Cloudflare Pages custom domain (HTTP $create_status)." >&2
exit 1
;;
esac
;;
*)
echo "Could not retrieve Cloudflare Pages custom domain (HTTP $domain_status)." >&2
exit 1
;;
esac
record_response="$(curl --fail --silent --show-error \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?type=CNAME&name=$custom_domain")"
record_id="$(jq --raw-output '.result[0].id // empty' <<< "$record_response")"
record_data="$(jq --null-input \
--arg content "$pages_target" \
--arg name "$custom_domain" \
'{type: "CNAME", name: $name, content: $content, proxied: true}')"
if [[ -n "$record_id" ]]; then
curl --fail --silent --show-error \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header 'Content-Type: application/json' \
--data "$record_data" \
"https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id" > /dev/null
else
curl --fail --silent --show-error \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header 'Content-Type: application/json' \
--data "$record_data" \
"https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records" > /dev/null
fi
domain_response="$(curl --fail --silent --show-error \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"$domain_url")"
if [[ "$(jq --raw-output '.result.status' <<< "$domain_response")" == "active" ]]; then
echo "url=https://$custom_domain" >> "$GITHUB_OUTPUT"
else
echo "Cloudflare custom domain is pending activation; using the Pages preview URL."
fi
- name: Set Cloudflare preview URL
id: preview_url
if: steps.cloudflare.outputs.pages-deployment-alias-url != ''
env:
CUSTOM_PREVIEW_URL: ${{ steps.custom_preview_domain.outputs.url }}
PAGES_PREVIEW_URL: ${{ steps.cloudflare.outputs.pages-deployment-alias-url }}
run: |
if [[ -n "$CUSTOM_PREVIEW_URL" ]]; then
echo "url=$CUSTOM_PREVIEW_URL" >> "$GITHUB_OUTPUT"
else
echo "url=$PAGES_PREVIEW_URL" >> "$GITHUB_OUTPUT"
fi
- name: Summarize Cloudflare preview
if: steps.preview_url.outputs.url != ''
env:
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
PREVIEW_URL: ${{ steps.preview_url.outputs.url }}
run: |
echo "## Documentation preview" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "[$PREVIEW_URL]($PREVIEW_URL) for commit \`$COMMIT_SHA\`." >> "$GITHUB_STEP_SUMMARY"
- name: Configure GitHub Pages
if: inputs.deploy_github_pages
uses: actions/configure-pages@v6
- name: Upload GitHub Pages artifact
if: inputs.deploy_github_pages
uses: actions/upload-pages-artifact@v5
with:
path: ${{ inputs.site_path }}/
deploy:
name: Deploy documentation
if: inputs.deploy_github_pages
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5