|
| 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: ./.ci/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 | +NODE_JS_VERSION=16 |
| 37 | +WORKFLOW=${WORKFLOW-staging} |
| 38 | +set -euo pipefail |
| 39 | + |
| 40 | +product="elastic/elasticsearch-js" |
| 41 | +output_folder=".ci/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 -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 | + 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") |
| 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 \ |
| 119 | + --file .ci/Dockerfile \ |
| 120 | + --tag ${product} \ |
| 121 | + --build-arg NODE_JS_VERSION=${NODE_JS_VERSION} \ |
| 122 | + --build-arg USER_ID="$(id -u)" \ |
| 123 | + --build-arg GROUP_ID="$(id -g)" \ |
| 124 | + . |
| 125 | + |
| 126 | +# ------------------------------------------------------- # |
| 127 | +# Run the Container |
| 128 | +# ------------------------------------------------------- # |
| 129 | + |
| 130 | +echo -e "\033[34;1mINFO: running $product container\033[0m" |
| 131 | + |
| 132 | +docker run \ |
| 133 | + --volume $repo:/usr/src/app \ |
| 134 | + --volume /usr/src/app/node_modules \ |
| 135 | + --env "WORKFLOW=${WORKFLOW}" \ |
| 136 | + --name make-elasticsearch-js \ |
| 137 | + --rm \ |
| 138 | + $product \ |
| 139 | + node .ci/make.mjs --task $TASK ${TASK_ARGS[*]} |
| 140 | + |
| 141 | +# ------------------------------------------------------- # |
| 142 | +# Post Command tasks & checks |
| 143 | +# ------------------------------------------------------- # |
| 144 | + |
| 145 | +if [[ "$CMD" == "assemble" ]]; then |
| 146 | + if compgen -G ".ci/output/*" > /dev/null; then |
| 147 | + echo -e "\033[32;1mTARGET: successfully assembled client v$VERSION\033[0m" |
| 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 | + if [ -n "$(git status --porcelain)" ]; then |
| 156 | + echo -e "\033[32;1mTARGET: successfully bumped client v$VERSION\033[0m" |
| 157 | + else |
| 158 | + echo -e "\033[31;1mTARGET: failed bumped client v$VERSION\033[0m" |
| 159 | + exit 1 |
| 160 | + fi |
| 161 | +fi |
| 162 | + |
| 163 | +if [[ "$CMD" == "codegen" ]]; then |
| 164 | + if [ -n "$(git status --porcelain)" ]; then |
| 165 | + echo -e "\033[32;1mTARGET: successfully generated client v$VERSION\033[0m" |
| 166 | + else |
| 167 | + echo -e "\033[31;1mTARGET: failed generating client v$VERSION\033[0m" |
| 168 | + exit 1 |
| 169 | + fi |
| 170 | +fi |
| 171 | + |
| 172 | +if [[ "$CMD" == "docsgen" ]]; then |
| 173 | + echo "TODO" |
| 174 | +fi |
| 175 | + |
| 176 | +if [[ "$CMD" == "examplesgen" ]]; then |
| 177 | + echo "TODO" |
| 178 | +fi |
0 commit comments