Skip to content

Commit 1f651a3

Browse files
Merge pull request #1478 from elastic/add-bumpmatrix-cmd
Add bumpmatrix and codegen automation commands
1 parent 6e7e1e6 commit 1f651a3

File tree

1 file changed

+52
-20
lines changed

1 file changed

+52
-20
lines changed

.github/make.sh

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@
1111
#
1212
# Targets:
1313
# ---------------------------
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
14+
# assemble <VERSION> : build client artefacts with version
15+
# bump <VERSION> : bump client internals to version
16+
# bumpmatrix <VERSION> : bump stack version in test matrix to version
17+
# codegen <VERSION> : generate endpoints
18+
# docsgen <VERSION> : generate documentation
19+
# examplegen : generate the doc examples
20+
# clean : clean workspace
2021
#
2122
# ------------------------------------------------------- #
2223

2324
# ------------------------------------------------------- #
2425
# Bootstrap
2526
# ------------------------------------------------------- #
2627

27-
script_path=$(dirname "$(realpath -s "$0")")
28+
script_path=$(dirname "$(realpath "$0")")
2829
repo=$(realpath "$script_path/../")
2930

3031
# shellcheck disable=SC1090
@@ -68,11 +69,8 @@ case $CMD in
6869
TASK_ARGS=("$VERSION" "$output_folder")
6970
;;
7071
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"
72+
VERSION=$(git rev-parse --abbrev-ref HEAD)
73+
echo -e "\033[36;1mTARGET: codegen API $VERSION\033[0m"
7674
TASK=codegen
7775
# VERSION is BRANCH here for now
7876
TASK_ARGS=("$VERSION" "$codegen_folder")
@@ -103,7 +101,16 @@ case $CMD in
103101
# VERSION is BRANCH here for now
104102
TASK_ARGS=("$VERSION")
105103
;;
106-
*)
104+
bumpmatrix)
105+
if [ -v $VERSION ]; then
106+
echo -e "\033[31;1mTARGET: bumpmatrix -> missing version parameter\033[0m"
107+
exit 1
108+
fi
109+
echo -e "\033[36;1mTARGET: bump stack in test matrix to version $VERSION\033[0m"
110+
TASK=bumpmatrix
111+
TASK_ARGS=("$VERSION")
112+
;;
113+
*)
107114
echo -e "\nUsage:\n\t $CMD is not supported right now\n"
108115
exit 1
109116
esac
@@ -113,12 +120,13 @@ esac
113120
# Build Container
114121
# ------------------------------------------------------- #
115122

116-
#echo -e "\033[34;1mINFO: building $product container\033[0m"
117-
118-
#docker build --file .github/Dockerfile --tag ${product} \
119-
# --build-arg USER_ID="$(id -u)" \
120-
# --build-arg GROUP_ID="$(id -g)" .
123+
build_container() {
124+
echo -e "\033[34;1mINFO: building $product container\033[0m"
121125

126+
docker build --file $repo/.buildkite/Dockerfile --tag ${product} \
127+
--build-arg USER_ID="$(id -u)" \
128+
--build-arg GROUP_ID="$(id -g)" .
129+
}
122130

123131
# ------------------------------------------------------- #
124132
# Run the Container
@@ -173,8 +181,32 @@ if [[ "$CMD" == "bump" ]]; then
173181
sed -i "s/es-version: \[[0-9]\+\.[0-9]\+\.\?[0-9]\?-SNAPSHOT\]/es-version: \[$MINOR_VERSION-SNAPSHOT\]/" $repo/.github/workflows/test.yml
174182
fi
175183

184+
if [[ "$CMD" == "bumpmatrix" ]]; then
185+
TEST_FILES=".buildkite/pipeline.yml .github/workflows/test.yml .github/workflows/integration_test.yml .github/workflows/yaml_test.yml"
186+
for TEST_FILE in $TEST_FILES; do
187+
sed -E -i.bak 's/[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT/'$VERSION'/g' ${TEST_FILE}
188+
rm ${TEST_FILE}.bak
189+
done
190+
exit 0
191+
fi
192+
176193
if [[ "$CMD" == "codegen" ]]; then
177-
echo "TODO"
194+
BRANCH=$VERSION
195+
if [[ "$BRANCH" == "main" ]]; then
196+
ES_VERSION="main"
197+
else
198+
ES_VERSION=$(curl -L -s https://artifacts-snapshot.elastic.co/elasticsearch/latest/$BRANCH.json | jq -r ".version")
199+
fi
200+
build_container
201+
docker run \
202+
--rm -v $repo:/code/elasticsearch-php \
203+
$product \
204+
/bin/bash -x -c "cd /code && mkdir codegen && \
205+
git clone https://$CLIENTS_GITHUB_TOKEN@github.com/elastic/elastic-client-generator-php.git && \
206+
cd /code/elastic-client-generator-php && composer install && \
207+
bin/elasticsearch9.php $ES_VERSION $BRANCH /code/codegen config/elasticsearch9.json && \
208+
cp /code/codegen/Elastic/Elasticsearch/Endpoints/* /code/elasticsearch-php/src/Endpoints/ && \
209+
cp /code/codegen/Elastic/Elasticsearch/Traits/* /code/elasticsearch-php/src/Traits/"
178210
fi
179211

180212
if [[ "$CMD" == "docsgen" ]]; then
@@ -183,4 +215,4 @@ fi
183215

184216
if [[ "$CMD" == "examplesgen" ]]; then
185217
echo "TODO"
186-
fi
218+
fi

0 commit comments

Comments
 (0)