From 5e5c534c320247ac15c4825d251e9130f9408291 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Fri, 23 Sep 2022 23:08:22 -0500 Subject: [PATCH] Check if artifact exists before trying to install it --- ansible_collection.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ansible_collection.py b/ansible_collection.py index 18f04a9..17c6777 100755 --- a/ansible_collection.py +++ b/ansible_collection.py @@ -51,6 +51,14 @@ class AnsibleCollection: return load(file, Loader=CSafeLoader) def install(self, destdir: Union[str, Path]) -> None: + artifact = self.collection_srcdir / Path( + f"{self.namespace}-{self.name}-{self.version}.tar.gz" + ) + if not artifact.exists() and not artifact.is_file(): + raise CollectionError( + f"{artifact} does not exist! Did you run %ansible_collection_build?" + ) + args = ( "ansible-galaxy", "collection", @@ -58,11 +66,12 @@ class AnsibleCollection: "-n", "-p", str(destdir), - f"{self.namespace}-{self.name}-{self.version}.tar.gz", + str(artifact), ) print(f"Running: {args}") print() subprocess.run(args, check=True, cwd=self.collection_srcdir) + print() def write_filelist(self, filelist: Path) -> None: filelist.parent.mkdir(parents=True, exist_ok=True) @@ -134,5 +143,5 @@ def main(): if __name__ == "__main__": try: main() - except CollectionError as err: + except (CollectionError, subprocess.CalledProcessError) as err: sys.exit(err)