-
Notifications
You must be signed in to change notification settings - Fork 61
396 lines (324 loc) · 15.7 KB
/
Copy pathupdate-ref-docs.yaml
File metadata and controls
396 lines (324 loc) · 15.7 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
name: Update Reference Documentation
on:
workflow_dispatch: # Allow manual triggers
schedule:
# Nightly at 06:30 UTC: regenerate API/Helm docs from the latest kagent/kmcp main so docs don't drift from code.
- cron: '30 6 * * *'
# Queue overlapping runs (e.g. nightly cron + a manual dispatch) so they don't force-push the same PR branch concurrently.
concurrency:
group: update-ref-docs
cancel-in-progress: false
# The docs are a Hugo site under docs-site/ (served at /docs). This workflow
# generates the reference pages directly as Hugo markdown into docs-site/content:
# - kagent CRD API ref -> docs-site/content/kagent/resources/api-ref.md
# - kmcp CRD API ref -> docs-site/content/kmcp/reference/api-ref.md
# - kagent Helm ref -> docs-site/content/kagent/resources/helm.md
# Each page uses plain Hugo YAML frontmatter (no MDX `export const metadata`).
jobs:
generate-api-docs:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
# Target Hugo content paths (relative to the website checkout).
env:
KAGENT_API_PAGE: docs-site/content/kagent/resources/api-ref.md
KMCP_API_PAGE: docs-site/content/kmcp/reference/api-ref.md
HELM_PAGE: docs-site/content/kagent/resources/helm.md
steps:
- name: Checkout kagent repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/kagent
path: kagent
- name: Checkout kmcp repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/kmcp
path: kmcp
- name: Checkout docs repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/website
path: website
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
cache: false
- name: Set kagent commit SHA
run: echo "KAGENT_COMMIT=$(cd kagent && git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Set kmcp commit SHA
run: echo "KMCP_COMMIT=$(cd kmcp && git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Verify API directory exists
run: |
if [ ! -d "$GITHUB_WORKSPACE/kagent/go/api/v1alpha2" ]; then
echo "Error: API directory not found at $GITHUB_WORKSPACE/kagent/go/api/v1alpha2"
ls -la "$GITHUB_WORKSPACE/kagent/go/api/"
exit 1
fi
echo "API directory found and verified"
- name: Read max Kubernetes version
run: |
if [ ! -f "website/public/docs/versions/max-kube.md" ]; then
echo "Error: max-kube.md file not found"
exit 1
fi
KUBE_VERSION=$(cat website/public/docs/versions/max-kube.md | tr -d '\n')
echo "KUBE_VERSION=$KUBE_VERSION" >> $GITHUB_ENV
echo "Using Kubernetes version: $KUBE_VERSION"
- name: Generate API Reference
run: |
# Substitute KUBE_VERSION in the config template and write to a temp file
cd "$GITHUB_WORKSPACE/website"
if [ ! -f "scripts/crd-ref-docs-config.yaml" ]; then
echo "Error: crd-ref-docs-config.yaml not found in scripts directory"
exit 1
fi
envsubst < scripts/crd-ref-docs-config.yaml > crd-ref-docs-config.yaml
echo "Changed to docs repository: $PWD"
echo "Using config file:"
cat crd-ref-docs-config.yaml
# Generate API docs
go run github.com/elastic/crd-ref-docs@v0.1.0 \
--source-path="$GITHUB_WORKSPACE/kagent/go/api/v1alpha2/" \
--renderer=markdown \
--output-path ./ \
--config=crd-ref-docs-config.yaml
# Check if generation was successful
if [ ! -f "./out.md" ]; then
echo "Error: API docs generation failed - out.md not created"
exit 1
fi
# Remove the temporary config file so it is not included in the PR
rm -f crd-ref-docs-config.yaml
# Fix problematic angle brackets in the generated markdown.
# Goldmark (unsafe: true) would otherwise treat stray <...> as raw HTML
# and silently swallow it, so convert bare angle brackets to HTML
# entities (they render literally). Preserve legitimate <br /> tags.
echo "Fixing problematic angle brackets in generated markdown..."
sed -i 's/<br \/>/__BR_TAG__/g' "./out.md"
sed -i 's/</\</g' "./out.md"
sed -i 's/>/\>/g' "./out.md"
sed -i 's/__BR_TAG__/<br \/>/g' "./out.md"
# crd-ref-docs's markdown renderer emits multiple consecutive blank
# lines around headings/descriptions. Collapse runs of 2+ blank
# lines to a single one so regenerating doesn't churn whitespace
# against the committed page on every run.
echo "Collapsing excess blank lines..."
sed -i ':a;N;$!ba;s/\n\{3,\}/\n\n/g' "./out.md"
# Drop crd-ref-docs's default leading `# API Reference` H1: Hextra
# renders the frontmatter title as the page H1, so a body H1 would
# duplicate it (same reasoning as the Helm chart step below).
sed -i '0,/^# /{/^# /d}' "./out.md"
# The H1 removal leaves a blank line where the heading was; strip
# leading blank lines so it doesn't stack with the frontmatter's
# own trailing blank line once appended below.
sed -i '/./,$!d' "./out.md"
# Write the Hugo page: plain YAML frontmatter + generated body.
mkdir -p "$(dirname "$KAGENT_API_PAGE")"
cat > "$KAGENT_API_PAGE" <<'EOF'
---
title: API Reference
linkTitle: API docs
description: kagent API reference documentation
weight: 1
author: kagent.dev
---
EOF
cat "./out.md" >> "$KAGENT_API_PAGE"
rm -f "./out.md"
# Normalize to exactly one trailing newline. crd-ref-docs can leave
# trailing blank lines at EOF that would otherwise churn on every
# regeneration even though nothing meaningful changed.
printf '%s\n' "$(cat "$KAGENT_API_PAGE")" > "$KAGENT_API_PAGE"
# Verify the output file was created
if [ ! -f "$KAGENT_API_PAGE" ]; then
echo "Error: Failed to create API docs page"
exit 1
fi
echo "API docs generated and processed successfully"
- name: Verify KMCP API directory exists
run: |
if [ ! -d "$GITHUB_WORKSPACE/kmcp/api/v1alpha1" ]; then
echo "Error: KMCP API directory not found at $GITHUB_WORKSPACE/kmcp/api/v1alpha1"
ls -la "$GITHUB_WORKSPACE/kmcp/api/" || echo "kmcp/api directory not found"
exit 1
fi
echo "KMCP API directory found and verified"
- name: Generate KMCP API Reference
run: |
# Substitute KUBE_VERSION in the config template and write to a temp file
cd "$GITHUB_WORKSPACE/website"
if [ ! -f "scripts/crd-ref-docs-config.yaml" ]; then
echo "Error: crd-ref-docs-config.yaml not found in scripts directory"
exit 1
fi
envsubst < scripts/crd-ref-docs-config.yaml > crd-ref-docs-config.yaml
echo "Changed to docs repository: $PWD"
echo "Using config file:"
cat crd-ref-docs-config.yaml
# Generate KMCP API docs
go run github.com/elastic/crd-ref-docs@v0.1.0 \
--source-path="$GITHUB_WORKSPACE/kmcp/api/v1alpha1/" \
--renderer=markdown \
--output-path ./ \
--config=crd-ref-docs-config.yaml
# Check if generation was successful
if [ ! -f "./out.md" ]; then
echo "Error: KMCP API docs generation failed - out.md not created"
exit 1
fi
# Remove the temporary config file so it is not included in the PR
rm -f crd-ref-docs-config.yaml
# Fix problematic angle brackets (see the kagent step for rationale).
echo "Fixing problematic angle brackets in generated markdown..."
sed -i 's/<br \/>/__BR_TAG__/g' "./out.md"
sed -i 's/</\</g' "./out.md"
sed -i 's/>/\>/g' "./out.md"
sed -i 's/__BR_TAG__/<br \/>/g' "./out.md"
# See the kagent step above for rationale: collapse crd-ref-docs's
# excess blank lines so this doesn't churn whitespace every run.
echo "Collapsing excess blank lines..."
sed -i ':a;N;$!ba;s/\n\{3,\}/\n\n/g' "./out.md"
# See the kagent step above for rationale: drop the duplicate H1.
sed -i '0,/^# /{/^# /d}' "./out.md"
# See the kagent step above for rationale: strip the leading blank
# line the H1 removal leaves behind.
sed -i '/./,$!d' "./out.md"
# Write the Hugo page: plain YAML frontmatter + generated body.
mkdir -p "$(dirname "$KMCP_API_PAGE")"
cat > "$KMCP_API_PAGE" <<'EOF'
---
title: API Reference
linkTitle: API docs
description: kmcp API reference documentation
weight: 5
author: kagent.dev
---
EOF
cat "./out.md" >> "$KMCP_API_PAGE"
rm -f "./out.md"
# See the kagent step above for rationale: normalize trailing newline.
printf '%s\n' "$(cat "$KMCP_API_PAGE")" > "$KMCP_API_PAGE"
# Verify the output file was created
if [ ! -f "$KMCP_API_PAGE" ]; then
echo "Error: Failed to create KMCP API docs page"
exit 1
fi
echo "KMCP API docs generated and processed successfully"
- name: Generate Helm Chart Reference
run: |
echo "Looking for Helm directory:"
ls -la "$GITHUB_WORKSPACE/kagent/helm" || echo "Helm directory not found!"
# Update docs repository
cd "$GITHUB_WORKSPACE/website"
echo "Changed to docs repository: $PWD"
# Generate Helm Docs for kagent chart
if [ ! -d "$GITHUB_WORKSPACE/kagent/helm/kagent" ]; then
echo "Error: kagent Helm chart directory not found"
exit 1
fi
echo "Processing kagent Helm chart..."
echo "Chart directory contents:"
ls -la "$GITHUB_WORKSPACE/kagent/helm/kagent/"
# Generate Chart.yaml from template for helm-docs to work
echo "Generating Chart.yaml from template..."
cd "$GITHUB_WORKSPACE/kagent/helm/kagent"
# Get the version from git or use a default
VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.5.5")
echo "Using version: $VERSION"
# Copy template and substitute version
cp Chart-template.yaml Chart.yaml
sed -i "s/\${VERSION}/$VERSION/g" Chart.yaml
echo "Generated Chart.yaml contents:"
cat Chart.yaml
# Go back to website directory
cd "$GITHUB_WORKSPACE/website"
echo "Chart.yaml contents:"
cat "$GITHUB_WORKSPACE/kagent/helm/kagent/Chart.yaml" || echo "Chart.yaml not found!"
echo "Values.yaml contents (first 20 lines):"
head -20 "$GITHUB_WORKSPACE/kagent/helm/kagent/values.yaml" || echo "values.yaml not found!"
# Generate the helm documentation
echo "Running helm-docs..."
find "$GITHUB_WORKSPACE/kagent/helm" -name "Chart.yaml" -type f 2>/dev/null | head -10
go run github.com/norwoodj/helm-docs/cmd/helm-docs@v1.14.2 \
--chart-search-root "$GITHUB_WORKSPACE/kagent/helm/kagent" \
--dry-run > "helm-temp.md"
echo "Generated helm-docs output (first 50 lines):"
head -50 "helm-temp.md"
echo "Total lines generated:"
wc -l "helm-temp.md"
# Remove the badge line and following empty line
# (might be replaced by a helm-docs template in the future).
sed -i '/!\[Version:/,/^$/d' "helm-temp.md"
# Drop the leading `# <chart name>` H1: Hextra renders the frontmatter
# title as the page H1, so a body H1 would duplicate it.
sed -i '0,/^# /{/^# /d}' "helm-temp.md"
# The H1 removal leaves a blank line where the heading was; strip
# leading blank lines so it doesn't stack with the frontmatter's
# own trailing blank line once appended into $HELM_PAGE below.
sed -i '/./,$!d' "helm-temp.md"
# Wrap version placeholders in inline code so they show literally.
python - <<'PY'
import re
from pathlib import Path
path = Path("helm-temp.md")
text = path.read_text()
for placeholder in ("${KMCP_VERSION}", "${SUBSTRATE_VERSION}", "${SUBSTRATE_REPO}"):
text = text.replace(placeholder, "`" + placeholder + "`")
# Wrap bare Helm/Go template expressions ({{ ... }}) in inline code.
# Hugo renders them literally, but the MDX build (and copy-out to any
# MDX consumer) parses {{ ... }} in prose as a JSX expression and
# fails with "Could not parse expression with acorn" (e.g. the
# extraObjects @default example). Existing inline-code spans are left
# untouched so already-backticked templates are not double-wrapped.
template = re.compile(r"\{\{.*?\}\}")
code_span = re.compile(r"`[^`]*`")
wrapped = []
pos = 0
for span in code_span.finditer(text):
wrapped.append(template.sub(lambda m: "`" + m.group(0) + "`", text[pos:span.start()]))
wrapped.append(span.group(0))
pos = span.end()
wrapped.append(template.sub(lambda m: "`" + m.group(0) + "`", text[pos:]))
text = "".join(wrapped)
path.write_text(text)
PY
# Write the Hugo page: plain YAML frontmatter + generated body.
mkdir -p "$(dirname "$HELM_PAGE")"
cat > "$HELM_PAGE" <<'EOF'
---
title: kagent
linkTitle: Helm Chart Configuration
description: kagent Helm chart configuration reference
weight: 2
author: kagent.dev
---
EOF
cat "helm-temp.md" >> "$HELM_PAGE"
rm -f "helm-temp.md"
# Normalize to exactly one trailing newline, same as the API ref
# pages above.
printf '%s\n' "$(cat "$HELM_PAGE")" > "$HELM_PAGE"
echo "Final generated file contents (first 50 lines):"
head -50 "$HELM_PAGE"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: website
commit-message: "docs: Update kagent and kmcp API reference docs"
signoff: true
title: "Update kagent and kmcp API reference docs"
body: |
Automated API and kagent Helm chart documentation update based on the latest commits:
- **kagent**: [`${{ env.KAGENT_COMMIT }}`](https://github.com/${{ github.repository_owner }}/kagent/commit/${{ env.KAGENT_COMMIT }})
- **kmcp**: [`${{ env.KMCP_COMMIT }}`](https://github.com/${{ github.repository_owner }}/kmcp/commit/${{ env.KMCP_COMMIT }})
This PR was automatically generated by the [**Update Reference documentation** workflow](https://github.com/${{ github.repository_owner }}/website/actions/workflows/update-ref-docs.yaml).
branch: api-gen-update
delete-branch: true
base: main
labels: |
documentation
automated pr