diff --git a/bioconda_utils/artifacts.py b/bioconda_utils/artifacts.py index 5bc5bee7fe..6a1321cac3 100644 --- a/bioconda_utils/artifacts.py +++ b/bioconda_utils/artifacts.py @@ -1,5 +1,6 @@ +from enum import Enum import glob import os import re @@ -20,7 +21,14 @@ IMAGE_RE = re.compile(r"(.+)(?::|%3A)(.+)\.tar\.gz$") -def upload_pr_artifacts(config, repo, git_sha, dryrun=False, mulled_upload_target=None, label=None, artifact_source="azure") -> bool: +class UploadResult(Enum): + SUCCESS = 1 + FAILURE = 2 + NO_ARTIFACTS = 3 + NO_PR = 4 + + +def upload_pr_artifacts(config, repo, git_sha, dryrun=False, mulled_upload_target=None, label=None, artifact_source="azure") -> UplaodResult: _config = utils.load_config(config) repodata = utils.RepoData() @@ -32,13 +40,13 @@ def upload_pr_artifacts(config, repo, git_sha, dryrun=False, mulled_upload_targe prs = commit.get_pulls() if not prs: # no PR found for the commit - return True + return UploadResult.NO_PR pr = prs[0] artifacts = set(fetch_artifacts(pr, artifact_source)) if not artifacts: # no artifacts found, fail and rebuild packages logger.info("No artifacts found.") - return False + return UploadResult.NO_ARTIFACTS else: success = [] for artifact in artifacts: @@ -92,7 +100,10 @@ def upload_pr_artifacts(config, repo, git_sha, dryrun=False, mulled_upload_targe # upload the image logger.info(f"Uploading {img} to {target}.") success.append(skopeo_upload(fixed_img_name, target, creds=quay_login)) - return all(success) + if all(success): + return UploadResult.SUCCESS + else: + return UploadResult.FAILURE @backoff.on_exception( diff --git a/bioconda_utils/cli.py b/bioconda_utils/cli.py index ccf25bae28..5abcf1f159 100644 --- a/bioconda_utils/cli.py +++ b/bioconda_utils/cli.py @@ -9,7 +9,7 @@ import warnings from bioconda_utils import bulk -from bioconda_utils.artifacts import upload_pr_artifacts +from bioconda_utils.artifacts import UploadResult, upload_pr_artifacts from bioconda_utils.skiplist import Skiplist from bioconda_utils.build_failure import BuildFailureRecord, collect_build_failure_dataframe warnings.filterwarnings("ignore", message="numpy.dtype size changed") @@ -538,10 +538,12 @@ def handle_merged_pr( ): label = os.getenv('BIOCONDA_LABEL', None) or None - success = upload_pr_artifacts( - config, repo, git_range[1], dryrun=dryrun, mulled_upload_target=quay_upload_target, label=label, artifact_source=artifact_source + res = upload_pr_artifacts( + config, repo, git_range[1], dryrun=dryrun, + mulled_upload_target=quay_upload_target, label=label, + artifact_source=artifact_source ) - if not success and fallback == 'build': + if res == UploadResult.NO_ARTIFACTS and fallback == 'build': success = build( recipe_folder, config, @@ -551,6 +553,8 @@ def handle_merged_pr( mulled_test=True, label=label, ) + else: + success = res != UploadResult.FAILURE exit(0 if success else 1) @recipe_folder_and_config()