diff --git a/.gitlab/benchmarks/steps/build-baseline.sh b/.gitlab/benchmarks/steps/build-baseline.sh index 8ed61992164..d77c7080faf 100755 --- a/.gitlab/benchmarks/steps/build-baseline.sh +++ b/.gitlab/benchmarks/steps/build-baseline.sh @@ -2,20 +2,37 @@ set -e -o pipefail # If we have a tag (e.g. v2.21.1), then use the PyPI published wheel -# Otherwise, build the wheel from commit hash if [[ -n "${BASELINE_TAG}" ]]; then + echo "Downloading wheel for tag ${BASELINE_TAG} from PyPI" python3.9 -m pip download --no-deps "ddtrace==${BASELINE_TAG:1}" -else - ulimit -c unlimited - curl -sSf https://sh.rustup.rs | sh -s -- -y; - export PATH="$HOME/.cargo/bin:$PATH" - echo "Building wheel for ${BASELINE_BRANCH}:${BASELINE_COMMIT_SHA}" - git checkout "${BASELINE_COMMIT_SHA}" - mkdir ./tmp - PYO3_PYTHON=python3.9 CIBW_BUILD=1 python3.9 -m pip wheel --no-deps -w ./tmp/ ./ - for wheel in ./tmp/*.whl; - do - auditwheel repair "$wheel" --plat "manylinux2014_x86_64" -w ./ - done + exit 0 fi + + +# If we have a commit SHA, try to download the prebuild wheel from GitHub Actions +if [[ -n "${BASELINE_COMMIT_SHA}" ]]; +then + # Try to download the wheel from the public S3 bucket if we have one + PIPELINE_ID=$(.gitlab/scripts/get-pipelines-for-ref.sh "${BASELINE_COMMIT_SHA}" | jq -r 'if length > 0 then .[0].id else empty end') + + if [[ -n "${PIPELINE_ID}" ]]; + then + echo "Downloading prebuilt wheel for ${BASELINE_BRANCH}:${BASELINE_COMMIT_SHA} from pipeline ${PIPELINE_ID}" + python3.9 -m pip download --no-deps --index-url "https://dd-trace-py-builds.s3.amazonaws.com/${PIPELINE_ID}/" "ddtrace" + exit 0 + fi +fi + +# Otherwise, build from source +ulimit -c unlimited +curl -sSf https://sh.rustup.rs | sh -s -- -y; +export PATH="$HOME/.cargo/bin:$PATH" +echo "Building wheel for ${BASELINE_BRANCH}:${BASELINE_COMMIT_SHA}" +git checkout "${BASELINE_COMMIT_SHA}" +mkdir ./tmp +PYO3_PYTHON=python3.9 CIBW_BUILD=1 python3.9 -m pip wheel --no-deps -w ./tmp/ ./ +for wheel in ./tmp/*.whl; +do + auditwheel repair "$wheel" --plat "manylinux2014_x86_64" -w ./ +done diff --git a/.gitlab/scripts/get-pipelines-for-ref.sh b/.gitlab/scripts/get-pipelines-for-ref.sh new file mode 100755 index 00000000000..3cf3706f0d3 --- /dev/null +++ b/.gitlab/scripts/get-pipelines-for-ref.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Usage: +# ./get-pipelines-for-ref.sh +# +# Example: +# ./get-pipelines-for-ref.sh 3dbf82a +# +# Environment: +# GITLAB_TOKEN (required) + +GITLAB_API_URL=${GITLAB_API_URL:-"https://gitlab.ddbuild.io/api/v4"} +GITLAB_PROJECT_ID=${GITLAB_PROJECT_ID:-"358"} + +if [[ $# -ne 1 ]]; then + echo "usage: $0 " >&2 + exit 1 +fi + +if [[ -z "${GITLAB_TOKEN:-}" ]]; then + echo "GITLAB_TOKEN is not set" >&2 + exit 1 +fi + +REF="$1" + +curl --show-error --silent --fail \ + --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ + "${GITLAB_API_URL}/projects/${GITLAB_PROJECT_ID}/pipelines?sha=${REF}"