|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Licensed to Elasticsearch B.V. under one or more contributor |
| 4 | +# license agreements. See the NOTICE file distributed with |
| 5 | +# this work for additional information regarding copyright |
| 6 | +# ownership. Elasticsearch B.V. licenses this file to you under |
| 7 | +# the Apache License, Version 2.0 (the "License"); you may |
| 8 | +# not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | +# |
| 20 | + |
| 21 | +# ------------------------------------------------------- # |
| 22 | +# |
| 23 | +# Skeleton for common build entry script for all elastic |
| 24 | +# clients. Needs to be adapted to individual client usage. |
| 25 | +# |
| 26 | +# Must be called: ./.ci/make.sh <target> <params> |
| 27 | +# |
| 28 | +# Version: 1.1.0 |
| 29 | +# |
| 30 | +# Targets: |
| 31 | +# --------------------------- |
| 32 | +# assemble <VERSION> : build client artefacts with version |
| 33 | +# bump <VERSION> : bump client internals to version |
| 34 | +# codegen <VERSION> : generate endpoints |
| 35 | +# docsgen <VERSION> : generate documentation |
| 36 | +# examplegen : generate the doc examples |
| 37 | +# clean : clean workspace |
| 38 | +# |
| 39 | +# ------------------------------------------------------- # |
| 40 | + |
| 41 | +# ------------------------------------------------------- # |
| 42 | +# Bootstrap |
| 43 | +# ------------------------------------------------------- # |
| 44 | + |
| 45 | +set -euo pipefail |
| 46 | + |
| 47 | +script_path=$(dirname "$(realpath "$0")") |
| 48 | +repo=$(realpath "$script_path/../") |
| 49 | + |
| 50 | +# shellcheck disable=SC1090 |
| 51 | +CMD=$1 |
| 52 | +TASK=$1 |
| 53 | +TASK_ARGS=() |
| 54 | +VERSION=$2 |
| 55 | +STACK_VERSION=$VERSION |
| 56 | + |
| 57 | +product="elastic/elasticsearch-java" |
| 58 | +output_folder=".ci/output" |
| 59 | +codegen_folder=".ci/output" |
| 60 | +OUTPUT_DIR="$repo/${output_folder}" |
| 61 | +WORKFLOW="${WORKFLOW-staging}" |
| 62 | +mkdir -p "$OUTPUT_DIR" |
| 63 | + |
| 64 | +echo -e "\033[34;1mINFO:\033[0m PRODUCT ${product}\033[0m" |
| 65 | +echo -e "\033[34;1mINFO:\033[0m VERSION ${STACK_VERSION}\033[0m" |
| 66 | +echo -e "\033[34;1mINFO:\033[0m OUTPUT_DIR ${OUTPUT_DIR}\033[0m" |
| 67 | + |
| 68 | +# ------------------------------------------------------- # |
| 69 | +# Parse Command |
| 70 | +# ------------------------------------------------------- # |
| 71 | + |
| 72 | +case $CMD in |
| 73 | + clean) |
| 74 | + echo -e "\033[36;1mTARGET: clean workspace $output_folder\033[0m" |
| 75 | + rm -rf "$output_folder" |
| 76 | + echo -e "\033[32;1mdone.\033[0m" |
| 77 | + exit 0 |
| 78 | + ;; |
| 79 | + assemble) |
| 80 | + if [ -z "$VERSION" ]; then |
| 81 | + echo -e "\033[31;1mTARGET: assemble -> missing version parameter\033[0m" |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | + echo -e "\033[36;1mTARGET: assemble artefact $VERSION\033[0m" |
| 85 | + TASK=assemble |
| 86 | + TASK_ARGS=("$VERSION" "$output_folder") |
| 87 | + ;; |
| 88 | + release) |
| 89 | + if [ -z "$VERSION" ]; then |
| 90 | + echo -e "\033[31;1mTARGET: release -> missing version parameter\033[0m" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + echo -e "\033[36;1mTARGET: release artefact $VERSION\033[0m" |
| 94 | + TASK=release |
| 95 | + TASK_ARGS=("$VERSION" "$output_folder") |
| 96 | + ;; |
| 97 | + codegen) |
| 98 | + if [ -v "$VERSION" ]; then |
| 99 | + echo -e "\033[31;1mTARGET: codegen -> missing version parameter\033[0m" |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | + echo -e "\033[36;1mTARGET: codegen API v$VERSION\033[0m" |
| 103 | + TASK=codegen |
| 104 | + # VERSION is BRANCH here for now |
| 105 | + TASK_ARGS=("$VERSION" "$codegen_folder") |
| 106 | + ;; |
| 107 | + docsgen) |
| 108 | + if [ -v "$VERSION" ]; then |
| 109 | + echo -e "\033[31;1mTARGET: docsgen -> missing version parameter\033[0m" |
| 110 | + exit 1 |
| 111 | + fi |
| 112 | + echo -e "\033[36;1mTARGET: generate docs for $VERSION\033[0m" |
| 113 | + TASK=codegen |
| 114 | + # VERSION is BRANCH here for now |
| 115 | + TASK_ARGS=("$VERSION" "$codegen_folder") |
| 116 | + ;; |
| 117 | + examplesgen) |
| 118 | + echo -e "\033[36;1mTARGET: generate examples\033[0m" |
| 119 | + TASK=codegen |
| 120 | + # VERSION is BRANCH here for now |
| 121 | + TASK_ARGS=("$VERSION" "$codegen_folder") |
| 122 | + ;; |
| 123 | + bump) |
| 124 | + if [ -z "$VERSION" ]; then |
| 125 | + echo -e "\033[31;1mTARGET: bump -> missing version parameter\033[0m" |
| 126 | + exit 1 |
| 127 | + fi |
| 128 | + echo -e "\033[36;1mTARGET: bump to version $VERSION\033[0m" |
| 129 | + TASK=bump |
| 130 | + # VERSION is BRANCH here for now |
| 131 | + TASK_ARGS=("$VERSION") |
| 132 | + ;; |
| 133 | + *) |
| 134 | + echo -e "\nUsage:\n\t $CMD is not supported right now\n" |
| 135 | + exit 1 |
| 136 | +esac |
| 137 | + |
| 138 | + |
| 139 | +# ------------------------------------------------------- # |
| 140 | +# Build Container |
| 141 | +# ------------------------------------------------------- # |
| 142 | + |
| 143 | +docker_image=${product}-build-$(echo "$VERSION" | tr '[:upper:]' '[:lower:]') |
| 144 | +git_mount="-v $repo/.git:/elasticsearch-java/.git:ro" |
| 145 | +src_mount="-v $repo/java-client/src:/elasticsearch-java/java-client/src:ro" |
| 146 | +output_mount="-v $repo/.ci/output:/elasticsearch-java/build" |
| 147 | + |
| 148 | +build_image() { |
| 149 | + echo -e "\033[34;1mINFO: building $product container\033[0m" |
| 150 | + |
| 151 | + docker build \ |
| 152 | + --file .ci/Dockerfile \ |
| 153 | + --tag $docker_image \ |
| 154 | + --build-arg BUILDER_UID="$(id -u)" \ |
| 155 | + --build-arg BUILDER_GID="$(id -g)" . |
| 156 | +} |
| 157 | + |
| 158 | +# ------------------------------------------------------- # |
| 159 | +# Post Command tasks & checks |
| 160 | +# ------------------------------------------------------- # |
| 161 | + |
| 162 | +if [[ "$CMD" == "assemble" ]]; then |
| 163 | + rm -rf .ci/output/repository |
| 164 | + |
| 165 | + if [[ "$WORKFLOW" == 'snapshot' ]]; then |
| 166 | + assemble_version="$VERSION-SNAPSHOT" |
| 167 | + else |
| 168 | + assemble_version="$VERSION" |
| 169 | + fi |
| 170 | + |
| 171 | + build_image |
| 172 | + echo -e "\033[34;1mINFO:\033[0m Building version ${assemble_version}\033[0m" |
| 173 | + docker run --rm --env VERSION=$assemble_version -u "$(id -u)" \ |
| 174 | + $git_mount $src_mount $output_mount \ |
| 175 | + $docker_image \ |
| 176 | + publishForReleaseManager |
| 177 | + |
| 178 | + if compgen -G ".ci/output/release/*" > /dev/null; then |
| 179 | + if [[ -n ${DEPENDENCIES_REPORTS_DIR+x} ]]; then |
| 180 | + cp .ci/output/release/dependencies.csv "$DEPENDENCIES_REPORTS_DIR"/"$DEPENDENCIES_REPORT" |
| 181 | + fi |
| 182 | + echo -e "\033[32;1mTARGET: successfully assembled client version $assemble_version\033[0m" |
| 183 | + else |
| 184 | + echo -e "\033[31;1mTARGET: assemble failed, empty workspace!\033[0m" |
| 185 | + exit 1 |
| 186 | + fi |
| 187 | +fi |
| 188 | + |
| 189 | +if [[ "$CMD" == "release" ]]; then |
| 190 | + rm -rf .ci/output/repository |
| 191 | + rm -rf signed-artifacts |
| 192 | + build_image |
| 193 | + echo -e "\033[34;1mINFO:\033[0m Building version ${VERSION}\033[0m" |
| 194 | + |
| 195 | + if [[ "$DRY_RUN" = "true" ]]; then |
| 196 | + echo "Dry run: building and publishing to the local repository" |
| 197 | + gradle_task="publishForReleaseManager" |
| 198 | + else |
| 199 | + echo "Releasing to Maven repo" |
| 200 | + gradle_task="publishForMavenCentral" |
| 201 | + fi |
| 202 | + docker run --rm --env VERSION=$VERSION -u "$(id -u)" \ |
| 203 | + $git_mount $src_mount $output_mount \ |
| 204 | + -v /tmp/secured:/tmp/secured \ |
| 205 | + $docker_image \ |
| 206 | + $gradle_task |
| 207 | + |
| 208 | + mkdir -p signed-artifacts/$VERSION |
| 209 | + cp .ci/output/repository/co/elastic/clients/elasticsearch-java/$VERSION/elasticsearch-java-${VERSION}-javadoc.jar signed-artifacts/$VERSION/elasticsearch-java-${VERSION}-javadoc.jar |
| 210 | +fi |
| 211 | + |
| 212 | +if [[ "$CMD" == "bump" ]]; then |
| 213 | + echo $VERSION > config/version.txt |
| 214 | +fi |
| 215 | + |
| 216 | +if [[ "$CMD" == "codegen" ]]; then |
| 217 | + echo "TODO" |
| 218 | +fi |
| 219 | + |
| 220 | +if [[ "$CMD" == "docsgen" ]]; then |
| 221 | + echo "TODO" |
| 222 | +fi |
| 223 | + |
| 224 | +if [[ "$CMD" == "examplesgen" ]]; then |
| 225 | + echo "TODO" |
| 226 | +fi |
0 commit comments