mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 22:38:54 -06:00
refactor: one list of files the pipeline rewrites
diskcleanup kept its own regex of generated paths and missed derivable.json, retired.json and wiki/installer.md, so a worktree holding only a pipeline run's output was kept as uncommitted code. core.generated holds the globs, the cleanup and the nightly's commit rules match with them, and a test ties the regenerate rule to the list. The rule gains install/standalone/*.json and wiki/reading-reports.md, which the pipeline writes and no rule committed.
This commit is contained in:
1 parent
2a3b55432b
commit
f379df5e1e
6 files changed
+82
-28
No files matched your search
@@ -0,0 +1,48 @@
|
||||
"""The tracked paths a pipeline run rewrites, as globs whose `*` stays inside one path segment."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import fnmatch
|
||||
from collections.abc import Iterable
|
||||
|
||||
# What `pipeline.py --offline` writes and the nightly job commits under its
|
||||
# "regenerate collection records" rule (automation/jobs.yml).
|
||||
COLLECTION_RECORDS = (
|
||||
"database.json",
|
||||
"derivable.json",
|
||||
"retired.json",
|
||||
"install/*.json",
|
||||
"install/standalone/*.json",
|
||||
"install/targets/*.json",
|
||||
"install/games/*.json",
|
||||
"install/games/*/*.json",
|
||||
"README.md",
|
||||
"CONTRIBUTING.md",
|
||||
"wiki/installer.md",
|
||||
"wiki/reading-reports.md",
|
||||
"website/src/data/*.json",
|
||||
)
|
||||
# The archive recipes of step 1c, committed by the recipes rule, and the
|
||||
# reports of `--with-export`.
|
||||
OTHER_PIPELINE_OUTPUTS = (
|
||||
"recipes/archives.json",
|
||||
"exports/*.json",
|
||||
"exports/*/*.json",
|
||||
)
|
||||
GENERATED = COLLECTION_RECORDS + OTHER_PIPELINE_OUTPUTS
|
||||
|
||||
|
||||
def path_matches(pattern: str, path: str) -> bool:
|
||||
"""A glob whose `*` stays inside one path segment."""
|
||||
parts, segments = pattern.split("/"), path.split("/")
|
||||
return len(parts) == len(segments) and all(
|
||||
fnmatch.fnmatchcase(s, p) for p, s in zip(parts, segments)
|
||||
)
|
||||
|
||||
|
||||
def matches_any(path: str, patterns: Iterable[str]) -> bool:
|
||||
return any(path_matches(p, path) for p in patterns)
|
||||
|
||||
|
||||
def is_generated(path: str) -> bool:
|
||||
return matches_any(path, GENERATED)
|
||||
@@ -4,19 +4,15 @@ from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from core.generated import is_generated
|
||||
from core.paths import AUTORUN_WORKTREE
|
||||
|
||||
GENERATED = re.compile(
|
||||
r"^(database\.json|install/.*\.json|exports/.*\.json|README\.md|CONTRIBUTING\.md"
|
||||
r"|website/src/data/[^/]+\.json)$"
|
||||
)
|
||||
KEPT_TMP = ("acquire",)
|
||||
ALERT_GB = 100
|
||||
|
||||
@@ -80,7 +76,7 @@ def real_changes(worktree: Path) -> list[str]:
|
||||
if len(line) < 4 or line[:2].strip() == "D":
|
||||
continue
|
||||
path = line[3:].split(" -> ")[-1].strip('"')
|
||||
if not GENERATED.match(path):
|
||||
if not is_generated(path):
|
||||
paths.append(path)
|
||||
return paths
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ may carry, and the push.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import fnmatch
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from collections.abc import Callable, Sequence
|
||||
from pathlib import Path
|
||||
|
||||
from core.generated import matches_any
|
||||
from core.gitclone import GitRefused
|
||||
from core.gitclone import main_checkout as gitclone_main_checkout
|
||||
from core.paths import REPO_ROOT
|
||||
@@ -54,16 +54,8 @@ def changed_files(worktree: Path) -> list[str]:
|
||||
return sorted(set(paths))
|
||||
|
||||
|
||||
def path_matches(pattern: str, path: str) -> bool:
|
||||
"""A glob whose `*` stays inside one path segment."""
|
||||
parts, segments = pattern.split("/"), path.split("/")
|
||||
return len(parts) == len(segments) and all(
|
||||
fnmatch.fnmatchcase(s, p) for p, s in zip(parts, segments)
|
||||
)
|
||||
|
||||
|
||||
def plan_commit(changed: Sequence[str], patterns: Sequence[str]) -> list[str]:
|
||||
return sorted(p for p in changed if any(path_matches(g, p) for g in patterns))
|
||||
return sorted(p for p in changed if matches_any(p, patterns))
|
||||
|
||||
|
||||
def commit_paths(worktree: Path, files: Sequence[str], rule: CommitRule) -> str:
|
||||
|
||||
Reference in new issue
Block a user