Verify index.md matches the README.md body under the Jekyll front matter. README.md is the canonical source for the project overview; index.md is the Jekyll-rendered version with a YAML front matter block prepended. The sync_index_from_readme.py script regenerates index.md from README.m
()
| 221 | |
| 222 | |
| 223 | def check_index_in_sync_with_readme() -> int: |
| 224 | """Verify index.md matches the README.md body under the Jekyll front matter. |
| 225 | |
| 226 | README.md is the canonical source for the project overview; index.md |
| 227 | is the Jekyll-rendered version with a YAML front matter block prepended. |
| 228 | The sync_index_from_readme.py script regenerates index.md from README.md. |
| 229 | This check fails the build if the two have drifted. |
| 230 | """ |
| 231 | |
| 232 | if not repo_path(SYNC_INDEX_SCRIPT).is_file(): |
| 233 | print( |
| 234 | f"No sync script found at {display_path(SYNC_INDEX_SCRIPT)}. " |
| 235 | "Skipping index.md / README.md sync check." |
| 236 | ) |
| 237 | return 0 |
| 238 | |
| 239 | if not repo_path(INDEX_MD).is_file() or not repo_path(README_MD).is_file(): |
| 240 | print( |
| 241 | "FAILED: Expected README.md and index.md to both exist for the sync check." |
| 242 | ) |
| 243 | return 1 |
| 244 | |
| 245 | original_index_contents = read_bytes(INDEX_MD) |
| 246 | exit_code = 0 |
| 247 | |
| 248 | try: |
| 249 | subprocess.run( |
| 250 | [sys.executable, str(repo_path(SYNC_INDEX_SCRIPT))], |
| 251 | cwd=repo_root(), |
| 252 | check=True, |
| 253 | ) |
| 254 | |
| 255 | regenerated_index = read_bytes(INDEX_MD) |
| 256 | expected_lines = raw_text_lines(original_index_contents) |
| 257 | actual_lines = raw_text_lines(regenerated_index) |
| 258 | |
| 259 | if expected_lines != actual_lines: |
| 260 | print_diff( |
| 261 | "FAILED: index.md is out of sync with README.md. " |
| 262 | "Run scripts/sync_index_from_readme.py to regenerate it.", |
| 263 | expected_lines=expected_lines, |
| 264 | actual_lines=actual_lines, |
| 265 | expected_name="committed index.md", |
| 266 | actual_name="regenerated index.md", |
| 267 | ) |
| 268 | exit_code = 1 |
| 269 | except subprocess.CalledProcessError as exc: |
| 270 | print( |
| 271 | f"FAILED: sync_index_from_readme.py exited with status {exc.returncode}." |
| 272 | ) |
| 273 | exit_code = 1 |
| 274 | except Exception as exc: |
| 275 | print(f"FAILED: index.md / README.md sync check could not complete: {exc}") |
| 276 | exit_code = 1 |
| 277 | finally: |
| 278 | restore_errors = restore_original_files({INDEX_MD: original_index_contents}) |
| 279 | if restore_errors: |
| 280 | for message in restore_errors: |
no test coverage detected