From c761faeb14560780dc733bb965205b0eb98febbf Mon Sep 17 00:00:00 2001 From: Victor Seva <linuxmaniac@torreviejawireless.org> Date: Sat, 11 Jan 2025 21:44:23 +0100 Subject: [PATCH] don't fail if ``manifest unknown`` is detected (#54) related Chizkiyahu/delete-untagged-ghcr-action#53 --- clean_ghcr.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/clean_ghcr.py b/clean_ghcr.py index faaa3e1..1926561 100644 --- a/clean_ghcr.py +++ b/clean_ghcr.py @@ -11,6 +11,10 @@ DOCKER_ENDPOINT = "ghcr.io/" +class NoManifestErr(Exception): + pass + + def get_url(path): if path.startswith(API_ENDPOINT): return path @@ -121,9 +125,12 @@ def get_deps_pkgs(owner, pkgs): def get_image_deps(image): - manifest_txt = get_manifest(image) - data = json.loads(manifest_txt) - return [manifest['digest'] for manifest in data.get("manifests", [])] + try: + manifest_txt = get_manifest(image) + data = json.loads(manifest_txt) + return [manifest["digest"] for manifest in data.get("manifests", [])] + except NoManifestErr: + return [] def get_manifest(image): @@ -131,6 +138,8 @@ def get_manifest(image): res = subprocess.run(cmd, shell=True, capture_output=True) if res.returncode != 0: print(cmd) + if res.stderr == b"manifest unknown\n": + raise NoManifestErr() raise Exception(res.stderr) return res.stdout.decode("utf-8")