Skip to content

Commit

Permalink
fix: detect errors when uploading artifacts (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester authored Mar 27, 2024
1 parent 7e8c47c commit d0a79cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
24 changes: 18 additions & 6 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") -> UploadResult:
_config = utils.load_config(config)
repodata = utils.RepoData()

Expand All @@ -32,14 +40,15 @@ 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:
with tempfile.TemporaryDirectory() as tmpdir:
# download the artifact
Expand Down Expand Up @@ -67,7 +76,7 @@ def upload_pr_artifacts(config, repo, git_sha, dryrun=False, mulled_upload_targe
else:
logger.info(f"Uploading {pkg} to anaconda.org.")
# upload the package
anaconda_upload(pkg, label=label)
success.append(anaconda_upload(pkg, label=label))

if mulled_upload_target:
quay_login = os.environ['QUAY_LOGIN']
Expand All @@ -90,8 +99,11 @@ def upload_pr_artifacts(config, repo, git_sha, dryrun=False, mulled_upload_targe
else:
# upload the image
logger.info(f"Uploading {img} to {target}.")
skopeo_upload(fixed_img_name, target, creds=quay_login)
return True
success.append(skopeo_upload(fixed_img_name, target, creds=quay_login))
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 d0a79cd

Please sign in to comment.