-
Notifications
You must be signed in to change notification settings - Fork 6
177 lines (149 loc) · 6.33 KB
/
Copy pathpr-docs.yml
File metadata and controls
177 lines (149 loc) · 6.33 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
name: PR Documentation Check
on:
pull_request:
branches: [ main ]
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
docs-check:
runs-on: ubuntu-latest
name: Documentation Check
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect documentation changes
uses: dorny/paths-filter@v2
id: changes
with:
filters: |
code:
- 'neural/**/*.py'
docs:
- 'docs/**'
- 'docs-site/**'
examples:
- 'examples/**'
readme:
- 'README.md'
- name: Set up uv
if: steps.changes.outputs.code == 'true' || steps.changes.outputs.examples == 'true'
uses: astral-sh/setup-uv@v7
with:
python-version: "3.11"
enable-cache: true
- name: Sync dependencies
if: steps.changes.outputs.code == 'true' || steps.changes.outputs.examples == 'true'
run: uv sync --extra dev
- name: Check for docstring coverage
if: steps.changes.outputs.code == 'true'
run: |
uv run python scripts/check_docstring_coverage.py
- name: Validate example documentation
if: steps.changes.outputs.examples == 'true'
run: |
uv run python scripts/validate_examples.py
- name: Check for API documentation updates
if: steps.changes.outputs.code == 'true'
run: |
uv run python scripts/validate_docs.py
- name: Comment on PR
if: always()
continue-on-error: true
uses: actions/github-script@v6
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📚 Documentation Status')
);
let commentBody = '## 📚 Documentation Status\n\n';
if ('${{ steps.changes.outputs.code }}' === 'true') {
commentBody += '✅ Code changes detected\n';
commentBody += '- Docstring coverage checked\n';
commentBody += '- API documentation validation completed\n';
}
if ('${{ steps.changes.outputs.docs }}' === 'true') {
commentBody += '✅ Documentation changes detected\n';
commentBody += '- Documentation structure validated\n';
commentBody += '- Links checked for broken references\n';
}
if ('${{ steps.changes.outputs.examples }}' === 'true') {
commentBody += '✅ Example changes detected\n';
commentBody += '- Example documentation validated\n';
commentBody += '- Code syntax verified\n';
}
if ('${{ steps.changes.outputs.readme }}' === 'true') {
commentBody += '✅ README changes detected\n';
}
if ('${{ steps.changes.outputs.code }}' === 'false' &&
'${{ steps.changes.outputs.docs }}' === 'false' &&
'${{ steps.changes.outputs.examples }}' === 'false' &&
'${{ steps.changes.outputs.readme }}' === 'false') {
commentBody += 'ℹ️ No documentation-related changes detected\n';
}
commentBody += '\n---\n*This comment is automatically generated by the documentation workflow.*';
if (botComment) {
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});
}
require-docs:
runs-on: ubuntu-latest
name: Require Documentation
if: github.event.pull_request.draft == false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if documentation is required
uses: actions/github-script@v6
with:
script: |
const { execSync } = require('child_process');
// Get changed files
const diff = execSync('git diff --name-only origin/main...HEAD', { encoding: 'utf8' });
const changedFiles = diff.trim().split('\n');
// Check if code changes require documentation
const codeFiles = changedFiles.filter(file => file.startsWith('neural/') && file.endsWith('.py'));
const docFiles = changedFiles.filter(file =>
file.startsWith('docs/') ||
file.startsWith('docs-site/') ||
file === 'README.md'
);
console.log('Code files changed:', codeFiles.length);
console.log('Doc files changed:', docFiles.length);
if (codeFiles.length > 0 && docFiles.length === 0) {
// Check if changes are minor (don't require docs)
const minorChanges = execSync(`git log --format=%s origin/main...HEAD | grep -E "^(fix|chore|refactor|style|test)" | wc -l`, { encoding: 'utf8' });
if (parseInt(minorChanges.trim()) < codeFiles.length) {
console.log('⚠️ Documentation may be required for these changes');
console.log('Consider updating:');
console.log('- API documentation for new functions/classes');
console.log('- Examples for new features');
console.log('- README for breaking changes');
// This doesn't fail the build, just provides guidance
process.exit(0);
}
}
console.log('✅ Documentation requirements satisfied');