Skip to content

Commit

Permalink
use enum for artifact upload result handling
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester committed Mar 26, 2024
1 parent c54b5bf commit 24ffb68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 15 additions & 4 deletions bioconda_utils/artifacts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@


from enum import Enum
import glob
import os
import re
Expand All @@ -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()

Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 8 additions & 4 deletions bioconda_utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down

0 comments on commit 24ffb68

Please sign in to comment.