Skip to content

Set up repo to support automated codegen #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
ARG NODE_JS_VERSION=18
ARG NODE_JS_VERSION=20
FROM node:${NODE_JS_VERSION}

# Create app directory
WORKDIR /usr/src/app
# install zip util
RUN apt-get clean -y && \
apt-get update -y && \
apt-get install -y zip

RUN apt-get clean -y
RUN apt-get update -y
RUN apt-get install -y zip
# Set user permissions and directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./
Expand Down
37 changes: 23 additions & 14 deletions .ci/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# assemble <VERSION> : build client artifacts with version
# bump <VERSION> : bump client internals to version
# bumpmatrix <VERSION> : bump stack version in test matrix to version
# codegen : generate endpoints
# codegen <VERSION> : generate endpoints
# docsgen <VERSION> : generate documentation
# examplegen : generate the doc examples
# clean : clean workspace
Expand All @@ -24,7 +24,6 @@
# ------------------------------------------------------- #
script_path=$(dirname "$(realpath -s "$0")")
repo=$(realpath "$script_path/../")
generator=$(realpath "$script_path/../../elastic-client-generator-js")

# shellcheck disable=SC1090
CMD=$1
Expand All @@ -38,7 +37,6 @@ product="elastic/elasticsearch-js"
output_folder=".ci/output"
codegen_folder=".ci/output"
OUTPUT_DIR="$repo/${output_folder}"
# REPO_BINDING="${OUTPUT_DIR}:/sln/${output_folder}"
NODE_JS_VERSION=18
WORKFLOW=${WORKFLOW-staging}
mkdir -p "$OUTPUT_DIR"
Expand All @@ -59,18 +57,29 @@ case $CMD in
echo -e "\033[31;1mTARGET: assemble -> missing version parameter\033[0m"
exit 1
fi
echo -e "\033[36;1mTARGET: assemble artefact $VERSION\033[0m"
echo -e "\033[36;1mTARGET: assemble artifact $VERSION\033[0m"
TASK=release
TASK_ARGS=("$VERSION" "$output_folder")
;;
codegen)
if [ -v $VERSION ]; then
echo -e "\033[31;1mTARGET: codegen -> missing version parameter\033[0m"
exit 1
if [ -v "$VERSION" ] || [[ -z "$VERSION" ]]; then
# fall back to branch name or `main` if no VERSION is set
branch_name=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch_name" =~ ^[0-9]+\.[0-9]+ ]]; then
echo -e "\033[36;1mTARGET: codegen -> No VERSION argument found, using branch name: \`$branch_name\`\033[0m"
VERSION="$branch_name"
else
echo -e "\033[36;1mTARGET: codegen -> No VERSION argument found, using \`main\`\033[0m"
VERSION="main"
fi
fi
echo -e "\033[36;1mTARGET: codegen API v$VERSION\033[0m"
if [ "$VERSION" = 'main' ]; then
echo -e "\033[36;1mTARGET: codegen API $VERSION\033[0m"
else
echo -e "\033[36;1mTARGET: codegen API v$VERSION\033[0m"
fi

TASK=codegen
# VERSION is BRANCH here for now
TASK_ARGS=("$VERSION")
;;
docsgen)
Expand All @@ -80,13 +89,11 @@ case $CMD in
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)
Expand All @@ -96,7 +103,6 @@ case $CMD in
fi
echo -e "\033[36;1mTARGET: bump to version $VERSION\033[0m"
TASK=bump
# VERSION is BRANCH here for now
TASK_ARGS=("$VERSION")
;;
bumpmatrix)
Expand Down Expand Up @@ -138,14 +144,17 @@ echo -e "\033[34;1mINFO: running $product container\033[0m"

docker run \
--volume "$repo:/usr/src/app" \
--volume "$generator:/usr/src/elastic-client-generator-js" \
--volume /usr/src/app/node_modules \
-u "$(id -u):$(id -g)" \
--env "WORKFLOW=$WORKFLOW" \
--name make-elasticsearch-js \
--rm \
$product \
node .ci/make.mjs --task $TASK ${TASK_ARGS[*]}
/bin/bash -c "cd /usr/src && \
git clone https://[email protected]/elastic/elastic-client-generator-js.git && \
mkdir -p /usr/src/elastic-client-generator-js/output && \
cd /usr/src/app && \
node .ci/make.mjs --task $TASK ${TASK_ARGS[*]}"

# ------------------------------------------------------- #
# Post Command tasks & checks
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elasticsearch-serverless",
"private": true,
"version": "0.1.0",
"version": "0.1.0+20231031",
"description": "The official Node.js Elastic client for the Elasticsearch Serverless service.",
"main": "index.js",
"types": "index.d.ts",
Expand Down