feature(keyringctl): rework ci module to execute full lint for new certs

This commit is contained in:
Levente Polyak 2021-11-09 02:34:14 +01:00
parent bce5bc550e
commit 83a345a1b8
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
2 changed files with 21 additions and 10 deletions

View File

@ -24,11 +24,22 @@ def ci(working_dir: Path, keyring_root: Path, project_root: Path) -> None:
"""
ci_merge_request_diff_base = environ.get("CI_MERGE_REQUEST_DIFF_BASE_SHA")
created, deleted, changed = git_changed_files(
git_path=project_root, base=f"{ci_merge_request_diff_base}", paths=[Path("keyring")]
created, deleted, modified = git_changed_files(
git_path=project_root, base=ci_merge_request_diff_base, paths=[Path("keyring")]
)
added_certificates: List[Path] = list(get_parent_cert_paths(paths=created))
changed_certificates: List[Path] = list(get_parent_cert_paths(paths=created + deleted + modified))
verify(
working_dir=working_dir,
keyring_root=keyring_root,
sources=changed_certificates,
lint_hokey=False,
lint_sq_keyring=False,
)
added_certificates: List[Path] = [
path for path in changed_certificates if (path / f"{path.name}.asc").relative_to(project_root) in created
]
if added_certificates:
verify(working_dir=working_dir, keyring_root=keyring_root, sources=added_certificates)

View File

@ -9,9 +9,9 @@ from .util import system
def git_changed_files(
git_path: Optional[Path], base: Optional[str], paths: Optional[List[Path]] = None
git_path: Optional[Path] = None, base: Optional[str] = None, paths: Optional[List[Path]] = None
) -> Tuple[List[Path], List[Path], List[Path]]:
"""Returns lists of created, deleted and changed files based on diff stats related to a base commit
"""Returns lists of created, deleted and modified files based on diff stats related to a base commit
and optional paths.
Parameters
@ -22,7 +22,7 @@ def git_changed_files(
Returns
-------
Lists of created, deleted and changed paths
Lists of created, deleted and modified paths
"""
cmd = ["git"]
if git_path:
@ -38,7 +38,7 @@ def git_changed_files(
created: List[Path] = []
deleted: List[Path] = []
changed: List[Path] = []
modified: List[Path] = []
for line in result.splitlines():
line = line.strip()
@ -48,8 +48,8 @@ def git_changed_files(
if line.startswith("delete"):
deleted.append(Path(line.split(maxsplit=3)[3]))
continue
changed.append(Path(line.split(maxsplit=2)[2]))
modified.append(Path(line.split(maxsplit=2)[2]))
changed = [path for path in changed if path not in created and path not in deleted]
modified = [path for path in modified if path not in created and path not in deleted]
return created, deleted, changed
return created, deleted, modified