From fff236cf4ee79cb618f4873429d9e13339be70cc Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Fri, 24 May 2024 12:36:58 +0200 Subject: [PATCH] buildkite(dra): support list for feature branches (#13139) --- .buildkite/scripts/dra.sh | 43 +++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/.buildkite/scripts/dra.sh b/.buildkite/scripts/dra.sh index b469e359881..ec7e4d761e2 100644 --- a/.buildkite/scripts/dra.sh +++ b/.buildkite/scripts/dra.sh @@ -5,7 +5,7 @@ ## ## It downloads the generated artifacts and run the DRA only if the branch is an active ## branch, based on the Unified Release policy. Otherwise, it won't run the DRA but print -## some traces. +## some traces and fail unless it's a feature branch then it will list the DRA artifacts. ## set -eo pipefail @@ -28,6 +28,10 @@ if [[ "${BUILDKITE_PULL_REQUEST:-false}" == "true" ]]; then exit 0 fi +# by default it uses the buildkite branch +DRA_BRANCH="$BUILDKITE_BRANCH" +# by default it publishes the DRA artifacts, for such it uses the collect command. +dra_command=collect BRANCHES_URL=https://storage.googleapis.com/artifacts-api/snapshots/branches.json curl -s "${BRANCHES_URL}" > active-branches.json if ! grep -q "\"$BUILDKITE_BRANCH\"" active-branches.json ; then @@ -37,13 +41,34 @@ if ! grep -q "\"$BUILDKITE_BRANCH\"" active-branches.json ; then echo "VERSION=$VERSION" echo "Supported branches:" cat active-branches.json - buildkite-agent annotate "${BUILDKITE_BRANCH} is not supported yet. Look for the supported branches in ${BRANCHES_URL}" --style 'warning' --context 'ctx-warn' - exit 1 + if [[ $BUILDKITE_BRANCH =~ "feature/" ]]; then + buildkite-agent annotate "${BUILDKITE_BRANCH} will list DRA artifacts. Feature branches are not supported. Look for the supported branches in ${BRANCHES_URL}" --style 'info' --context 'ctx-info' + dra_command=list + + # use a different branch since DRA does not support feature branches but main/release branches + # for such we will use the VERSION and https://storage.googleapis.com/artifacts-api/snapshots/.json + # to know if the branch was branched out from main or the release branches. + MAJOR_MINOR=${VERSION%.*} + if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/main.json" | grep -q "$VERSION" ; then + DRA_BRANCH=main + else + if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/$MAJOR_MINOR.json" | grep -q "$VERSION" ; then + DRA_BRANCH="$MAJOR_MINOR" + else + buildkite-agent annotate "It was not possible to know the original base branch for ${BUILDKITE_BRANCH}. This won't fail - this is a feature branch." --style 'info' --context 'ctx-info-feature-branch' + exit 0 + fi + fi + else + buildkite-agent annotate "${BUILDKITE_BRANCH} is not supported yet. Look for the supported branches in ${BRANCHES_URL}" --style 'warning' --context 'ctx-warn' + exit 1 + fi fi dra() { local workflow=$1 - echo "--- Run release manager $workflow" + local command=$2 + echo "--- Run release manager $workflow (DRA command: $command)" docker run --rm \ --name release-manager \ -e VAULT_ADDR="${VAULT_ADDR_SECRET}" \ @@ -51,16 +76,16 @@ dra() { -e VAULT_SECRET_ID="${VAULT_SECRET}" \ --mount type=bind,readonly=false,src=$(pwd),target=/artifacts \ docker.elastic.co/infra/release-manager:latest \ - cli collect \ + cli "$command" \ --project apm-server \ - --branch $BUILDKITE_BRANCH \ + --branch $DRA_BRANCH \ --commit $BUILDKITE_COMMIT \ --workflow $workflow \ --artifact-set main \ --version $VERSION } -dra "snapshot" -if [[ "${BUILDKITE_BRANCH}" != "main" ]]; then - dra "staging" +dra "snapshot" "$dra_command" +if [[ "${DRA_BRANCH}" != "main" ]]; then + dra "staging" "$dra_command" fi