fix(ci): date uncommitted plugins by mtime in the catalog generator
This commit is contained in:
@@ -16,6 +16,20 @@ OPTIONAL_STRING_FIELDS = ("license", "icon", "description")
|
|||||||
OPTIONAL_BOOL_FIELDS = ("deprecated",)
|
OPTIONAL_BOOL_FIELDS = ("deprecated",)
|
||||||
|
|
||||||
|
|
||||||
|
def git_commit_time(path: Path, *extra_args: str) -> int | None:
|
||||||
|
"""Commit time in Unix seconds, or None when `path` has no matching commit.
|
||||||
|
|
||||||
|
An uncommitted plugin has no history, so `git log` prints nothing.
|
||||||
|
"""
|
||||||
|
stdout = subprocess.run(
|
||||||
|
["git", "log", "-1", *extra_args, "--format=%ct", "--", path],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=True,
|
||||||
|
).stdout.strip()
|
||||||
|
return int(stdout) if stdout else None
|
||||||
|
|
||||||
|
|
||||||
def load_plugin_manifest(path: Path) -> dict:
|
def load_plugin_manifest(path: Path) -> dict:
|
||||||
with path.open("rb") as handle:
|
with path.open("rb") as handle:
|
||||||
manifest = tomllib.load(handle)
|
manifest = tomllib.load(handle)
|
||||||
@@ -48,19 +62,13 @@ def load_plugin_manifest(path: Path) -> dict:
|
|||||||
raise ValueError(f"{path.relative_to(ROOT_DIR)} has invalid {field}; expected bool")
|
raise ValueError(f"{path.relative_to(ROOT_DIR)} has invalid {field}; expected bool")
|
||||||
out[field] = manifest[field]
|
out[field] = manifest[field]
|
||||||
|
|
||||||
out["updated_at"] = int(subprocess.run(
|
# Git dates a committed plugin, and is stable across checkouts. Anything git cannot date
|
||||||
["git", "log", "-1", "--format=%ct", "--", path],
|
# falls back to the file's mtime: an uncommitted plugin still gets a sensible entry so the
|
||||||
capture_output=True,
|
# catalog can be generated mid-development. (A rename also breaks the link to the commit
|
||||||
text=True,
|
# that first added the file, which is why added_at falls back too.)
|
||||||
check=True,
|
mtime = int(path.stat().st_mtime)
|
||||||
).stdout.strip())
|
out["updated_at"] = git_commit_time(path) or mtime
|
||||||
|
out["added_at"] = git_commit_time(path, "--diff-filter=A") or out["updated_at"]
|
||||||
out["added_at"] = int(subprocess.run(
|
|
||||||
["git", "log", "-1", "--diff-filter=A", "--format=%ct", "--", path],
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
check=True
|
|
||||||
).stdout.strip())
|
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user