|
| 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: ./.github/make.sh <target> <params> |
| 9 | +# |
| 10 | +# Version: 1.1.0 |
| 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 | +set -euo pipefail |
| 37 | + |
| 38 | +product="elastic/elasticsearch-py" |
| 39 | +output_folder=".github/output" |
| 40 | +codegen_folder=".github/output" |
| 41 | +OUTPUT_DIR="$repo/${output_folder}" |
| 42 | +REPO_BINDING="${OUTPUT_DIR}:/sln/${output_folder}" |
| 43 | +WORKFLOW="${WORKFLOW-staging}" |
| 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 -rf "$output_folder" |
| 58 | + echo -e "\033[32;1mdone.\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 | + VERSION=$(git rev-parse --abbrev-ref HEAD) |
| 72 | + echo -e "\033[36;1mTARGET: codegen API $VERSION\033[0m" |
| 73 | + TASK=codegen |
| 74 | + # VERSION is BRANCH here for now |
| 75 | + TASK_ARGS=("$VERSION" "$codegen_folder") |
| 76 | + ;; |
| 77 | + docsgen) |
| 78 | + if [ -v $VERSION ]; then |
| 79 | + echo -e "\033[31;1mTARGET: docsgen -> missing version parameter\033[0m" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | + echo -e "\033[36;1mTARGET: generate docs for $VERSION\033[0m" |
| 83 | + TASK=codegen |
| 84 | + # VERSION is BRANCH here for now |
| 85 | + TASK_ARGS=("$VERSION" "$codegen_folder") |
| 86 | + ;; |
| 87 | + examplesgen) |
| 88 | + echo -e "\033[36;1mTARGET: generate examples\033[0m" |
| 89 | + TASK=codegen |
| 90 | + # VERSION is BRANCH here for now |
| 91 | + TASK_ARGS=("$VERSION" "$codegen_folder") |
| 92 | + ;; |
| 93 | + bump) |
| 94 | + if [ -v $VERSION ]; then |
| 95 | + echo -e "\033[31;1mTARGET: bump -> missing version parameter\033[0m" |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + echo -e "\033[36;1mTARGET: bump to version $VERSION\033[0m" |
| 99 | + TASK=bump |
| 100 | + # VERSION is BRANCH here for now |
| 101 | + TASK_ARGS=("$VERSION") |
| 102 | + ;; |
| 103 | + *) |
| 104 | + echo -e "\nUsage:\n\t $CMD is not supported right now\n" |
| 105 | + exit 1 |
| 106 | +esac |
| 107 | + |
| 108 | + |
| 109 | +# ------------------------------------------------------- # |
| 110 | +# Build Container |
| 111 | +# ------------------------------------------------------- # |
| 112 | + |
| 113 | +echo -e "\033[34;1mINFO: building $product container\033[0m" |
| 114 | + |
| 115 | +docker build \ |
| 116 | + --build-arg BUILDER_UID="$(id -u)" \ |
| 117 | + --file $repo/.buildkite/Dockerfile \ |
| 118 | + --tag ${product} \ |
| 119 | + . |
| 120 | + |
| 121 | +# ------------------------------------------------------- # |
| 122 | +# Run the Container |
| 123 | +# ------------------------------------------------------- # |
| 124 | + |
| 125 | +echo -e "\033[34;1mINFO: running $product container\033[0m" |
| 126 | + |
| 127 | +if [[ "$CMD" == "assemble" ]]; then |
| 128 | + |
| 129 | + # Build dists into .github/output |
| 130 | + docker run \ |
| 131 | + -u "$(id -u)" \ |
| 132 | + --rm -v $repo/.github/output:/code/elasticsearch-py/dist \ |
| 133 | + $product \ |
| 134 | + /bin/bash -c "pip install build; python /code/elasticsearch-py/utils/build-dists.py $VERSION" |
| 135 | + |
| 136 | + # Verify that there are dists in .github/output |
| 137 | + if compgen -G ".github/output/*" > /dev/null; then |
| 138 | + |
| 139 | + # Tarball everything up in .github/output |
| 140 | + if [[ "$WORKFLOW" == 'snapshot' ]]; then |
| 141 | + cd $repo/.github/output && tar -czvf elasticsearch-py-$VERSION-SNAPSHOT.tar.gz * && cd - |
| 142 | + else |
| 143 | + cd $repo/.github/output && tar -czvf elasticsearch-py-$VERSION.tar.gz * && cd - |
| 144 | + fi |
| 145 | + |
| 146 | + echo -e "\033[32;1mTARGET: successfully assembled client v$VERSION\033[0m" |
| 147 | + exit 0 |
| 148 | + else |
| 149 | + echo -e "\033[31;1mTARGET: assemble failed, empty workspace!\033[0m" |
| 150 | + exit 1 |
| 151 | + fi |
| 152 | +fi |
| 153 | + |
| 154 | +if [[ "$CMD" == "bump" ]]; then |
| 155 | + docker run \ |
| 156 | + --rm -v $repo:/code/elasticsearch-py \ |
| 157 | + $product \ |
| 158 | + /bin/bash -c "python /code/elasticsearch-py/utils/bump-version.py $VERSION" |
| 159 | + |
| 160 | + exit 0 |
| 161 | +fi |
| 162 | + |
| 163 | +if [[ "$CMD" == "codegen" ]]; then |
| 164 | + docker run \ |
| 165 | + --rm -v $repo:/code/elasticsearch-py \ |
| 166 | + $product \ |
| 167 | + /bin/bash -c "cd /code && python -m pip install nox && \ |
| 168 | + git clone https://$CLIENTS_GITHUB_TOKEN@github.com/elastic/elastic-client-generator-python.git && \ |
| 169 | + cd /code/elastic-client-generator-python && GIT_BRANCH=$VERSION python -m nox -s generate-es && \ |
| 170 | + cd /code/elasticsearch-py && python -m nox -s format" |
| 171 | + |
| 172 | + exit 0 |
| 173 | +fi |
| 174 | + |
| 175 | +if [[ "$CMD" == "docsgen" ]]; then |
| 176 | + echo "TODO" |
| 177 | +fi |
| 178 | + |
| 179 | +if [[ "$CMD" == "examplesgen" ]]; then |
| 180 | + echo "TODO" |
| 181 | +fi |
| 182 | + |
| 183 | +echo "Must be called with '.github/make.sh [command]" |
| 184 | +exit 1 |
0 commit comments