Skip to content

Commit f8c0a3e

Browse files
delvedorJoshMock
authored andcommitted
Add make.sh for v7 (#1701)
1 parent b4b43cc commit f8c0a3e

File tree

5 files changed

+290
-3
lines changed

5 files changed

+290
-3
lines changed

.ci/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG NODE_JS_VERSION=10
1+
ARG NODE_JS_VERSION=16
22
FROM node:${NODE_JS_VERSION}
33

44
# Create app directory

.ci/make.mjs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/* global $ argv */
21+
22+
'use strict'
23+
24+
import 'zx/globals'
25+
26+
import { readFile, writeFile } from 'fs/promises'
27+
import assert from 'assert'
28+
import { join } from 'desm'
29+
import semver from 'semver'
30+
31+
assert(typeof argv.task === 'string', 'Missing task parameter')
32+
33+
switch (argv.task) {
34+
case 'release':
35+
release(argv._).catch(onError)
36+
break
37+
case 'bump':
38+
bump(argv._).catch(onError)
39+
break
40+
case 'codegen':
41+
codegen(argv._).catch(onError)
42+
break
43+
default:
44+
console.log(`Unknown task: ${argv.task}`)
45+
process.exit(1)
46+
}
47+
48+
async function release (args) {
49+
assert(args.length === 2, 'Release task expects two parameters')
50+
let [version, outputFolder] = args
51+
52+
if (process.env.WORKFLOW === 'snapshot' && !version.endsWith('SNAPSHOT')) {
53+
version = `${version}-SNAPSHOT`
54+
}
55+
56+
await bump([version])
57+
58+
const packageJson = JSON.parse(await readFile(
59+
join(import.meta.url, '..', 'package.json'),
60+
'utf8'
61+
))
62+
63+
await $`npm pack`
64+
await $`zip elasticsearch-js-${version}.zip elastic-elasticsearch-${packageJson.version}.tgz`
65+
await $`rm elastic-elasticsearch-${packageJson.version}.tgz`
66+
await $`mv ${join(import.meta.url, '..', `elasticsearch-js-${version}.zip`)} ${join(import.meta.url, '..', outputFolder, `elasticsearch-js-${version}.zip`)}`
67+
}
68+
69+
async function bump (args) {
70+
assert(args.length === 1, 'Bump task expects one parameter')
71+
const [version] = args
72+
const packageJson = JSON.parse(await readFile(
73+
join(import.meta.url, '..', 'package.json'),
74+
'utf8'
75+
))
76+
77+
const cleanVersion = semver.clean(version.includes('SNAPSHOT') ? version.split('-')[0] : version)
78+
assert(semver.valid(cleanVersion))
79+
packageJson.version = cleanVersion
80+
packageJson.versionCanary = `${cleanVersion}-canary.0`
81+
82+
await writeFile(
83+
join(import.meta.url, '..', 'package.json'),
84+
JSON.stringify(packageJson, null, 2),
85+
'utf8'
86+
)
87+
88+
const testMatrix = await readFile(join(import.meta.url, 'test-matrix.yml'), 'utf8')
89+
await writeFile(
90+
join(import.meta.url, 'test-matrix.yml'),
91+
testMatrix.replace(/STACK_VERSION:\s+\- "[0-9]+[0-9\.]*[0-9](?:\-SNAPSHOT)?"/, `STACK_VERSION:\n - "${cleanVersion}-SNAPSHOT"`), // eslint-disable-line
92+
'utf8'
93+
)
94+
}
95+
96+
// this command can only be executed locally for now
97+
async function codegen (args) {
98+
assert(args.length === 1, 'Bump task expects one parameter')
99+
const [version] = args
100+
101+
await $`node scripts/generate --version ${version}`
102+
}
103+
104+
function onError (err) {
105+
console.log(err)
106+
process.exit(1)
107+
}

.ci/make.sh

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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

.ci/test-matrix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
STACK_VERSION:
3-
- 7.16-SNAPSHOT
3+
- "7.17.4-SNAPSHOT"
44

55
NODE_JS_VERSION:
66
- 16

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"cross-zip": "^4.0.0",
5555
"dedent": "^0.7.0",
5656
"deepmerge": "^4.2.2",
57+
"desm": "^1.2.0",
5758
"dezalgo": "^1.0.3",
5859
"fast-deep-equal": "^3.1.3",
5960
"into-stream": "^6.0.0",
@@ -74,7 +75,8 @@
7475
"tap": "^15.0.9",
7576
"tsd": "^0.15.1",
7677
"workq": "^3.0.0",
77-
"xmlbuilder2": "^2.4.1"
78+
"xmlbuilder2": "^2.4.1",
79+
"zx": "^6.1.0"
7880
},
7981
"dependencies": {
8082
"debug": "^4.3.1",

0 commit comments

Comments
 (0)