Skip to content

Commit bdc9598

Browse files
authored
[7.17] (backport #19188) fix(packaging): slack notifications and DRA branch for PRs (#19369)
Backport #15350 and #19188
1 parent 596923a commit bdc9598

File tree

5 files changed

+113
-116
lines changed

5 files changed

+113
-116
lines changed

.buildkite/hooks/post-checkout

Lines changed: 0 additions & 58 deletions
This file was deleted.

.buildkite/hooks/pre-command

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,14 @@
1010

1111
set -eo pipefail
1212

13-
retry() {
14-
local retries=$1
15-
shift
13+
# Upload should not do much with the pre-command.
14+
if [[ "$BUILDKITE_COMMAND" =~ .*"upload".* ]]; then
15+
echo "Skipped pre-command when running the Upload pipeline"
16+
exit 0
17+
fi
1618

17-
local count=0
18-
until "$@"; do
19-
exit=$?
20-
wait=$((2 ** count))
21-
count=$((count + 1))
22-
if [ $count -lt "$retries" ]; then
23-
>&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
24-
sleep $wait
25-
else
26-
>&2 echo "Retry $count/$retries exited $exit, no more retries left."
27-
return $exit
28-
fi
29-
done
30-
return 0
31-
}
19+
# shellcheck disable=SC1091
20+
source .buildkite/scripts/utils.sh
3221

3322
get_os_details() {
3423
case $(uname | tr '[:upper:]' '[:lower:]') in

.buildkite/package.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
notify:
22
- slack: "#apm-server"
3-
if: build.state == "failed"
3+
if: build.state == "failed" && build.branch =~ /^(main|\d+\.\d+|\d+\.x)$$/
44
- slack: "#observablt-bots"
5-
if: "build.state != 'passed'"
5+
if: build.state == "failed" && build.branch =~ /^(main|\d+\.\d+|\d+\.x)$$/
66

77
env:
88
IMAGE_UBUNTU_X86_64: "family/core-ubuntu-2004"
@@ -63,11 +63,14 @@ steps:
6363

6464
- label: "DRA"
6565
key: "dra"
66-
command: ".buildkite/scripts/dra.sh"
66+
command: ".buildkite/scripts/dra.sh {{matrix}}"
6767
agents:
6868
provider: "gcp"
6969
image: "${IMAGE_UBUNTU_X86_64}"
7070
machineType: "c2-standard-16"
71+
matrix:
72+
- "snapshot"
73+
- "staging"
7174
depends_on:
7275
- step: "package"
7376
allow_failure: false

.buildkite/scripts/dra.sh

100644100755
Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
##
66
## It downloads the generated artifacts and run the DRA only if the branch is an active
77
## branch, based on the Unified Release policy. Otherwise, it won't run the DRA but print
8-
## some traces.
8+
## some traces and fail unless it's a feature branch then it will list the DRA artifacts.
99
##
1010

1111
set -eo pipefail
1212

13-
## Read current version.
14-
VERSION=$(make get-version)
13+
# Either staging or snapshot
14+
TYPE="$1"
15+
16+
# NOTE: load the shared functions
17+
# shellcheck disable=SC1091
18+
source .buildkite/scripts/utils.sh
1519

1620
echo "--- Restoring Artifacts"
1721
buildkite-agent artifact download "build/**/*" .
@@ -23,59 +27,47 @@ echo "--- Changing permissions for the release manager"
2327
sudo chown -R :1000 build/
2428
ls -l build/distributions/
2529

26-
if [[ "${BUILDKITE_PULL_REQUEST:-false}" == "true" ]]; then
27-
echo "--- :arrow_right: Release Manager does not run on PRs, skipping"
28-
exit 0
29-
fi
30-
30+
# by default it uses the buildkite branch
31+
DRA_BRANCH="$BUILDKITE_BRANCH"
32+
# by default it publishes the DRA artifacts, for such it uses the collect command.
33+
DRA_COMMAND=collect
34+
VERSION=$(make get-version)
3135
BRANCHES_URL=https://storage.googleapis.com/artifacts-api/snapshots/branches.json
3236
curl -s "${BRANCHES_URL}" > active-branches.json
3337
if ! grep -q "\"$BUILDKITE_BRANCH\"" active-branches.json ; then
34-
echo "--- :arrow_right: Release Manager only supports the current active branches, skipping"
35-
echo "BUILDKITE_BRANCH=$BUILDKITE_BRANCH"
36-
echo "BUILDKITE_COMMIT=$BUILDKITE_COMMIT"
37-
echo "VERSION=$VERSION"
38-
echo "Supported branches:"
39-
cat active-branches.json
40-
buildkite-agent annotate "${BUILDKITE_BRANCH} is not supported yet. Look for the supported branches in ${BRANCHES_URL}" --style 'warning' --context 'ctx-warn'
41-
exit 1
38+
# If no active branches are found, let's see if it is a feature branch.
39+
dra_process_other_branches
4240
fi
4341

42+
echo "--- :arrow_right: Release Manager only supports the current active branches"
43+
echo "BUILDKITE_BRANCH=$BUILDKITE_BRANCH"
44+
echo "BUILDKITE_COMMIT=$BUILDKITE_COMMIT"
45+
echo "VERSION=$VERSION"
46+
echo "Supported branches:"
47+
cat active-branches.json
48+
4449
dra() {
4550
local workflow=$1
46-
echo "--- Prepare release manager $workflow"
47-
.ci/scripts/prepare-release-manager.sh $workflow
48-
49-
echo "--- Run release manager $workflow"
51+
local command=$2
52+
echo "--- Run release manager $workflow (DRA command: $command)"
53+
set -x
5054
docker run --rm \
5155
--name release-manager \
5256
-e VAULT_ADDR="${VAULT_ADDR_SECRET}" \
5357
-e VAULT_ROLE_ID="${VAULT_ROLE_ID_SECRET}" \
5458
-e VAULT_SECRET_ID="${VAULT_SECRET}" \
5559
--mount type=bind,readonly=false,src=$(pwd),target=/artifacts \
5660
docker.elastic.co/infra/release-manager:latest \
57-
cli collect \
61+
cli "$command" \
5862
--project apm-server \
59-
--branch $BUILDKITE_BRANCH \
63+
--branch $DRA_BRANCH \
6064
--commit $BUILDKITE_COMMIT \
6165
--workflow $workflow \
6266
--artifact-set main \
6367
--version $VERSION | tee rm-output.txt
68+
set +x
6469

65-
# Create Buildkite annotation similarly done in Beats:
66-
# https://github.com/elastic/beats/blob/90f9e8f6e48e76a83331f64f6c8c633ae6b31661/.buildkite/scripts/dra.sh#L74-L81
67-
if [[ "$command" == "collect" ]]; then
68-
# extract the summary URL from a release manager output line like:
69-
# Report summary-18.22.0.html can be found at https://artifacts-staging.elastic.co/apm-server/18.22.0-ABCDEFGH/summary-18.22.0.html
70-
SUMMARY_URL=$(grep -E '^Report summary-.* can be found at ' rm-output.txt | grep -oP 'https://\S+' | awk '{print $1}')
71-
rm rm-output.txt
72-
73-
# and make it easily clickable as a Builkite annotation
74-
printf "**${workflow} summary link:** [${SUMMARY_URL}](${SUMMARY_URL})\n" | buildkite-agent annotate --style=success --append
75-
fi
70+
create_annotation_dra_summary "$command" "$workflow" rm-output.txt
7671
}
7772

78-
dra "snapshot"
79-
if [[ "${BUILDKITE_BRANCH}" != "main" ]]; then
80-
dra "staging"
81-
fi
73+
dra "${TYPE}" "$DRA_COMMAND"

.buildkite/scripts/utils.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
retry() {
2+
local retries=$1
3+
shift
4+
5+
local count=0
6+
until "$@"; do
7+
exit=$?
8+
wait=$((2 ** count))
9+
count=$((count + 1))
10+
if [ $count -lt "$retries" ]; then
11+
>&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
12+
sleep $wait
13+
else
14+
>&2 echo "Retry $count/$retries exited $exit, no more retries left."
15+
return $exit
16+
fi
17+
done
18+
return 0
19+
}
20+
21+
#
22+
# An opinionated approach to detect if unsupported Unified Release branches
23+
# can be used, this is handy for testing feature branches in dry-run mode.
24+
# In addition support for PRs is added by using the base branch of the PR.
25+
# It produces the below environment variables:
26+
# - VERSION
27+
# - DRA_COMMAND
28+
# - DRA_BRANCH
29+
dra_process_other_branches() {
30+
VERSION=$(make get-version)
31+
DRA_BRANCH="$BUILDKITE_BRANCH"
32+
if [[ $BUILDKITE_BRANCH =~ "feature/" ]]; then
33+
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'
34+
DRA_COMMAND=list
35+
36+
# use a different branch since DRA does not support feature branches but main/release branches
37+
# for such we will use the VERSION and https://storage.googleapis.com/artifacts-api/snapshots/<major.minor>.json
38+
# to know if the branch was branched out from main or the release branches.
39+
MAJOR_MINOR=${VERSION%.*}
40+
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/main.json" | grep -q "$VERSION" ; then
41+
DRA_BRANCH=main
42+
else
43+
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/$MAJOR_MINOR.json" | grep -q "$VERSION" ; then
44+
DRA_BRANCH="$MAJOR_MINOR"
45+
else
46+
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'
47+
fi
48+
fi
49+
elif [[ -n "$BUILDKITE_PULL_REQUEST_BASE_BRANCH" ]]; then
50+
DRA_BRANCH="$BUILDKITE_PULL_REQUEST_BASE_BRANCH"
51+
DRA_COMMAND=list
52+
fi
53+
export DRA_BRANCH DRA_COMMAND VERSION
54+
}
55+
56+
# Create Buildkite annotation similarly done in Beats:
57+
# https://github.com/elastic/beats/blob/90f9e8f6e48e76a83331f64f6c8c633ae6b31661/.buildkite/scripts/dra.sh#L74-L81
58+
create_annotation_dra_summary() {
59+
local command=$1
60+
local workflow=$2
61+
local output=$3
62+
if [[ "$command" == "collect" ]]; then
63+
# extract the summary URL from a release manager output line like:
64+
# Report summary-18.22.0.html can be found at https://artifacts-staging.elastic.co/apm-server/18.22.0-ABCDEFGH/summary-18.22.0.html
65+
SUMMARY_URL=$(grep -E '^Report summary-.* can be found at ' "$output" | grep -oP 'https://\S+' | awk '{print $1}')
66+
rm "$output"
67+
68+
# and make it easily clickable as a Builkite annotation
69+
printf "**${workflow} summary link:** [${SUMMARY_URL}](${SUMMARY_URL})\n" | buildkite-agent annotate --style=success --append
70+
fi
71+
}

0 commit comments

Comments
 (0)