#!/bin/bash # Common functionality for downloading artifacts from GitHub PR builds # # Arguments: # 1) repo name # 2) PR number # 3) "cpp" or "python", to get the artifact for the C++ or Python build, respectively # 4) "wheel" or "conda", to get the wheel or conda package artifact, respectively # 5) [optional] full commit hash, to get the artifact for a specific commit # Flags: # --pkg_name PACKAGE_NAME: specify the package name to download if different from repo name (e.g. pylibraft from raft) # defaults to `lib{repo name}` for C++ artifacts and `{repo_name}` for Python artifacts # --py [PY_VERSION]: for python packages that don't use the stable ABI (abi3), # pass `py` to download version-specific artifacts. Defaults to # `$RAPIDS_PY_VERSION` if Python version is not given. # --noarch: for artifacts built without a strict `$ARCH` dependency (Pure-python packages) # --override-artifact-name ARTIFACT_NAME: pass in full artifact name and override all other flags # # Additional environment variables recognized by 'rapids-get-pr-artifact': # # * RAPIDS_BUILD_WORKFLOW_NAME = Filename for the workflow that build the artifacts you're trying to fetch. # Defaults to 'pr.yaml'. # set -euo pipefail # Parse flags pkg_name_arg="" py_flag=0 noarch_flag=0 override_flag=0 override_name="" positional_args=() while [[ $# -gt 0 ]]; do case $1 in --pkg_name) pkg_name_arg="$2" shift 2 ;; --py) py_flag=1 shift # Check if next argument exists and doesn't start with "-" (i.e., it's a version) if [[ $# -gt 0 && "$1" != -* ]]; then py_version="$1" shift else # No argument provided, will use RAPIDS_PY_VERSION py_version="$RAPIDS_PY_VERSION" fi ;; --override-artifact-name) override_name="$2" override_flag=1 shift 2 ;; --noarch) noarch_flag=1 shift ;; -*) echo "Unknown flag: $1" >&2 exit 1 ;; *) positional_args+=("$1") shift ;; esac done # Check for minimum required arguments if [[ ${#positional_args[@]} -lt 4 ]]; then echo "Must specify: REPO_NAME PR_NUMBER PACKAGE_TYPE PACKAGE_FORMAT [COMMIT]" >&2 exit 1 fi if [[ "${positional_args[0]}" == */* ]]; then repo="${positional_args[0]}" else repo="rapidsai/${positional_args[0]}" fi repo_name="$(echo "${repo}" | cut -d/ -f2)" pr="${positional_args[1]}" package_type="${positional_args[2]}" package_format="${positional_args[3]}" commit="${positional_args[4]:-}" # Validate --py flag if (( py_flag == 1 )); then if [[ "${package_type:-}" != "python" ]]; then rapids-echo-stderr "Error: --py flag is only compatible with package_type='python'" rapids-echo-stderr "Got: package_format='${package_format}'" exit 1 fi fi source rapids-prompt-local-github-auth # If commit is not provided, get the latest commit on the PR if [[ -z "${commit:-}" ]]; then commit=$(rapids-retry --quiet gh pr view "${pr}" --repo "${repo}" --json headRefOid --jq '.headRefOid') fi # Generate the artifact name # For `cpp` artifacts, assume a default package name of `lib{repo}` # so `libraft` for `raft` # For `python` artifacts, assume a default package name of `{repo}` if [[ "${package_type:-}" == "cpp" ]]; then PACKAGE_NAME="${pkg_name_arg:-lib${repo_name}}" else PACKAGE_NAME="${pkg_name_arg:-${repo_name}}" fi # Non-cuda-suffixed packages are rare enough that we just assume we need the cuda suffix # For the edge cases, uses can use the override functionality RAPIDS_ARTIFACT_NAME_ARGS=("${package_format}_${package_type}" "$PACKAGE_NAME" "${repo_name}" "--cuda") if [[ "${package_type:-}" == "python" && (( $noarch_flag == 0 ))]]; then if (( py_flag == 1 )); then RAPIDS_ARTIFACT_NAME_ARGS+=("--py" "$py_version") else RAPIDS_ARTIFACT_NAME_ARGS+=("--stable") fi fi # Artifacts with an `any` arch are almost always also `pure`, so group those options # together to cover 95% of all artifacts. if (( noarch_flag == 1 )); then RAPIDS_ARTIFACT_NAME_ARGS+=("--arch" "any" "--pure") fi pkg_name="$(rapids-artifact-name "${RAPIDS_ARTIFACT_NAME_ARGS[@]}")" if (( override_flag == 1 )); then pkg_name=$override_name fi if [[ ${GHA_TOOLS_DEBUG:-} == "1" ]]; then rapids-logger "$pkg_name" fi # if RAPIDS_BUILD_WORKFLOW_NAME is set, use that instead of any RAPIDS conventions if [[ -n "${RAPIDS_BUILD_WORKFLOW_NAME:-}" ]]; then workflow_that_produced_artifacts="${RAPIDS_BUILD_WORKFLOW_NAME}" else # otherwise, rely on the RAPIDS workflow name conventions workflow_that_produced_artifacts="pr.yaml" fi # get run ID # NOTE: cannot reuse rapids-github-run-id here, because the environment variable # GITHUB_RUN_ID will refer to the run this is being called from, not # the run that generated the artifact we're looking for. # # For example, if this is called on a 'cudf' PR to download 'rmm' artifacts, # here we want a run ID from an 'rmm' CI run, not the current 'cudf' one. github_run_id=$( RAPIDS_RETRY_SLEEP=120 \ rapids-retry --quiet gh run list \ --repo "${repo}" \ --branch "pull-request/${pr}" \ --commit "${commit}" \ --workflow "${workflow_that_produced_artifacts}" \ --json 'createdAt,databaseId' \ --jq 'sort_by(.createdAt) | reverse | .[0] | .databaseId' ) # Passing an empty string to `gh run download` results in it searching all runs from all times... which could be # thousands of results and result in exceeding GitHub rate limits. Prevent that. if [[ -z "${github_run_id:-}" ]]; then rapids-echo-stderr "ERROR: failed to find a GitHub Actions run for [repo=${repo}, workflow=${workflow_that_produced_artifacts}, branch=pull-request/${pr}, commit=${commit}]." exit 1 fi unzip_dest="${RAPIDS_UNZIP_DIR:-$(mktemp -d)}" rapids-echo-stderr "Downloading and decompressing ${pkg_name} from Run ID ${github_run_id} into ${unzip_dest}" rapids-retry gh run download \ "${github_run_id}" \ --repo "${repo}" \ --name "${pkg_name}" \ --dir "${unzip_dest}" echo -n "${unzip_dest}"