Skip to content

Commit b635a0d

Browse files
committed
Added and updated make.sh in buildkite
1 parent 478ca36 commit b635a0d

File tree

2 files changed

+188
-0
lines changed

2 files changed

+188
-0
lines changed

.buildkite/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tmp/
2+
output/

.buildkite/make.sh

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/usr/bin/env bash
2+
3+
# ------------------------------------------------------- #
4+
#
5+
# Skeleton for common build entry script for all elastic
6+
# clients. Needs to be adapted to individual client usage.
7+
#
8+
# Must be called: ./.buildkite/make.sh <target> <params>
9+
#
10+
# Version: 1.1.1
11+
#
12+
# Targets:
13+
# ---------------------------
14+
# assemble <VERSION> : build client artefacts with version
15+
# bump <VERSION> : bump client internals to version
16+
# codegen <VERSION> : generate endpoints
17+
# docsgen <VERSION> : generate documentation
18+
# examplegen : generate the doc examples
19+
# clean : clean workspace
20+
#
21+
# ------------------------------------------------------- #
22+
23+
# ------------------------------------------------------- #
24+
# Bootstrap
25+
# ------------------------------------------------------- #
26+
27+
script_path=$(dirname "$(realpath -s "$0")")
28+
repo=$(realpath "$script_path/../")
29+
30+
# shellcheck disable=SC1090
31+
CMD=$1
32+
TASK=$1
33+
TASK_ARGS=()
34+
VERSION=$2
35+
STACK_VERSION=$VERSION
36+
WORKFLOW=${WORKFLOW-staging}
37+
set -euo pipefail
38+
39+
product="elastic/elasticsearch-php"
40+
output_folder=".buildkite/output"
41+
codegen_folder=".buildkite/output"
42+
OUTPUT_DIR="$repo/${output_folder}"
43+
REPO_BINDING="${OUTPUT_DIR}:/sln/${output_folder}"
44+
mkdir -p "$OUTPUT_DIR"
45+
46+
echo -e "\033[34;1mINFO:\033[0m PRODUCT ${product}\033[0m"
47+
echo -e "\033[34;1mINFO:\033[0m VERSION ${STACK_VERSION}\033[0m"
48+
echo -e "\033[34;1mINFO:\033[0m OUTPUT_DIR ${OUTPUT_DIR}\033[0m"
49+
50+
# ------------------------------------------------------- #
51+
# Parse Command
52+
# ------------------------------------------------------- #
53+
54+
case $CMD in
55+
clean)
56+
echo -e "\033[36;1mTARGET: clean workspace $output_folder\033[0m"
57+
rm -rfv "$output_folder"
58+
echo -e "\033[32;1mTARGET: clean - done.\033[0m"
59+
exit 0
60+
;;
61+
assemble)
62+
if [ -v $VERSION ]; then
63+
echo -e "\033[31;1mTARGET: assemble -> missing version parameter\033[0m"
64+
exit 1
65+
fi
66+
echo -e "\033[36;1mTARGET: assemble artefact $VERSION\033[0m"
67+
TASK=release
68+
TASK_ARGS=("$VERSION" "$output_folder")
69+
;;
70+
codegen)
71+
if [ -v $VERSION ]; then
72+
echo -e "\033[31;1mTARGET: codegen -> missing version parameter\033[0m"
73+
exit 1
74+
fi
75+
echo -e "\033[36;1mTARGET: codegen API v$VERSION\033[0m"
76+
TASK=codegen
77+
# VERSION is BRANCH here for now
78+
TASK_ARGS=("$VERSION" "$codegen_folder")
79+
;;
80+
docsgen)
81+
if [ -v $VERSION ]; then
82+
echo -e "\033[31;1mTARGET: docsgen -> missing version parameter\033[0m"
83+
exit 1
84+
fi
85+
echo -e "\033[36;1mTARGET: generate docs for $VERSION\033[0m"
86+
TASK=codegen
87+
# VERSION is BRANCH here for now
88+
TASK_ARGS=("$VERSION" "$codegen_folder")
89+
;;
90+
examplesgen)
91+
echo -e "\033[36;1mTARGET: generate examples\033[0m"
92+
TASK=codegen
93+
# VERSION is BRANCH here for now
94+
TASK_ARGS=("$VERSION" "$codegen_folder")
95+
;;
96+
bump)
97+
if [ -v $VERSION ]; then
98+
echo -e "\033[31;1mTARGET: bump -> missing version parameter\033[0m"
99+
exit 1
100+
fi
101+
echo -e "\033[36;1mTARGET: bump to version $VERSION\033[0m"
102+
TASK=bump
103+
# VERSION is BRANCH here for now
104+
TASK_ARGS=("$VERSION")
105+
;;
106+
*)
107+
echo -e "\nUsage:\n\t $CMD is not supported right now\n"
108+
exit 1
109+
esac
110+
111+
112+
# ------------------------------------------------------- #
113+
# Build Container
114+
# ------------------------------------------------------- #
115+
116+
#echo -e "\033[34;1mINFO: building $product container\033[0m"
117+
118+
#docker build --file .buildkite/Dockerfile --tag ${product} \
119+
# --build-arg USER_ID="$(id -u)" \
120+
# --build-arg GROUP_ID="$(id -g)" .
121+
122+
123+
# ------------------------------------------------------- #
124+
# Run the Container
125+
# ------------------------------------------------------- #
126+
127+
#echo -e "\033[34;1mINFO: running $product container\033[0m"
128+
129+
#docker run \
130+
# --env "DOTNET_VERSION" \
131+
# --name test-runner \
132+
# --volume $REPO_BINDING \
133+
# --rm \
134+
# $product \
135+
# /bin/bash -c "./build.sh $TASK ${TASK_ARGS[*]} && chown -R $(id -u):$(id -g) ."
136+
137+
# ------------------------------------------------------- #
138+
# Post Command tasks & checks
139+
# ------------------------------------------------------- #
140+
141+
if [[ "$CMD" == "assemble" ]]; then
142+
echo -e "\033[34;1mINFO: copy artefacts\033[0m"
143+
rsync -ar --exclude=.buildkite --exclude=.git --filter=':- .gitignore' "$PWD" "${output_folder}/."
144+
145+
if compgen -G ".buildkite/output/*" > /dev/null; then
146+
if [[ "$WORKFLOW" == "snapshot" ]]; then
147+
cd $repo/.buildkite/output && tar -czf elasticsearch-php-$VERSION-SNAPSHOT.tar.gz * && cd -
148+
else
149+
cd $repo/.buildkite/output && tar -czf elasticsearch-php-$VERSION.tar.gz * && cd -
150+
fi
151+
rm -Rf "${repo}/.buildkite/output/elasticsearch-php"
152+
echo -e "\033[32;1mTARGET: successfully assembled client v$VERSION\033[0m"
153+
exit 0
154+
else
155+
echo -e "\033[31;1mTARGET: assemble failed, empty workspace!\033[0m"
156+
exit 1
157+
fi
158+
fi
159+
160+
if [[ "$CMD" == "bump" ]]; then
161+
# Change version to src/Client.php
162+
sed -i "s/const VERSION = '[0-9]\+\.[0-9]\+\.[0-9]\+'/const VERSION = '$VERSION'/" $repo/src/Client.php
163+
164+
# Change version to .github/workflows/unified-release.yml
165+
sed -i "s/[0-9]\+\.[0-9]\+\.[0-9]\+-SNAPSHOT/$VERSION-SNAPSHOT/" $repo/.github/workflows/unified-release.yml
166+
167+
MINOR_VERSION=`echo $VERSION | grep -Eo "[0-9]+.[0-9]+"`
168+
169+
# Change version to .buildkite/pipeline.yml
170+
sed -i "s/STACK_VERSION: [0-9]\+\.[0-9]\+-SNAPSHOT/STACK_VERSION: $MINOR_VERSION-SNAPSHOT/" $repo/.buildkite/pipeline.yml
171+
172+
# Change version to .github/workflows/test.yml
173+
sed -i "s/es-version: \[[0-9]\+\.[0-9]\+\.\?[0-9]\?-SNAPSHOT\]/es-version: \[$MINOR_VERSION-SNAPSHOT\]/" $repo/.github/workflows/test.yml
174+
fi
175+
176+
if [[ "$CMD" == "codegen" ]]; then
177+
echo "TODO"
178+
fi
179+
180+
if [[ "$CMD" == "docsgen" ]]; then
181+
echo "TODO"
182+
fi
183+
184+
if [[ "$CMD" == "examplesgen" ]]; then
185+
echo "TODO"
186+
fi

0 commit comments

Comments
 (0)