Repository navigation
820 lines (716 loc) · 33.7 KB
/
Copy pathdocumentation.yml
File metadata and controls
820 lines (716 loc) · 33.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
name: Documentation Validation & Maintenance
# ci-resync: force synchronize event after PR reopen didn't retrigger checks
on:
workflow_dispatch:
inputs:
action:
description: 'Action to perform'
required: true
type: choice
options:
- audit
- maintain
scope:
description: 'Scope (audit: all/syntax/accessibility/contrast/staleness; maintain: all/mermaid/staleness)'
required: false
default: 'all'
type: string
dry_run:
description: 'Preview changes without committing (maintain action only)'
required: false
default: 'false'
type: choice
options:
- 'true'
- 'false'
pull_request:
branches:
- develop
types: [opened, edited, synchronize, reopened, ready_for_review]
paths:
- '**/*.md'
- '.github/workflows/**'
- 'agents/**'
- '.github/instructions/**'
- 'docs/**'
- 'scripts/**'
# The skill-spec job below reads SKILL.md, agent definitions and AGENTS.md
# files, so a change to any of them, or to the validator, must reach it.
- 'skills/**'
- 'agents/**'
- 'plugins/**'
- '.claude/**'
- '**/*.agent.md'
- '**/AGENTS.md'
- 'package.json'
- 'package-lock.json'
push:
branches:
- develop
paths:
- '**/*.md'
- '.github/workflows/**'
- 'agents/**'
- '.github/instructions/**'
- 'docs/**'
- 'scripts/**'
- 'skills/**'
- 'agents/**'
- 'plugins/**'
- '.claude/**'
- '**/*.agent.md'
- '**/AGENTS.md'
- 'package.json'
- 'package-lock.json'
permissions:
contents: read
concurrency:
group: documentation-${{ github.ref }}
cancel-in-progress: true
env:
ACTION: ${{ github.event.inputs.action || 'regenerate' }}
AUDIT_SCOPE: ${{ github.event.inputs.scope || 'all' }}
DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }}
jobs:
audit:
name: Documentation Audit
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'audit'
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Create audit directory
run: mkdir -p .github/reports/mermaid-audit
- name: Run README audit
id: audit
if: contains(fromJson('["all", "audit"]'), env.AUDIT_SCOPE)
run: |
npm run audit:readme -- \
--scope=${{ env.AUDIT_SCOPE }} \
--format=markdown \
--output=.github/reports/mermaid-audit/
continue-on-error: true
- name: Validate Mermaid syntax
id: syntax
if: contains(fromJson('["all", "syntax"]'), env.AUDIT_SCOPE)
run: npm run validate:mermaid-syntax
- name: Check WCAG compliance
id: accessibility
if: contains(fromJson('["all", "accessibility"]'), env.AUDIT_SCOPE)
run: npm run validate:mermaid-accessibility
- name: Check Mermaid colour contrast
id: contrast
if: contains(fromJson('["all", "contrast"]'), env.AUDIT_SCOPE)
run: npm run validate:mermaid-contrast
- name: Identify stale documents
id: staleness
if: contains(fromJson('["all", "staleness"]'), env.AUDIT_SCOPE)
run: |
echo "Checking for stale README files (>6 months old)..."
find . -name "README.md" -type f | while read -r file; do
echo "Checking staleness for $file..."
done
- name: Check validation outcomes
id: validation-status
if: always()
env:
SYNTAX_OUTCOME: ${{ steps.syntax.outcome }}
A11Y_OUTCOME: ${{ steps.accessibility.outcome }}
CONTRAST_OUTCOME: ${{ steps.contrast.outcome }}
run: node scripts/collect-validation-results.js >> "$GITHUB_OUTPUT"
- name: Generate audit report
if: always()
env:
SYNTAX_PASSED: ${{ steps.validation-status.outputs.syntax_ok }}
A11Y_PASSED: ${{ steps.validation-status.outputs.a11y_ok }}
CONTRAST_PASSED: ${{ steps.validation-status.outputs.contrast_ok }}
AUDIT_SCOPE: ${{ env.AUDIT_SCOPE }}
run: node scripts/generate-doc-audit-report.js >> "$GITHUB_STEP_SUMMARY"
- name: Upload audit artifacts
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: documentation-audit-report-${{ github.run_number }}
path: .github/reports/mermaid-audit/
retention-days: 30
- name: Create issue for critical findings
if: failure()
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🚨 Critical Findings from Documentation Audit',
body: 'Documentation audit workflow found critical issues. See audit report artifacts.',
labels: ['type:bug', 'area:documentation', 'priority:critical']
})
regenerate:
name: Auto-regenerate Documentation
runs-on: ubuntu-latest
timeout-minutes: 15
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'push' && github.ref == 'refs/heads/develop')
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Resolve impacted README files
id: readmes
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE: ${{ github.event.pull_request.base.sha }}
PR_HEAD: ${{ github.event.pull_request.head.sha }}
PUSH_BEFORE: ${{ github.event.before }}
PUSH_SHA: ${{ github.sha }}
run: node scripts/workflows/resolve-readme-files.cjs
- name: Run README regeneration (PR dry-run)
if: steps.readmes.outputs.files != '' && github.event_name == 'pull_request'
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF_NAME: ${{ github.ref_name }}
README_FILES: ${{ steps.readmes.outputs.files }}
run: node scripts/agents/meta.agent.js --dry-run --files "$README_FILES"
- name: Run README regeneration (push commit)
if: steps.readmes.outputs.files != '' && github.event_name == 'push'
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF_NAME: ${{ github.ref_name }}
README_FILES: ${{ steps.readmes.outputs.files }}
run: node scripts/agents/meta.agent.js --files "$README_FILES"
- name: Check for content changes
id: content
run: |
# meta.agent.js always rewrites .github/metrics/meta-metrics.json
# (fresh timestamp), even when no content changed. Only proceed
# when at least one file other than the metrics file changed.
#
# `.github/workflows/` is excluded for the same reason the create-pull-request
# steps below exclude it from `add-paths`: GitHub treats a file directly in
# that directory as a workflow definition, so the App token (least privilege,
# no `workflows` permission) cannot push a change to it. Excluding it here
# keeps the "did anything change?" decision consistent with what the commit
# can actually contain, so a push whose only touched file was a workflow does
# not report has_changes=true on the strength of a file the push could not
# have made.
if git status --porcelain -- . ':(exclude).github/metrics/meta-metrics.json' ':(exclude).github/workflows' ':(exclude).github/workflows/**' | grep -q .; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
git checkout -- .github/metrics/meta-metrics.json 2>/dev/null || true
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "No content changes (metrics only, or .github/workflows/ only); skipping README PR."
fi
- name: Generate GitHub App token
# App token (not GITHUB_TOKEN) so the regeneration PR triggers CI and
# can satisfy develop's required checks. Requires repo/org secrets:
# BOT_PR_APP_CLIENT_ID and BOT_PR_APP_PRIVATE_KEY.
#
# `permission-workflows` is intentionally absent. The App stays at least
# privilege, and `.github/workflows/` is kept out of the bot's reach
# instead: resolve-readme-files.cjs never returns a README under that
# directory, and both create-pull-request steps below exclude it from
# `add-paths`. Do not add `permission-workflows` to work around a
# regeneration failure -- a failure means a workflow file leaked into
# the commit, which is the bug, not the missing permission.
id: app-token
if: github.event_name != 'pull_request' && steps.readmes.outputs.files != '' && steps.content.outputs.has_changes == 'true'
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ secrets.BOT_PR_APP_CLIENT_ID }}
private-key: ${{ secrets.BOT_PR_APP_PRIVATE_KEY }}
# Least privilege: push the branch, open/update the PR, label it.
permission-contents: write
permission-pull-requests: write
- name: Create or update README PR
if: github.event_name != 'pull_request' && steps.readmes.outputs.files != '' && steps.content.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@15733dbdfeedb4f7fdb73d13c6f5ac83b710fab8 # v8.1.2
with:
token: ${{ steps.app-token.outputs.token }}
branch: chore/readme-regeneration
base: develop
commit-message: 'chore(docs): regenerate impacted README files'
# Defence in depth. resolve-readme-files.cjs already refuses to emit a README
# under `.github/workflows/`, but this step is the last gate before the push:
# GitHub classifies a file directly in that directory as a workflow -- even a
# plain Markdown one -- and rejects the push unless the token carries
# `workflows` permission, which this App deliberately does not have.
# `add-paths` restricts staging to the repository minus that directory, so
# nothing under it can reach the commit even if the resolver regresses or
# meta.agent.js rewrites a file some other way.
#
# The pathspecs are unquoted on purpose. The action passes each comma/newline
# separated token straight to git as an argv element (no shell), so quotes
# would become part of the pathspec and git fails with
# "pathspec '':(exclude)...'' did not match any files". Verified against
# peter-evans/create-pull-request@5f6978f.
add-paths: |
.
:(exclude).github/workflows
title: 'chore(docs): regenerate impacted README files'
body: |
Automated README regeneration, Dependabot-style.
- Fixed branch; subsequent runs update this same PR until merged.
## Linked issues
N/A - automated README normalization, no tracked issue.
## Summary
README formatting normalization produced by meta.agent.js (headers, badges, footers, indexes).
## Changes
See the diff: README formatting normalization only, no intentional content changes. Review carefully before merging.
## Impact / Compatibility
Docs only; no code or behavior changes.
## Verification
- [x] Generated by the documentation.yml regenerate job; CI checks run on this PR via App token.
## Risk & Rollback
- Risk level: Low
- Rollback plan: close this PR unmerged, or revert after merge; the next regeneration run recreates it if still needed.
## Changelog
N/A - automated formatting normalization, exempt from changelog (bot author).
# No type label: the chore/ branch prefix gives type:chore, and an item keeps one type.
labels: |
area:documentation
- name: Upload regeneration artifacts
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: documentation-regeneration-${{ github.run_number }}
path: .github/reports/
if-no-files-found: ignore
retention-days: 14
footer-guard:
name: Footer Duplicate Guard
runs-on: ubuntu-latest
timeout-minutes: 15
# Ratchet, not a wall. Only the Markdown files this event touched are
# checked, so the pre-existing #3451 backlog does not block unrelated work
# while it is being cleared in dedicated cleanup PRs. Once
# `npm run validate:footers` reports zero findings, replace the
# changed-files check below with the whole-repo run.
if: github.event_name == 'pull_request' || github.event_name == 'push'
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Do not leave the job token in .git/config. This job runs `npm ci`
# and then a script from the checkout, so on a pull request both are
# contributor-controlled; the read-scoped token should not be
# reachable from them. Matches every other job in this workflow.
persist-credentials: false
# Full history so the base of the diff resolves, and the head ref
# checked out so the working tree matches the files being verified.
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
# Match every other job in this repo. Pinning a literal here drifted
# behind .nvmrc and `npm ci` failed on @babel/core's engine range.
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Resolve diff range
id: range
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE: ${{ github.event.pull_request.base.sha }}
PR_HEAD: ${{ github.event.pull_request.head.sha }}
PUSH_BEFORE: ${{ github.event.before }}
PUSH_SHA: ${{ github.sha }}
run: |
if [ "$EVENT_NAME" = "pull_request" ]; then
base="$PR_BASE"
head="$PR_HEAD"
else
base="$PUSH_BEFORE"
head="$PUSH_SHA"
fi
# A branch's first push reports an all-zero `before`, and a push that
# creates `develop` can also report one. There is no meaningful base in
# that case, so diff against the empty tree rather than `head^`:
# `head^` covers only the final commit and would miss Markdown files
# changed by earlier commits pushed in the same event.
if [ -z "$base" ] || [ "$base" = "0000000000000000000000000000000000000000" ]; then
base="$(git hash-object -t tree /dev/null 2>/dev/null || true)"
fi
if [ -z "$base" ]; then
{
echo "enabled=false"
} >> "$GITHUB_OUTPUT"
echo "No resolvable diff range; skipping the footer guard."
else
{
echo "enabled=true"
echo "base=$base"
echo "head=$head"
} >> "$GITHUB_OUTPUT"
fi
- name: Check changed Markdown files for duplicate footer blocks
if: steps.range.outputs.enabled == 'true'
env:
BASE: ${{ steps.range.outputs.base }}
HEAD: ${{ steps.range.outputs.head }}
run: |
if ! node scripts/dedupe-footers.js --check --changed-only --base="$BASE" --head="$HEAD"; then
echo "::error title=Duplicate footer blocks::A file in this change carries compounded, stranded, or footer-policy-exempt blocks. Run 'npm run validate:footers:fix' to repair, then re-run this job. See issue #3451."
exit 1
fi
- name: Report remaining whole-repo backlog
if: always() && steps.range.outputs.enabled == 'true'
run: |
# Progress signal for the #3451 cleanup; never fails the build.
node scripts/dedupe-footers.js --check || \
echo "::notice title=Footer backlog::Whole-repo footer backlog remains; tracked in issue #3451."
- name: Warn on possible unrecognised duplicate footers
# Advisory only, and deliberately a separate step from the failing check
# above. This signal reports files whose trailing zone holds two or more
# footer-shaped blocks that the wording-based deduper cannot recognise.
# Measured across 11,474 tracked Markdown files it flags 899 files, of
# which 255 (28.4%) hold fewer than two distinct known footer phrases,
# so it must never fail a build. That 28.4% is a share of flagged files,
# not a false-positive rate; the remainder includes files with no known
# phrase and files with exactly one, and a file with an unrecognised
# genuine duplicate footer may be among them. Nothing here confirms that
# any flagged file really holds a duplicate, and a file with two or more
# known phrases is not independently confirmed either, so no rate follows.
# Figures are from `npm run measure:footers:shape`; the guide records the
# same figures under a "No known footer" label, which this comment does
# not adopt. It exists to ask a human to look, and
# to surface footers whose wording is missing from footer-policy.js. See
# issue #3451.
if: always() && steps.range.outputs.enabled == 'true'
continue-on-error: true
env:
BASE: ${{ steps.range.outputs.base }}
HEAD: ${{ steps.range.outputs.head }}
run: |
node scripts/dedupe-footers.js --check --changed-only \
--base="$BASE" --head="$HEAD" --json > shape-report.json || true
node -e '
const fs = require("fs");
let report;
try {
report = JSON.parse(fs.readFileSync("shape-report.json", "utf8"));
} catch (error) {
console.log("::notice title=Footer shape signal::Could not read the report: " + error.message);
process.exit(0);
}
const findings = report.shapeFindings || [];
if (findings.length === 0) {
console.log("No footer-shaped blocks found in the changed Markdown files.");
process.exit(0);
}
const unrecognised = findings.filter((f) => !f.recognisedByDedupe);
for (const f of unrecognised) {
const texts = (f.regions || [])
.map((r) => r.texts.join(" "))
.join(" | ")
.slice(0, 200);
console.log(
"::warning title=Possible unrecognised duplicate footer::" +
f.path +
" holds " +
f.blocks +
" footer-shaped blocks the wording-based deduper does not recognise: " +
texts +
" Confirm and reconcile by hand. Nothing is auto-fixed; run " +
"npm run validate:footers:shape for the full report."
);
}
console.log(
"::notice title=Footer shape signal::" +
unrecognised.length +
" of " +
findings.length +
" changed file(s) hold a footer-shaped block the deduper cannot see. Advisory only: " +
"the measured share of flagged files holding fewer than two " +
"distinct known footer phrases is 28.4%, so this does not fail the build."
);
'
skill-spec:
name: Skill and Agent Spec Validation
# Validates the skill and agent rules for every pull request and push that can
# affect a SKILL.md, an agent definition or an AGENTS.md file. `develop` currently
# requires no status checks at all, so this is advisory: it reports when the
# workflow triggers and is skipped when the trigger-level `paths` filter does not
# match. A filtered-out run never reports, which would leave the check pending.
# If it is ever made a required check, it has to move to a workflow with
# no `paths` filter.
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.event_name == 'pull_request' || github.event_name == 'push'
permissions:
# Read-only. The job runs `npm ci` and then a script from the checkout, so
# on a pull request both are contributor-controlled and the job token must
# not stay reachable from them. Matches every other job in this workflow.
contents: read
concurrency:
group: skill-spec-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 1
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts --prefer-offline --no-audit --no-fund
- name: Per-class conformance report
# Prints the counts per file class so progress is measurable, and exits 0.
run: node scripts/validation/validate-skills.js --report
- name: Validate skills and agent definitions
# Fails on any finding absent from scripts/validation/skills-baseline.json,
# so the baseline cannot hide a regression. Each error names the file, the
# rule, the class it was checked against and the specification URL.
run: npm run validate:skills
skill-doc-contracts:
name: Skill Documentation Contracts
runs-on: ubuntu-latest
timeout-minutes: 10
# Fails when a SKILL.md offers a status label that none of its own bundled
# reference files define, so an agent cannot be told to emit a value the
# skill's authority rejects. That contradiction is what issue #3702 found
# twice in the same tree.
#
# Whole-repo, not changed-files, because a skill and its references are
# separate files: fixing the SKILL.md alone leaves the reference wrong, and
# a changed-files check would not see it. The current tree reports zero
# findings, so this needs no ratchet.
if: github.event_name == 'pull_request' || github.event_name == 'push'
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Do not leave the job token in .git/config. This job runs `npm ci`
# and then a script from the checkout, so on a pull request both are
# contributor-controlled; the read-scoped token should not be
# reachable from them. Matches every other job in this workflow.
persist-credentials: false
fetch-depth: 1
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
# Match every other job in this repo. Pinning a literal here drifted
# behind .nvmrc and `npm ci` failed on @babel/core's engine range.
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Check skill entry points against their own references
run: |
if ! npm run --silent validate:skill-doc-contracts; then
echo "::error title=Skill documentation contract::A SKILL.md offers a status label that none of its own reference files define. Either use a label the reference defines, or add the label to the reference that owns it. See issue #3702."
exit 1
fi
- name: Check badge URLs for unencoded spaces
run: |
if ! npm run --silent validate:badge-urls; then
echo "::error title=Badge URL encoding::A shields.io badge URL ends at an unencoded space, so GitHub renders a broken autolink instead of an image. Run 'npm run validate:badge-urls:fix' to repair, then re-run this job. See issue #3702."
exit 1
fi
maintain:
name: Documentation Maintenance
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'maintain'
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Create audit directory
run: mkdir -p .github/reports/mermaid-audit
- name: Run Mermaid diagram fixes
id: mermaid
if: ${{ env.AUDIT_SCOPE == 'all' || env.AUDIT_SCOPE == 'mermaid' }}
run: node scripts/fix-mermaid-diagrams.cjs
continue-on-error: true
- name: Validate Mermaid colour contrast
id: contrast
if: ${{ env.AUDIT_SCOPE == 'all' || env.AUDIT_SCOPE == 'mermaid' }}
run: npm run validate:mermaid-contrast
continue-on-error: true
- name: Run staleness updates
id: staleness
if: ${{ env.AUDIT_SCOPE == 'all' || env.AUDIT_SCOPE == 'staleness' }}
run: node scripts/fix-staleness-dates.cjs
continue-on-error: true
- name: Generate maintenance report
if: always()
run: |
REPORT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
MERMAID_STATUS="${{ steps.mermaid.outcome || 'skipped' }}"
CONTRAST_STATUS="${{ steps.contrast.outcome || 'skipped' }}"
STALENESS_STATUS="${{ steps.staleness.outcome || 'skipped' }}"
AUDIT_SCOPE="${{ env.AUDIT_SCOPE }}"
DRY_RUN="${{ env.DRY_RUN }}"
DRY_RUN_LABEL=$([ "$DRY_RUN" = "true" ] && echo "Yes (preview only)" || echo "No (changes applied)")
cat > .github/reports/mermaid-audit/maintenance-report.md <<EOF
# Documentation Maintenance Report
**Date**: ${REPORT_DATE}
**Scope**: ${AUDIT_SCOPE}
**Dry Run**: ${DRY_RUN}
## Processing Status
| Task | Status |
|------|--------|
| Mermaid Diagrams | ${MERMAID_STATUS} |
| Contrast Validation | ${CONTRAST_STATUS} |
| Staleness Updates | ${STALENESS_STATUS} |
## Changes Summary
- Mermaid diagrams: Updated accessibility attributes and colour-contrast-safe palette values
- Staleness updates: Refreshed \`last_updated\` dates for files exceeding 6-month threshold
## Processing Mode
- **Dry Run**: ${DRY_RUN_LABEL}
- **Scope**: ${AUDIT_SCOPE}
## Next Steps
If changes were applied:
1. Review the changes in this run's artifacts
2. Create a pull request with the updates
3. Have maintainers review and merge
EOF
cat .github/reports/mermaid-audit/maintenance-report.md
- name: Check for changes
id: changes
# `.github/workflows/` is excluded for the same reason the regenerate job
# excludes it: GitHub treats a file directly in that directory as a
# workflow and the App token cannot push one. Note this job always
# rewrites the tracked .github/reports/mermaid-audit/maintenance-report.md
# with a fresh timestamp, so in practice this reads true regardless; the
# load-bearing guard against a workflow file reaching the commit is the
# `add-paths` on the create-pull-request step below.
run: |
if git status --porcelain -- . ':(exclude).github/workflows' ':(exclude).github/workflows/**' | grep -q .; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
- name: Generate GitHub App token
# App token (not GITHUB_TOKEN) so the maintenance PR triggers CI and
# can satisfy develop's required checks. Requires repo/org secrets:
# BOT_PR_APP_CLIENT_ID and BOT_PR_APP_PRIVATE_KEY.
#
# `permission-workflows` is intentionally absent, for the same reason as in
# the regenerate job above: the App stays at least privilege and
# `.github/workflows/` is excluded from the commit instead. This job runs
# repository-wide fixers (Mermaid, staleness) and inherited the identical
# latent flaw, so it carries the same guard. Do not add
# `permission-workflows`; a push failure here means a workflow file leaked
# into the commit.
id: app-token
if: ${{ steps.changes.outputs.has_changes == 'true' && env.DRY_RUN == 'false' }}
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ secrets.BOT_PR_APP_CLIENT_ID }}
private-key: ${{ secrets.BOT_PR_APP_PRIVATE_KEY }}
# Least privilege: push the branch, open/update the PR, label it.
permission-contents: write
permission-pull-requests: write
- name: Create or update maintenance PR
if: ${{ steps.changes.outputs.has_changes == 'true' && env.DRY_RUN == 'false' }}
uses: peter-evans/create-pull-request@15733dbdfeedb4f7fdb73d13c6f5ac83b710fab8 # v8.1.2
with:
token: ${{ steps.app-token.outputs.token }}
branch: chore/docs-maintenance
base: develop
commit-message: 'docs: maintenance updates (Mermaid + staleness)'
# Same last-gate guard as the regenerate job: keep anything under
# `.github/workflows/` out of the commit, because this App token has no
# `workflows` permission and GitHub would refuse the push. Unquoted
# pathspecs are required -- the action passes each token to git as an
# argv element with no shell involved. See the regenerate job above.
add-paths: |
.
:(exclude).github/workflows
title: 'docs: maintenance updates (Mermaid + staleness)'
body: |
Automated documentation maintenance, Dependabot-style.
- Mermaid diagrams: accTitle, accDescr, approved palette values.
- Staleness: refreshed `last_updated` dates for files exceeding 6-month threshold.
- Scope: `${{ env.AUDIT_SCOPE }}`
- Fixed branch; subsequent runs update this same PR until merged.
## Linked issues
N/A - automated documentation maintenance, no tracked issue.
## Summary
Documentation maintenance produced by the documentation.yml maintain job (Mermaid fixes, staleness updates).
## Changes
See the diff: maintenance updates only, no intentional content changes. Review carefully before merging.
## Impact / Compatibility
Docs only; no code or behavior changes.
## Verification
- [x] Generated by the documentation.yml maintain job; CI checks run on this PR via App token.
## Risk & Rollback
- Risk level: Low
- Rollback plan: close this PR unmerged, or revert after merge; the next maintenance run recreates it if still needed.
## Changelog
N/A - automated maintenance updates, exempt from changelog (bot author).
# No type label: the chore/ branch prefix gives type:chore, and an item keeps one type.
labels: |
area:documentation
- name: Upload maintenance report
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: documentation-maintenance-report-${{ github.run_number }}
path: .github/reports/mermaid-audit/
- name: Maintenance summary
if: always()
env:
JOB_STATUS: ${{ job.status }}
HAS_CHANGES: ${{ steps.changes.outputs.has_changes }}
run: |
# AUDIT_SCOPE and DRY_RUN are already job env; read them as shell
# variables rather than inlining expressions into the script.
{
echo "## Documentation Maintenance Summary"
echo ""
echo "**Status**: $JOB_STATUS"
echo "**Scope**: $AUDIT_SCOPE"
echo "**Dry Run**: $DRY_RUN"
echo "**Changes Made**: $HAS_CHANGES"
} >> "$GITHUB_STEP_SUMMARY"