From 0e422207ef6cdfc3f41f90117e0140a3cac5665d Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Tue, 13 Feb 2024 11:49:20 +0400 Subject: [PATCH 1/4] Restore .ci/make.sh file --- .ci/make.sh | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100755 .ci/make.sh diff --git a/.ci/make.sh b/.ci/make.sh new file mode 100755 index 000000000..b628df473 --- /dev/null +++ b/.ci/make.sh @@ -0,0 +1,184 @@ +#!/usr/bin/env bash + +# ------------------------------------------------------- # +# +# Skeleton for common build entry script for all elastic +# clients. Needs to be adapted to individual client usage. +# +# Must be called: ./.ci/make.sh +# +# Version: 1.1.0 +# +# Targets: +# --------------------------- +# assemble : build client artefacts with version +# bump : bump client internals to version +# codegen : generate endpoints +# docsgen : generate documentation +# examplegen : generate the doc examples +# clean : clean workspace +# +# ------------------------------------------------------- # + +# ------------------------------------------------------- # +# Bootstrap +# ------------------------------------------------------- # + +script_path=$(dirname "$(realpath -s "$0")") +repo=$(realpath "$script_path/../") + +# shellcheck disable=SC1090 +CMD=$1 +TASK=$1 +TASK_ARGS=() +VERSION=$2 +STACK_VERSION=$VERSION +set -euo pipefail + +product="elastic/elasticsearch-py" +output_folder=".ci/output" +codegen_folder=".ci/output" +OUTPUT_DIR="$repo/${output_folder}" +REPO_BINDING="${OUTPUT_DIR}:/sln/${output_folder}" +WORKFLOW="${WORKFLOW-staging}" +mkdir -p "$OUTPUT_DIR" + +echo -e "\033[34;1mINFO:\033[0m PRODUCT ${product}\033[0m" +echo -e "\033[34;1mINFO:\033[0m VERSION ${STACK_VERSION}\033[0m" +echo -e "\033[34;1mINFO:\033[0m OUTPUT_DIR ${OUTPUT_DIR}\033[0m" + +# ------------------------------------------------------- # +# Parse Command +# ------------------------------------------------------- # + +case $CMD in + clean) + echo -e "\033[36;1mTARGET: clean workspace $output_folder\033[0m" + rm -rf "$output_folder" + echo -e "\033[32;1mdone.\033[0m" + exit 0 + ;; + assemble) + if [ -v $VERSION ]; then + echo -e "\033[31;1mTARGET: assemble -> missing version parameter\033[0m" + exit 1 + fi + echo -e "\033[36;1mTARGET: assemble artefact $VERSION\033[0m" + TASK=release + TASK_ARGS=("$VERSION" "$output_folder") + ;; + codegen) + VERSION=$(git rev-parse --abbrev-ref HEAD) + echo -e "\033[36;1mTARGET: codegen API $VERSION\033[0m" + TASK=codegen + # VERSION is BRANCH here for now + TASK_ARGS=("$VERSION" "$codegen_folder") + ;; + docsgen) + if [ -v $VERSION ]; then + echo -e "\033[31;1mTARGET: docsgen -> missing version parameter\033[0m" + exit 1 + fi + echo -e "\033[36;1mTARGET: generate docs for $VERSION\033[0m" + TASK=codegen + # VERSION is BRANCH here for now + TASK_ARGS=("$VERSION" "$codegen_folder") + ;; + examplesgen) + echo -e "\033[36;1mTARGET: generate examples\033[0m" + TASK=codegen + # VERSION is BRANCH here for now + TASK_ARGS=("$VERSION" "$codegen_folder") + ;; + bump) + if [ -v $VERSION ]; then + echo -e "\033[31;1mTARGET: bump -> missing version parameter\033[0m" + exit 1 + fi + echo -e "\033[36;1mTARGET: bump to version $VERSION\033[0m" + TASK=bump + # VERSION is BRANCH here for now + TASK_ARGS=("$VERSION") + ;; + *) + echo -e "\nUsage:\n\t $CMD is not supported right now\n" + exit 1 +esac + + +# ------------------------------------------------------- # +# Build Container +# ------------------------------------------------------- # + +echo -e "\033[34;1mINFO: building $product container\033[0m" + +docker build \ + --build-arg BUILDER_UID="$(id -u)" \ + --file $repo/.ci/Dockerfile \ + --tag ${product} \ + . + +# ------------------------------------------------------- # +# Run the Container +# ------------------------------------------------------- # + +echo -e "\033[34;1mINFO: running $product container\033[0m" + +if [[ "$CMD" == "assemble" ]]; then + + # Build dists into .ci/output + docker run \ + -u "$(id -u)" \ + --rm -v $repo/.ci/output:/code/elasticsearch-py/dist \ + $product \ + /bin/bash -c "python /code/elasticsearch-py/utils/build-dists.py $VERSION" + + # Verify that there are dists in .ci/output + if compgen -G ".ci/output/*" > /dev/null; then + + # Tarball everything up in .ci/output + if [[ "$WORKFLOW" == 'snapshot' ]]; then + cd $repo/.ci/output && tar -czvf elasticsearch-py-$VERSION-SNAPSHOT.tar.gz * && cd - + else + cd $repo/.ci/output && tar -czvf elasticsearch-py-$VERSION.tar.gz * && cd - + fi + + echo -e "\033[32;1mTARGET: successfully assembled client v$VERSION\033[0m" + exit 0 + else + echo -e "\033[31;1mTARGET: assemble failed, empty workspace!\033[0m" + exit 1 + fi +fi + +if [[ "$CMD" == "bump" ]]; then + docker run \ + --rm -v $repo:/code/elasticsearch-py \ + $product \ + /bin/bash -c "python /code/elasticsearch-py/utils/bump-version.py $VERSION" + + exit 0 +fi + +if [[ "$CMD" == "codegen" ]]; then + docker run \ + --rm -v $repo:/code/elasticsearch-py \ + $product \ + /bin/bash -c "cd /code && python -m pip install nox && \ + git clone https://$CLIENTS_GITHUB_TOKEN@github.com/elastic/elastic-client-generator-python.git && \ + cd /code/elastic-client-generator-python && GIT_BRANCH=$VERSION python -m nox -s generate-es && \ + cd /code/elasticsearch-py && python -m nox -s format" + + exit 0 +fi + +if [[ "$CMD" == "docsgen" ]]; then + echo "TODO" +fi + +if [[ "$CMD" == "examplesgen" ]]; then + echo "TODO" +fi + +echo "Must be called with '.ci/make.sh [command]" +exit 1 From 27cd32c81ce0f675ee9fcec1fd7254e562293986 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Tue, 13 Feb 2024 14:08:08 +0400 Subject: [PATCH 2/4] Move make.sh from .ci to .github --- {.ci => .github}/make.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {.ci => .github}/make.sh (100%) diff --git a/.ci/make.sh b/.github/make.sh similarity index 100% rename from .ci/make.sh rename to .github/make.sh From 716a8f7d2f4ecfbc67658b30d56dcc60c79753bf Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Thu, 15 Feb 2024 15:58:04 +0400 Subject: [PATCH 3/4] Fix references to .ci --- .github/make.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/make.sh b/.github/make.sh index b628df473..d152675bd 100755 --- a/.github/make.sh +++ b/.github/make.sh @@ -5,7 +5,7 @@ # Skeleton for common build entry script for all elastic # clients. Needs to be adapted to individual client usage. # -# Must be called: ./.ci/make.sh +# Must be called: ./.github/make.sh # # Version: 1.1.0 # @@ -36,8 +36,8 @@ STACK_VERSION=$VERSION set -euo pipefail product="elastic/elasticsearch-py" -output_folder=".ci/output" -codegen_folder=".ci/output" +output_folder=".github/output" +codegen_folder=".github/output" OUTPUT_DIR="$repo/${output_folder}" REPO_BINDING="${OUTPUT_DIR}:/sln/${output_folder}" WORKFLOW="${WORKFLOW-staging}" @@ -114,7 +114,7 @@ echo -e "\033[34;1mINFO: building $product container\033[0m" docker build \ --build-arg BUILDER_UID="$(id -u)" \ - --file $repo/.ci/Dockerfile \ + --file $repo/.buildkite/Dockerfile \ --tag ${product} \ . @@ -126,21 +126,21 @@ echo -e "\033[34;1mINFO: running $product container\033[0m" if [[ "$CMD" == "assemble" ]]; then - # Build dists into .ci/output + # Build dists into .github/output docker run \ -u "$(id -u)" \ - --rm -v $repo/.ci/output:/code/elasticsearch-py/dist \ + --rm -v $repo/.github/output:/code/elasticsearch-py/dist \ $product \ /bin/bash -c "python /code/elasticsearch-py/utils/build-dists.py $VERSION" - # Verify that there are dists in .ci/output - if compgen -G ".ci/output/*" > /dev/null; then + # Verify that there are dists in .github/output + if compgen -G ".github/output/*" > /dev/null; then - # Tarball everything up in .ci/output + # Tarball everything up in .github/output if [[ "$WORKFLOW" == 'snapshot' ]]; then - cd $repo/.ci/output && tar -czvf elasticsearch-py-$VERSION-SNAPSHOT.tar.gz * && cd - + cd $repo/.github/output && tar -czvf elasticsearch-py-$VERSION-SNAPSHOT.tar.gz * && cd - else - cd $repo/.ci/output && tar -czvf elasticsearch-py-$VERSION.tar.gz * && cd - + cd $repo/.github/output && tar -czvf elasticsearch-py-$VERSION.tar.gz * && cd - fi echo -e "\033[32;1mTARGET: successfully assembled client v$VERSION\033[0m" @@ -180,5 +180,5 @@ if [[ "$CMD" == "examplesgen" ]]; then echo "TODO" fi -echo "Must be called with '.ci/make.sh [command]" +echo "Must be called with '.github/make.sh [command]" exit 1 From 38d437df4d1ada5b31b290412ab4437660af35ff Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Thu, 15 Feb 2024 16:04:02 +0400 Subject: [PATCH 4/4] Fix assemble command --- .github/make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/make.sh b/.github/make.sh index d152675bd..79d785957 100755 --- a/.github/make.sh +++ b/.github/make.sh @@ -131,7 +131,7 @@ if [[ "$CMD" == "assemble" ]]; then -u "$(id -u)" \ --rm -v $repo/.github/output:/code/elasticsearch-py/dist \ $product \ - /bin/bash -c "python /code/elasticsearch-py/utils/build-dists.py $VERSION" + /bin/bash -c "pip install build; python /code/elasticsearch-py/utils/build-dists.py $VERSION" # Verify that there are dists in .github/output if compgen -G ".github/output/*" > /dev/null; then