Skip to content

Commit

Permalink
chore(tooling): clients scripts and Docker image (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Dec 17, 2021
1 parent 997737d commit c7fbbab
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 58 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.github
.git
.vscode
**/dist
**/build
**/node_modules
playground
2 changes: 1 addition & 1 deletion .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ runs:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}

- name: Restore maven dependencies.
- name: Restore maven dependencies
uses: actions/cache@v2
with:
path: '~/.m2/repository'
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ jobs:
uses: ./.github/actions/cache

- name: Checking search specs
run: yarn specs search
run: yarn build:specs search

- name: Checking recommend specs
run: yarn specs recommend
run: yarn build:specs recommend

- name: Checking personalization specs
run: yarn specs personalization
run: yarn build:specs personalization

- name: Checking analytics specs
run: yarn specs analytics
run: yarn build:specs analytics

- name: Lint
run: yamllint specs
Expand All @@ -52,25 +52,25 @@ jobs:
run: yarn generate javascript search

- name: Build search client
run: yarn client:build-js:search
run: yarn build:clients javascript search

- name: Generate recommend client
run: yarn generate javascript recommend

- name: Build recommend client
run: yarn client:build-js:recommend
run: yarn build:clients javascript recommend

- name: Generate personalization client
run: yarn generate javascript personalization

- name: Build personalization client
run: yarn client:build-js:personalization
run: yarn build:clients javascript personalization

- name: Generate analytics client
run: yarn generate javascript analytics

- name: Build analytics client
run: yarn client:build-js:analytics
run: yarn build:clients javascript analytics

- name: Lint
run: yarn lint
Expand All @@ -88,7 +88,7 @@ jobs:
run: yarn generate java search

- name: Build search client
run: yarn client:build-java
run: yarn build:clients java search

cts:
runs-on: ubuntu-20.04
Expand All @@ -103,7 +103,7 @@ jobs:
run: yarn generate

- name: Build client
run: yarn client:build
run: yarn build:clients

- name: Generate CTS
run: yarn cts:generate
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ARG NODE_VERSION=16.13.0

FROM node:$NODE_VERSION-alpine

ENV DOCKER=true

RUN apk add openjdk11 maven jq bash yamllint perl curl

WORKDIR /app

COPY package.json yarn.lock .yarnrc.yml ./
COPY clients/ ./clients/
COPY .yarn .yarn
RUN yarn install

RUN mkdir dist
RUN curl -L "https://github.com/google/google-java-format/releases/download/v1.13.0/google-java-format-1.13.0-all-deps.jar" > dist/google-java-format-1.13.0-all-deps.jar

COPY . .

CMD ["bash"]
72 changes: 57 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,93 @@
# How to run
# api-clients-automation

## Install and setup env
**Make sure to have Docker installed so you don't have to install the tooling for every API clients.**

## Setup repository tooling

```bash
nvm use && yarn
```

## Generate clients based on the [`specs`](./specs/)
## Setup dev environment

### All clients
You can also execute docker commands one by one, see [Docker commands](#docker)

```bash
yarn generate
yarn docker:setup
```

Generic command:
### Docker

#### Build

Build docker image from [Dockerfile](./Dockerfile)

```bash
yarn generate <language | all> <client | all>
yarn docker:build
```

### Search client
#### Mount

Mount docker image on `dev` container

```bash
yarn generate all search
yarn docker:mount
```

### Recommend client
#### Clean

Stops `dev` container and clean the built image

```bash
yarn generate all recommend
yarn docker:clean
```

## Build generated clients
## Contributing

You can now make changes locally and run commands through the docker container.

### Generate clients based on the [`specs`](./specs/)

#### Usage

```bash
yarn docker generate <language | all> <client | all>
```

#### Generate all clients

```bash
yarn client:build
yarn docker generate
```

# Testing clients
### Generate specific client for specific language

#### Usage

```bash
yarn docker build:clients <language | all> <client | all>
```

### Build specific client for specific language

```bash
yarn docker build:clients java recommend
```

## Testing clients

The clients can be tested inside the [`playground`](./playground) folder

## Usage

```bash
yarn docker playground:<language>:<client>
```

## JavaScript

```bash
yarn playground:js
yarn docker playground:js:search
```

# Troubleshooting
Expand Down
12 changes: 7 additions & 5 deletions openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"modelPropertyNaming": "original",
"supportsES6": true,
"npmName": "@algolia/client-search",
"packageName": "@algolia/client-search",
"npmVersion": "5.0.0",

"packageName": "@algolia/client-search",
"isSearchHost": true
}
},
Expand All @@ -39,9 +39,9 @@
"modelPropertyNaming": "original",
"supportsES6": true,
"npmName": "@algolia/recommend",
"packageName": "@algolia/recommend",
"npmVersion": "5.0.0",

"packageName": "@algolia/recommend",
"isSearchHost": true
}
},
Expand All @@ -59,9 +59,9 @@
"modelPropertyNaming": "original",
"supportsES6": true,
"npmName": "@algolia/client-personalization",
"packageName": "@algolia/client-personalization",
"npmVersion": "5.0.0",

"packageName": "@algolia/client-personalization",
"hasRegionalHost": true,
"isPersonalizationHost": true
}
Expand All @@ -80,9 +80,9 @@
"modelPropertyNaming": "original",
"supportsES6": true,
"npmName": "@algolia/client-analytics",
"packageName": "@algolia/client-analytics",
"npmVersion": "5.0.0",

"packageName": "@algolia/client-analytics",
"hasRegionalHost": true,
"isAnalyticsHost": true
}
Expand All @@ -105,7 +105,9 @@
"additionalProperties": {
"sourceFolder": "algoliasearch-core",
"java8": true,
"dateLibrary": "java8"
"dateLibrary": "java8",

"packageName": "algoliasearch-client-java-2"
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
"tests/"
],
"scripts": {
"build:clients": "./scripts/multiplexer.sh ./scripts/build/clients.sh ${0:-all} ${1:-all}",
"build:specs": "./scripts/build/specs.sh ${0:-all} ${1:-yaml}",
"build": "yarn build:specs && yarn build:clients",
"clean": "rm -rf **/dist **/build **/node_modules",
"client:build-java": "mvn clean install -f clients/algoliasearch-client-java-2/pom.xml",
"client:build-js:analytics": "yarn workspace @algolia/client-analytics build",
"client:build-js:personalization": "yarn workspace @algolia/client-personalization build",
"client:build-js:recommend": "yarn workspace @algolia/recommend build",
"client:build-js:search": "yarn workspace @algolia/client-search build",
"client:build-js": "yarn client:build-js:search && yarn client:build-js:recommend && yarn client:build-js:personalization && yarn client:build-js:analytics",
"client:build": "yarn client:build-js",
"cts:generate": "yarn workspace tests cts:generate",
"cts:test": "yarn workspace tests test",
"docker:build": "./scripts/docker/build.sh",
"docker:clean": "docker stop dev; docker rm -f dev; docker image rm -f api-clients-automation",
"docker:mount": "./scripts/docker/mount.sh",
"docker:setup": "yarn docker:clean && yarn docker:build && yarn docker:mount",
"docker": "docker exec dev yarn $*",
"lint": "eslint --ext=ts .",
"post:generate": "./scripts/post-gen/global.sh",
"generate": "./scripts/multiplexer.sh ./scripts/generate.sh ${0:-all} ${1:-all} && yarn post:generate",
Expand All @@ -25,8 +26,7 @@
"playground:js:personalization": "yarn workspace javascript-playground start:personalization",
"playground:js:recommend": "yarn workspace javascript-playground start:recommend",
"playground:js:search": "yarn workspace javascript-playground start:search",
"specs:format": "yarn prettier --write specs",
"specs": "./scripts/specs.sh ${0:-all} ${1:-yaml}"
"specs:format": "yarn prettier --write specs"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "2.4.18",
Expand Down
42 changes: 42 additions & 0 deletions scripts/build/clients.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Break on non-zero code
set -e

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
# Move to the root (easier to locate other scripts)
cd ${DIR}/../..

lang=$1
client=$2
generator="$lang-$client"
package=$(cat openapitools.json | jq -r --arg generator "$generator" '."generator-cli".generators[$generator].additionalProperties.packageName')

# Commands are based on the lang
build_client(){
echo "> Building $generator..."

if [[ $lang == 'javascript' ]]; then
yarn workspace $package build
elif [[ $lang == 'java' ]]; then
set +e

log=$(mvn clean install -f clients/$package/pom.xml)

if [[ $? != 0 ]]; then
echo "$log"
exit 1
fi

set -e
fi
}



if [[ -z $package ]]; then
echo "Unknown package ${package}"
exit 1
fi

build_client
8 changes: 7 additions & 1 deletion scripts/specs.sh → scripts/build/specs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

if [[ ! $CI ]] && [[ ! $DOCKER ]]; then
echo "You should run scripts via the docker container, see README.md"

exit 1
fi

# Break on non-zero code
set -e

Expand All @@ -10,7 +16,7 @@ SPECS=()

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
# Move to the root (easier to locate other scripts)
cd ${DIR}/..
cd ${DIR}/../..

find_specs() {
echo "> Searching for available specs..."
Expand Down
9 changes: 9 additions & 0 deletions scripts/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)/../.."

cd $ROOT

NODE_VERSION=$(cat .nvmrc)

docker build --build-arg NODE_VERSION=$NODE_VERSION -t api-clients-automation .
5 changes: 5 additions & 0 deletions scripts/docker/mount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)/../.."

docker run -d -it --name dev --mount type=bind,source=$ROOT/,target=/app api-clients-automation
Loading

0 comments on commit c7fbbab

Please sign in to comment.