Skip to content

Commit

Permalink
buildkite(dra): support list for feature branches (#13139)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored May 24, 2024
1 parent 0a54002 commit fff236c
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions .buildkite/scripts/dra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -37,30 +41,51 @@ 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/<major.minor>.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}" \
-e VAULT_ROLE_ID="${VAULT_ROLE_ID_SECRET}" \
-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

0 comments on commit fff236c

Please sign in to comment.