Skip to content

Commit 10b5a84

Browse files
authored
add ci shared qualified-version script (#17311)
* ci: add shareable script for generating qualified version * ci: use shared script to generate qualified version
1 parent 787fd2c commit 10b5a84

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
# ********************************************************
4+
# Source this script to get the QUALIFIED_VERSION env var
5+
# or execute it to receive the qualified version on stdout
6+
# ********************************************************
7+
8+
set -euo pipefail
9+
10+
export QUALIFIED_VERSION="$(
11+
# Extract the version number from the version.yml file
12+
# e.g.: 8.6.0
13+
printf '%s' "$(awk -F':' '{ if ("logstash" == $1) { gsub(/^ | $/,"",$2); printf $2; exit } }' versions.yml)"
14+
15+
# Qualifier is passed from CI as optional field and specify the version postfix
16+
# in case of alpha or beta releases for staging builds only:
17+
# e.g: 8.0.0-alpha1
18+
printf '%s' "${VERSION_QUALIFIER:+-${VERSION_QUALIFIER}}"
19+
20+
# add the SNAPSHOT tag unless WORKFLOW_TYPE=="staging" or RELEASE=="1"
21+
if [[ ! ( "${WORKFLOW_TYPE:-}" == "staging" || "${RELEASE:+$RELEASE}" == "1" ) ]]; then
22+
printf '%s' "-SNAPSHOT"
23+
fi
24+
)"
25+
26+
# if invoked directly, output the QUALIFIED_VERSION to stdout
27+
if [[ "$0" == "${BASH_SOURCE:-${ZSH_SCRIPT:-}}" ]]; then
28+
printf '%s' "${QUALIFIED_VERSION}"
29+
fi

.buildkite/scripts/dra/build_docker.sh

+1-11
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,7 @@ rake artifact:docker_oss || error "artifact:docker_oss build failed."
2626
rake artifact:docker_wolfi || error "artifact:docker_wolfi build failed."
2727
rake artifact:dockerfiles || error "artifact:dockerfiles build failed."
2828

29-
if [[ "$WORKFLOW_TYPE" == "staging" ]] && [[ -n "$VERSION_QUALIFIER" ]]; then
30-
# Qualifier is passed from CI as optional field and specify the version postfix
31-
# in case of alpha or beta releases for staging builds only:
32-
# e.g: 8.0.0-alpha1
33-
STACK_VERSION="${STACK_VERSION}-${VERSION_QUALIFIER}"
34-
fi
35-
36-
if [[ "$WORKFLOW_TYPE" == "snapshot" ]]; then
37-
STACK_VERSION="${STACK_VERSION}-SNAPSHOT"
38-
fi
39-
29+
STACK_VERSION="$(./$(dirname "$0")/../common/qualified-version.sh)"
4030
info "Build complete, setting STACK_VERSION to $STACK_VERSION."
4131

4232
info "Saving tar.gz for docker images"

.buildkite/scripts/dra/build_packages.sh

+1-11
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,7 @@ esac
2323

2424
SKIP_DOCKER=1 rake artifact:all || error "rake artifact:all build failed."
2525

26-
if [[ "$WORKFLOW_TYPE" == "staging" ]] && [[ -n "$VERSION_QUALIFIER" ]]; then
27-
# Qualifier is passed from CI as optional field and specify the version postfix
28-
# in case of alpha or beta releases for staging builds only:
29-
# e.g: 8.0.0-alpha1
30-
STACK_VERSION="${STACK_VERSION}-${VERSION_QUALIFIER}"
31-
fi
32-
33-
if [[ "$WORKFLOW_TYPE" == "snapshot" ]]; then
34-
STACK_VERSION="${STACK_VERSION}-SNAPSHOT"
35-
fi
36-
26+
STACK_VERSION="$(./$(dirname "$0")/../common/qualified-version.sh)"
3727
info "Build complete, setting STACK_VERSION to $STACK_VERSION."
3828

3929
info "Generated Artifacts"

.buildkite/scripts/dra/common.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ export JRUBY_OPTS="-J-Xmx4g"
2929

3030
# Extract the version number from the version.yml file
3131
# e.g.: 8.6.0
32-
# The suffix part like alpha1 etc is managed by the optional VERSION_QUALIFIER_OPT environment variable
32+
# The suffix part like alpha1 etc is managed by the optional VERSION_QUALIFIER environment variable
3333
STACK_VERSION=`cat versions.yml | sed -n 's/^logstash\:[[:space:]]\([[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\)$/\1/p'`
3434

3535
info "Agent is running on architecture [$(uname -i)]"
3636

37-
export VERSION_QUALIFIER_OPT=${VERSION_QUALIFIER_OPT:-""}
37+
export VERSION_QUALIFIER=${VERSION_QUALIFIER:-""}
3838
export DRA_DRY_RUN=${DRA_DRY_RUN:-""}
3939

4040
if [[ ! -z $DRA_DRY_RUN && $BUILDKITE_STEP_KEY == "logstash_publish_dra" ]]; then

.buildkite/scripts/dra/publish.sh

+1-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ fi
4545
info "Downloaded ARTIFACTS sha report"
4646
for file in build/logstash-*; do shasum $file;done
4747

48-
FINAL_VERSION=$STACK_VERSION
49-
if [[ -n "$VERSION_QUALIFIER" ]]; then
50-
FINAL_VERSION="$FINAL_VERSION-${VERSION_QUALIFIER}"
51-
fi
52-
53-
if [[ "$WORKFLOW_TYPE" == "snapshot" ]]; then
54-
FINAL_VERSION="${STACK_VERSION}-SNAPSHOT"
55-
fi
48+
FINAL_VERSION="$(./$(dirname "$0")/../common/qualified-version.sh)"
5649

5750
mv build/distributions/dependencies-reports/logstash-${FINAL_VERSION}.csv build/distributions/dependencies-${FINAL_VERSION}.csv
5851

0 commit comments

Comments
 (0)