Skip to content

Commit c95e71d

Browse files
authored
Merge branch 'main' into otel-adapter
2 parents 45f84a7 + e7deaa4 commit c95e71d

File tree

28 files changed

+353
-134
lines changed

28 files changed

+353
-134
lines changed

.buildkite/hooks/pre-command

+2-19
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,8 @@
1010

1111
set -eo pipefail
1212

13-
retry() {
14-
local retries=$1
15-
shift
16-
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-
}
13+
# shellcheck disable=SC1091
14+
source .buildkite/scripts/utils.sh
3215

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

.buildkite/scripts/dra.sh

+24-57
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ set -eo pipefail
1313
# Either staging or snapshot
1414
TYPE="$1"
1515

16-
## Read current version without the qualifier
17-
VERSION=$(make get-version-only)
16+
# NOTE: load the shared functions
17+
# shellcheck disable=SC1091
18+
source .buildkite/scripts/utils.sh
1819

1920
echo "--- Restoring Artifacts"
2021
buildkite-agent artifact download "build/**/*" .
@@ -34,48 +35,26 @@ fi
3435
# by default it uses the buildkite branch
3536
DRA_BRANCH="$BUILDKITE_BRANCH"
3637
# by default it publishes the DRA artifacts, for such it uses the collect command.
37-
dra_command=collect
38+
DRA_COMMAND=collect
39+
VERSION=$(make get-version-only)
3840
BRANCHES_URL=https://storage.googleapis.com/artifacts-api/snapshots/branches.json
3941
curl -s "${BRANCHES_URL}" > active-branches.json
40-
# as long as `8.x` is not in the active branches, we will explicitly add the condition.
41-
if [ "$BUILDKITE_BRANCH" == "8.x" ] || grep -q "\"$BUILDKITE_BRANCH\"" active-branches.json ; then
42-
echo "--- :arrow_right: Release Manager only supports the current active branches and 8.x, running"
43-
else
42+
if ! grep -q "\"$BUILDKITE_BRANCH\"" active-branches.json ; then
4443
# If no active branches are found, let's see if it is a feature branch.
45-
echo "--- :arrow_right: Release Manager only supports the current active branches, skipping"
46-
echo "BUILDKITE_BRANCH=$BUILDKITE_BRANCH"
47-
echo "BUILDKITE_COMMIT=$BUILDKITE_COMMIT"
48-
echo "VERSION=$VERSION"
49-
echo "Supported branches:"
50-
cat active-branches.json
51-
if [[ $BUILDKITE_BRANCH =~ "feature/" ]]; then
52-
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'
53-
dra_command=list
54-
55-
# use a different branch since DRA does not support feature branches but main/release branches
56-
# for such we will use the VERSION and https://storage.googleapis.com/artifacts-api/snapshots/<major.minor>.json
57-
# to know if the branch was branched out from main or the release branches.
58-
MAJOR_MINOR=${VERSION%.*}
59-
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/main.json" | grep -q "$VERSION" ; then
60-
DRA_BRANCH=main
61-
else
62-
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/$MAJOR_MINOR.json" | grep -q "$VERSION" ; then
63-
DRA_BRANCH="$MAJOR_MINOR"
64-
else
65-
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'
66-
exit 0
67-
fi
68-
fi
69-
else
70-
buildkite-agent annotate "${BUILDKITE_BRANCH} is not supported yet. Look for the supported branches in ${BRANCHES_URL}" --style 'warning' --context 'ctx-warn'
71-
exit 1
72-
fi
44+
dra_process_other_branches
7345
fi
7446

47+
echo "--- :arrow_right: Release Manager only supports the current active branches"
48+
echo "BUILDKITE_BRANCH=$BUILDKITE_BRANCH"
49+
echo "BUILDKITE_COMMIT=$BUILDKITE_COMMIT"
50+
echo "VERSION=$VERSION"
51+
echo "Supported branches:"
52+
cat active-branches.json
53+
7554
dra() {
7655
local workflow=$1
7756
local command=$2
78-
local qualifier=${ELASTIC_QUALIFIER:-""}
57+
local qualifier=${3:-""}
7958
echo "--- Run release manager $workflow (DRA command: $command)"
8059
set -x
8160
docker run --rm \
@@ -94,32 +73,20 @@ dra() {
9473
--qualifier "$qualifier" \
9574
--version $VERSION | tee rm-output.txt
9675
set +x
97-
# Create Buildkite annotation similarly done in Beats:
98-
# https://github.com/elastic/beats/blob/90f9e8f6e48e76a83331f64f6c8c633ae6b31661/.buildkite/scripts/dra.sh#L74-L81
99-
if [[ "$command" == "collect" ]]; then
100-
# extract the summary URL from a release manager output line like:
101-
# 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
102-
SUMMARY_URL=$(grep -E '^Report summary-.* can be found at ' rm-output.txt | grep -oP 'https://\S+' | awk '{print $1}')
103-
rm rm-output.txt
10476

105-
# and make it easily clickable as a Builkite annotation
106-
printf "**${workflow} summary link:** [${SUMMARY_URL}](${SUMMARY_URL})\n" | buildkite-agent annotate --style=success --append
107-
fi
77+
create_annotation_dra_summary "$command" "$workflow" rm-output.txt
10878
}
10979

11080
if [[ "${TYPE}" == "staging" ]]; then
81+
qualifier=$(fetch_elastic_qualifier "$DRA_BRANCH")
82+
# TODO: main and 8.x are not needed to run the DRA for staging
83+
# but main is needed until we do alpha1 releases of 9.0.0
11184
if [[ "${DRA_BRANCH}" != "8.x" ]]; then
112-
echo "${DRA_BRANCH} is not '8.x'"
113-
if [[ "${DRA_BRANCH}" == "main" ]] ; then
114-
# NOTE: qualifier is needed for main/staging at the moment. Skip builds if no ELASTIC_QUALIFIER
115-
if [[ -n "${ELASTIC_QUALIFIER}" ]]; then
116-
dra "${TYPE}" "$dra_command"
117-
fi
118-
else
119-
dra "${TYPE}" "$dra_command"
120-
fi
85+
dra "${TYPE}" "$DRA_COMMAND" "${qualifier}"
12186
fi
122-
else
87+
fi
88+
89+
if [[ "${TYPE}" == "snapshot" ]]; then
12390
# NOTE: qualifier is not needed for snapshots, let's unset it.
124-
dra "snapshot" "$dra_command" ""
91+
dra "${TYPE}" "$DRA_COMMAND" ""
12592
fi

.buildkite/scripts/package.sh

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ if [[ ${TYPE} == "snapshot" ]]; then
1919
MAKE_GOAL="${MAKE_GOAL}-snapshot"
2020
fi
2121

22+
if [[ ${TYPE} == "staging" ]]; then
23+
echo "--- Prepare the Elastic Qualifier"
24+
# NOTE: load the shared functions
25+
# shellcheck disable=SC1091
26+
source .buildkite/scripts/utils.sh
27+
dra_process_other_branches
28+
ELASTIC_QUALIFIER=$(fetch_elastic_qualifier "$DRA_BRANCH")
29+
export ELASTIC_QUALIFIER
30+
fi
31+
32+
echo "--- Run $MAKE_GOAL for $DRA_BRANCH"
2233
make $MAKE_GOAL
2334

2435
ls -l build/distributions/

.buildkite/scripts/utils.sh

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# An opinionated approach to manage the Elatic Qualifier for the DRA in a Google Bucket
2+
# Instead of using the ELASTIC_QUALIFIER env variable.
3+
fetch_elastic_qualifier() {
4+
local branch=$1
5+
qualifier=""
6+
URL="https://storage.googleapis.com/dra-qualifier/$branch"
7+
if curl -sf -o /dev/null "$URL" ; then
8+
qualifier=$(curl -s "$URL")
9+
fi
10+
echo "$qualifier"
11+
}
12+
13+
retry() {
14+
local retries=$1
15+
shift
16+
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+
}
32+
33+
#
34+
# An opinionated approach to detect if unsupported Unified Release branches
35+
# can be used, this is handy for testing feature branches in dry-run mode
36+
# It produces the below environment variables:
37+
# - VERSION
38+
# - DRA_COMMAND
39+
# - DRA_BRANCH
40+
dra_process_other_branches() {
41+
## Read current version without the qualifier
42+
VERSION=$(make get-version-only)
43+
DRA_BRANCH="$BUILDKITE_BRANCH"
44+
if [[ $BUILDKITE_BRANCH =~ "feature/" ]]; then
45+
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'
46+
DRA_COMMAND=list
47+
48+
# use a different branch since DRA does not support feature branches but main/release branches
49+
# for such we will use the VERSION and https://storage.googleapis.com/artifacts-api/snapshots/<major.minor>.json
50+
# to know if the branch was branched out from main or the release branches.
51+
MAJOR_MINOR=${VERSION%.*}
52+
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/main.json" | grep -q "$VERSION" ; then
53+
DRA_BRANCH=main
54+
else
55+
if curl -s "https://storage.googleapis.com/artifacts-api/snapshots/$MAJOR_MINOR.json" | grep -q "$VERSION" ; then
56+
DRA_BRANCH="$MAJOR_MINOR"
57+
else
58+
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'
59+
fi
60+
fi
61+
fi
62+
export DRA_BRANCH DRA_COMMAND VERSION
63+
}
64+
65+
# Create Buildkite annotation similarly done in Beats:
66+
# https://github.com/elastic/beats/blob/90f9e8f6e48e76a83331f64f6c8c633ae6b31661/.buildkite/scripts/dra.sh#L74-L81
67+
create_annotation_dra_summary() {
68+
local command=$1
69+
local workflow=$2
70+
local output=$3
71+
if [[ "$command" == "collect" ]]; then
72+
# extract the summary URL from a release manager output line like:
73+
# 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
74+
SUMMARY_URL=$(grep -E '^Report summary-.* can be found at ' "$output" | grep -oP 'https://\S+' | awk '{print $1}')
75+
rm "$output"
76+
77+
# and make it easily clickable as a Builkite annotation
78+
printf "**${workflow} summary link:** [${SUMMARY_URL}](${SUMMARY_URL})\n" | buildkite-agent annotate --style=success --append
79+
fi
80+
}

.github/workflows/prepare-release/action.yml

+20
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ runs:
4949
VERSION: ${{ inputs.version }}
5050
shell: 'bash'
5151

52+
- name: validate version format (major only)
53+
if: ${{ inputs.type == 'major' && ! endsWith(inputs.version, '.0.0') }}
54+
run: |-
55+
FAILURE_MESSAGE='version is not a major one but a patch (only support for <major>.0.0)'
56+
echo "FAILURE_MESSAGE=${FAILURE_MESSAGE}" >> "$GITHUB_ENV"
57+
echo "::error::${FAILURE_MESSAGE}" ; exit 1
58+
shell: 'bash'
59+
5260
- name: validate version format (minor only)
5361
if: ${{ inputs.type == 'minor' && ! endsWith(inputs.version, '0') }}
5462
run: |-
@@ -65,6 +73,18 @@ runs:
6573
echo "::error::${FAILURE_MESSAGE}" ; exit 1
6674
shell: 'bash'
6775

76+
- name: validate if branch already exists (major only)
77+
if: ${{ inputs.type == 'major' }}
78+
run: |-
79+
if git ls-remote --exit-code --heads "https://github.com/${GITHUB_REPOSITORY}.git" "$BRANCH" > /dev/null ; then
80+
echo "FAILURE_MESSAGE=${FAILURE_MESSAGE}" >> "$GITHUB_ENV"
81+
echo "::error::${FAILURE_MESSAGE}" ; exit 1
82+
fi
83+
shell: 'bash'
84+
env:
85+
BRANCH: ${{ steps.generate.outputs.release-branch }}
86+
FAILURE_MESSAGE: Branch already exists. This is not a major release.
87+
6888
- name: validate if branch already exists (minor only)
6989
if: ${{ inputs.type == 'minor' }}
7090
run: |-
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
name: run-major-release
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: 'The new version to be set, normally the version in the main branch (semver format: major.0.0)'
9+
required: true
10+
type: string
11+
12+
# Avoid concurrency so we can watch the releases correctly
13+
concurrency:
14+
group: ${{ github.workflow }}
15+
16+
permissions:
17+
contents: read
18+
19+
env:
20+
JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
21+
SLACK_CHANNEL: "#apm-server"
22+
23+
jobs:
24+
prepare:
25+
runs-on: ubuntu-latest
26+
outputs:
27+
release-branch: ${{ steps.prepare.outputs.release-branch }}
28+
release-type: ${{ steps.prepare.outputs.release-type }}
29+
release-version: ${{ steps.prepare.outputs.release-version }}
30+
slack-thread: ${{ steps.prepare.outputs.slack-thread }}
31+
steps:
32+
- uses: actions/checkout@v4
33+
- id: prepare
34+
uses: ./.github/workflows/prepare-release
35+
with:
36+
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
37+
version: ${{ inputs.version }}
38+
type: 'major'
39+
40+
run-major:
41+
runs-on: ubuntu-latest
42+
needs: [ prepare ]
43+
env:
44+
RELEASE_BRANCH: ${{ needs.prepare.outputs.release-branch }}
45+
RELEASE_TYPE: ${{ needs.prepare.outputs.release-type }}
46+
RELEASE_VERSION: ${{ needs.prepare.outputs.release-version }}
47+
permissions:
48+
contents: write
49+
steps:
50+
51+
- uses: elastic/oblt-actions/slack/send@v1
52+
with:
53+
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
54+
channel-id: ${{ env.SLACK_CHANNEL }}
55+
message: |-
56+
Feature freeze for `${{ github.repository }}@${{ env.RELEASE_VERSION }}` just started.
57+
The `${{ github.repository }}@${{ env.RELEASE_BRANCH }}` branch will be created Today.
58+
thread-timestamp: ${{ needs.prepare.outputs.slack-thread || '' }}
59+
60+
- name: Get token
61+
id: get_token
62+
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
63+
with:
64+
app_id: ${{ secrets.OBS_AUTOMATION_APP_ID }}
65+
private_key: ${{ secrets.OBS_AUTOMATION_APP_PEM }}
66+
permissions: >-
67+
{
68+
"contents": "write",
69+
"pull_requests": "write"
70+
}
71+
72+
- uses: actions/checkout@v4
73+
with:
74+
# 0 indicates all history for all branches and tags.
75+
fetch-depth: 0
76+
77+
# Required to use a service account, otherwise PRs created by
78+
# GitHub bot won't trigger any CI builds.
79+
# See https://github.com/peter-evans/create-pull-request/issues/48#issuecomment-537478081
80+
- name: Configure git user
81+
uses: elastic/oblt-actions/git/setup@v1
82+
with:
83+
github-token: ${{ steps.get_token.outputs.token }}
84+
85+
- name: Import GPG key
86+
uses: crazy-max/ghaction-import-gpg@cb9bde2e2525e640591a934b1fd28eef1dcaf5e5 # v6.2.0
87+
with:
88+
gpg_private_key: ${{ secrets.APM_SERVER_RELEASE_GPG_PRIVATE_KEY }}
89+
passphrase: ${{ secrets.APM_SERVER_RELEASE_PASSPHRASE }}
90+
git_user_signingkey: true
91+
git_commit_gpgsign: true
92+
93+
- run: make major-release
94+
env:
95+
GH_TOKEN: ${{ steps.get_token.outputs.token }}
96+
97+
- if: success()
98+
uses: elastic/oblt-actions/slack/send@v1
99+
with:
100+
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
101+
channel-id: ${{ env.SLACK_CHANNEL }}
102+
message: |-
103+
`${{ github.repository }}@${{ env.RELEASE_BRANCH }}` is now available.
104+
The docs and other references are updated. You can start using it.
105+
thread-timestamp: ${{ needs.prepare.outputs.slack-thread || '' }}
106+
107+
- if: failure()
108+
uses: elastic/oblt-actions/slack/send@v1
109+
with:
110+
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
111+
channel-id: ${{ env.SLACK_CHANNEL }}
112+
message: |-
113+
:fire: Something went wrong with the release. See <${{ env.JOB_URL }}|logs>.
114+
thread-timestamp: ${{ needs.prepare.outputs.slack-thread || '' }}

0 commit comments

Comments
 (0)