diff --git a/tools/rapids-download-conda-from-github b/tools/rapids-download-conda-from-github new file mode 100755 index 0000000..652047b --- /dev/null +++ b/tools/rapids-download-conda-from-github @@ -0,0 +1,24 @@ +#!/bin/bash +# A utility script that downloads a conda artifact archive from Github Artifacts, unzips it, +# and returns the path to the directory where it was unzipped. +# Positional Arguments: +# 1) a string of "cpp" or "python" which determines which conda artifact +# should be downloaded +set -euo pipefail +export RAPIDS_SCRIPT_NAME="rapids-download-conda-from-github" + +source rapids-prompt-local-repo-config + +# Validate package type argument +pkg_type="$1" +case "${pkg_type}" in + cpp|python) + pkg_name="$(RAPIDS_NO_PKG_EXTENSION=true rapids-package-name "conda_${pkg_type}")" + ;; + *) + rapids-echo-stderr 'Pass "cpp" or "python" as an argument.' + exit 1 + ;; +esac + +rapids-download-from-github "${pkg_name}" diff --git a/tools/rapids-download-from-github b/tools/rapids-download-from-github new file mode 100755 index 0000000..8af4a71 --- /dev/null +++ b/tools/rapids-download-from-github @@ -0,0 +1,21 @@ +#!/bin/bash +# A utility script that downloads an artifact from Github Artifacts, unzips it to a temporary directory, +# and prints the location where it was unzipped. +# Positional Arguments: +# 1) package name to download from Github Artifacts +set -euo pipefail +export RAPIDS_SCRIPT_NAME="rapids-download-from-github" + +if [ -z "$1" ]; then + rapids-echo-stderr "Must specify input arguments: PKG_NAME" + exit 1 +fi + +github_run_id="$(rapids-github-run-id)" +pkg_name="$1" +unzip_dest="${RAPIDS_UNZIP_DIR:-$(mktemp -d)}" + +rapids-echo-stderr "Downloading and decompressing ${pkg_name} from Run ID ${github_run_id} into ${unzip_dest}" +gh run download "${github_run_id}" --repo "${RAPIDS_REPOSITORY}" --name "${pkg_name}" --dir "${unzip_dest}" + +echo -n "${unzip_dest}" diff --git a/tools/rapids-download-wheels-from-github b/tools/rapids-download-wheels-from-github new file mode 100755 index 0000000..1eb8d71 --- /dev/null +++ b/tools/rapids-download-wheels-from-github @@ -0,0 +1,24 @@ +#!/bin/bash +# A utility script that downloads a wheel artifact archive from Github Artifacts, unzips it, +# and returns the path to the directory where it was unzipped. +# Positional Arguments: +# 1) a string of "cpp" or "python" which determines which wheel artifact +# should be downloaded +set -eo pipefail +export RAPIDS_SCRIPT_NAME="rapids-download-wheels-from-github" + +source rapids-prompt-local-repo-config + +# Validate package type argument +pkg_type="$1" +case "${pkg_type}" in + cpp|python) + pkg_name="$(RAPIDS_NO_PKG_EXTENSION=true rapids-package-name "wheel_${pkg_type}")" + ;; + *) + rapids-echo-stderr 'Pass "cpp" or "python" as an argument.' + exit 1 + ;; +esac + +rapids-download-from-github "${pkg_name}" diff --git a/tools/rapids-get-pr-conda-artifact-github b/tools/rapids-get-pr-conda-artifact-github new file mode 100755 index 0000000..b70aa29 --- /dev/null +++ b/tools/rapids-get-pr-conda-artifact-github @@ -0,0 +1,42 @@ +#!/bin/bash +# Downloads and decompresses a conda artifact for a specific PR from GitHub Artifacts. +# Finds and uses the latest commit on the PR. +# +# Positional Arguments: +# 1) repo name +# 2) PR number +# 3) "cpp" or "python", to get the conda artifact for the C++ or Python build, respectively +# 4) [optional] commit hash, to get the conda artifact for a specific commit +# +# Optional Environment Variables: +# RAPIDS_UNZIP_DIR: directory to unzip the conda artifact into +# +# Example Usage: +# rapids-get-pr-conda-artifact-github rmm 1095 cpp +set -euo pipefail +export RAPIDS_SCRIPT_NAME="rapids-get-pr-conda-artifact-github" + +repo="${1}" +pr="${2}" +package_type="${3}" +commit="${4:-}" + +# If commit is not provided, get the latest commit on the PR +if [[ -z "${commit}" ]]; then + commit=$(gh pr view "${pr}" --repo rapidsai/"${repo}" --json headRefOid --jq '.headRefOid[0:7]') +fi + +# Use a subshell to isolate environment variable changes +( + # Set up environment variables needed for GitHub artifact download + export RAPIDS_REPOSITORY="rapidsai/${repo}" + export RAPIDS_BUILD_TYPE="pull-request" + export RAPIDS_SHA="${commit}" + export RAPIDS_REF_NAME="pull-request/${pr}" + + # Generate the artifact name + artifact_name="$(RAPIDS_NO_PKG_EXTENSION=true rapids-package-name "conda_${package_type}")" + + unzip_dir=$(rapids-download-from-github "${artifact_name}") + echo -n "${unzip_dir}" +) diff --git a/tools/rapids-get-pr-wheel-artifact-github b/tools/rapids-get-pr-wheel-artifact-github new file mode 100755 index 0000000..c52a4b3 --- /dev/null +++ b/tools/rapids-get-pr-wheel-artifact-github @@ -0,0 +1,48 @@ +#!/bin/bash +# Downloads and decompresses a wheel artifact for a specific PR from GitHub Artifacts. +# Finds and uses the latest commit on the PR. +# +# Positional Arguments: +# 1) repo name +# 2) PR number +# 3) "cpp" or "python", to get the wheel artifact for the C++ or Python build, respectively +# 4) [optional] commit hash, to get the wheel artifact for a specific commit +# +# Optional Environment Variables: +# RAPIDS_UNZIP_DIR: directory to unzip the wheel artifact into +# +# Example Usage: +# rapids-get-pr-wheel-artifact-github rmm 1095 cpp +set -euo pipefail +export RAPIDS_SCRIPT_NAME="rapids-get-pr-wheel-artifact-github" + +repo="${1}" +pr="${2}" +package_type="${3}" +commit="${4:-}" + +# Check if RAPIDS_PY_WHEEL_NAME is set when fetching a wheel +if [[ -z "${RAPIDS_PY_WHEEL_NAME}" ]]; then + rapids-echo-stderr "The RAPIDS_PY_WHEEL_NAME variable must be set when fetching a wheel artifact" + exit 1 +fi + +# If commit is not provided, get the latest commit on the PR +if [[ -z "${commit}" ]]; then + commit=$(gh pr view "${pr}" --repo rapidsai/"${repo}" --json headRefOid --jq '.headRefOid[0:7]') +fi + +# Use a subshell to isolate environment variable changes +( + # Set up environment variables needed for GitHub artifact download + export RAPIDS_REPOSITORY="rapidsai/${repo}" + export RAPIDS_BUILD_TYPE="pull-request" + export RAPIDS_SHA="${commit}" + export RAPIDS_REF_NAME="pull-request/${pr}" + + # Generate the artifact name + artifact_name="$(RAPIDS_NO_PKG_EXTENSION=true rapids-package-name "wheel_${package_type}")" + + unzip_dir=$(rapids-download-from-github "${artifact_name}") + echo -n "${unzip_dir}" +) diff --git a/tools/rapids-github-run-id b/tools/rapids-github-run-id new file mode 100755 index 0000000..cca2e76 --- /dev/null +++ b/tools/rapids-github-run-id @@ -0,0 +1,19 @@ +#!/bin/bash +# A utility script that examines environment variables provided +# by GitHub Actions to print out a Github Workflow Run ID where the expected artifact +# should be. +set -euo pipefail +export RAPIDS_SCRIPT_NAME="rapids-github-run-id" + +# While called by CI, all the environment variables are set by the caller. However when run locally, these environment variables are set by rapids-prompt-local-repo-config +case "${RAPIDS_BUILD_TYPE}" in + pull-request|branch|nightly) + run_id=$(gh run list --repo "${RAPIDS_REPOSITORY}" --branch "${RAPIDS_REF_NAME}" --commit "${RAPIDS_SHA}" --json databaseId --jq '.[0] | .databaseId') + ;; + *) + rapids-echo-stderr "please pass a valid RAPIDS_BUILD_TYPE" + exit 1 + ;; +esac + +echo -n "${run_id}" diff --git a/tools/rapids-package-name b/tools/rapids-package-name index eaadc5c..945f2d0 100755 --- a/tools/rapids-package-name +++ b/tools/rapids-package-name @@ -76,6 +76,11 @@ if (( append_arch == 1)); then fi # for cpp and python package types, it's a tarball, append .tar.gz and prepend project name -pkg_name="${repo_name}_${pkg_name}.tar.gz" +pkg_extension=".tar.gz" +if [[ "${RAPIDS_NO_PKG_EXTENSION:-}" == "true" ]]; then + pkg_extension="" +fi + +pkg_name="${repo_name}_${pkg_name}${pkg_extension}" echo -n "${pkg_name}"