Repository navigation
193 lines (163 loc) · 6.56 KB
/
Copy pathdocs-pr-validation.yml
File metadata and controls
193 lines (163 loc) · 6.56 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
name: Documentation PR Validation
on:
pull_request:
branches: [main, release]
paths:
- "docs-site/**"
- "docs/**"
- ".github/workflows/docs-pr-validation.yml"
permissions:
contents: read
pull-requests: write
env:
NODE_VERSION: "22.23.4"
jobs:
validate:
name: Validate Documentation
runs-on: ubuntu-latest
defaults:
run:
working-directory: docs-site
outputs:
frontmatter_status: ${{ steps.frontmatter.outcome }}
typecheck_status: ${{ steps.typecheck.outcome }}
build_status: ${{ steps.build.outcome }}
links_status: ${{ steps.links.outcome }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
- name: Setup Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
cache-dependency-path: docs-site/pnpm-lock.yaml
- name: Restore Docusaurus cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
docs-site/.docusaurus
docs-site/node_modules/.cache
key: ${{ runner.os }}-docusaurus-${{ hashFiles('docs-site/pnpm-lock.yaml') }}-${{ hashFiles('docs-site/**/*.{ts,tsx,mdx,css}') }}
restore-keys: |
${{ runner.os }}-docusaurus-${{ hashFiles('docs-site/pnpm-lock.yaml') }}-
${{ runner.os }}-docusaurus-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Sync docs content
run: pnpm run sync-docs
- name: Validate frontmatter
id: frontmatter
continue-on-error: true
run: pnpm run validate:frontmatter
- name: TypeScript check
id: typecheck
run: pnpm run typecheck
- name: Build documentation
id: build
run: pnpm build
env:
NODE_OPTIONS: "--max-old-space-size=4096"
- name: Validate links
id: links
continue-on-error: true
run: |
if grep -q '"validate:links"' package.json; then
pnpm run validate:links
else
echo "No validate:links script found, skipping..."
fi
- name: Upload build artifact
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: docs-build-${{ github.sha }}
path: docs-site/build
retention-days: 7
comment:
name: Post Validation Results
runs-on: ubuntu-latest
needs: validate
if: always()
permissions:
pull-requests: write
steps:
- name: Check Comment Permissions
id: check-permissions
run: |
if [ "${{ github.event.pull_request.head.repo.id }}" != "${{ github.event.repository.id }}" ]; then
echo "🔒 External contributor PR - comment posting skipped (GitHub security restrictions)"
echo "can_comment=false" >> $GITHUB_OUTPUT
else
echo "🏠 Internal PR - comment posting enabled"
echo "can_comment=true" >> $GITHUB_OUTPUT
fi
- name: Post PR comment with results
if: steps.check-permissions.outputs.can_comment == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const frontmatter = '${{ needs.validate.outputs.frontmatter_status }}';
const typecheck = '${{ needs.validate.outputs.typecheck_status }}';
const build = '${{ needs.validate.outputs.build_status }}';
const links = '${{ needs.validate.outputs.links_status }}';
const getStatusEmoji = (status) => {
if (status === 'success') return ':white_check_mark:';
if (status === 'failure') return ':x:';
if (status === 'skipped') return ':fast_forward:';
return ':warning:';
};
const getStatusText = (status) => {
if (status === 'success') return 'Passed';
if (status === 'failure') return 'Failed';
if (status === 'skipped') return 'Skipped';
return 'Unknown';
};
const allPassed = frontmatter === 'success' &&
typecheck === 'success' &&
build === 'success';
const overallStatus = allPassed
? ':rocket: **Documentation validation passed!**'
: ':warning: **Documentation validation has issues**';
const body = `## Documentation Validation Results
${overallStatus}
| Check | Status | Result |
|-------|--------|--------|
| Frontmatter Validation | ${getStatusEmoji(frontmatter)} | ${getStatusText(frontmatter)} |
| TypeScript Check | ${getStatusEmoji(typecheck)} | ${getStatusText(typecheck)} |
| Build | ${getStatusEmoji(build)} | ${getStatusText(build)} |
| Link Validation | ${getStatusEmoji(links)} | ${getStatusText(links)} |
---
${allPassed
? ':package: Build artifact uploaded successfully. Ready for deployment preview.'
: ':construction: Please fix the failing checks before merging.'}
<sub>Commit: \`${{ github.sha }}\` | Workflow: [View logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})</sub>
`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Documentation Validation Results')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}