-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (70 loc) · 2.75 KB
/
validate-docs.yml
File metadata and controls
87 lines (70 loc) · 2.75 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
name: Validate Documentation
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
validate-requirements:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install dependencies
run: pip install tomli
- name: Validate README requirements match pyproject.toml
run: |
python - <<'EOF'
import re
import sys
try:
import tomli
except ImportError:
import tomllib as tomli
# Read pyproject.toml
with open('pyproject.toml', 'rb') as f:
pyproject = tomli.load(f)
# Extract requirements from pyproject.toml
requires_python = pyproject['project']['requires-python']
dependencies = pyproject['project']['dependencies']
# Parse version constraints
python_version = re.search(r'>=(\d+\.\d+)', requires_python).group(1)
dep_versions = {}
for dep in dependencies:
match = re.match(r'([a-z-]+)>=([0-9.]+)', dep)
if match:
dep_versions[match.group(1)] = match.group(2)
# Read README.md
with open('README.md', 'r') as f:
readme = f.read()
# Extract Requirements section
req_section = re.search(r'## Requirements\n\n(.*?)\n\n', readme, re.DOTALL)
if not req_section:
print("ERROR: Could not find Requirements section in README.md")
sys.exit(1)
req_text = req_section.group(1)
# Validate each requirement
errors = []
# Check Python version
if f"Python {python_version}+" not in req_text:
errors.append(f"Python version mismatch: README should show 'Python {python_version}+' (from pyproject.toml: {requires_python})")
# Check dependencies
for dep_name, dep_version in dep_versions.items():
if f"{dep_name} >= {dep_version}" not in req_text:
errors.append(f"Dependency mismatch: README should show '{dep_name} >= {dep_version}'")
if errors:
print("ERROR: README.md Requirements section does not match pyproject.toml:\n")
for error in errors:
print(f" - {error}")
print("\nExpected Requirements section:")
print(f"* Python {python_version}+")
for dep_name, dep_version in sorted(dep_versions.items()):
print(f"* {dep_name} >= {dep_version}")
sys.exit(1)
print("✓ README.md Requirements section matches pyproject.toml")
EOF