Skip to content

Commit c7fbbab

Browse files
authored
chore(tooling): clients scripts and Docker image (#43)
1 parent 997737d commit c7fbbab

File tree

16 files changed

+227
-58
lines changed

16 files changed

+227
-58
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.github
2+
.git
3+
.vscode
4+
**/dist
5+
**/build
6+
**/node_modules
7+
playground

.github/actions/cache/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ runs:
2323
path: '**/node_modules'
2424
key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
2525

26-
- name: Restore maven dependencies.
26+
- name: Restore maven dependencies
2727
uses: actions/cache@v2
2828
with:
2929
path: '~/.m2/repository'

.github/workflows/check.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ jobs:
2525
uses: ./.github/actions/cache
2626

2727
- name: Checking search specs
28-
run: yarn specs search
28+
run: yarn build:specs search
2929

3030
- name: Checking recommend specs
31-
run: yarn specs recommend
31+
run: yarn build:specs recommend
3232

3333
- name: Checking personalization specs
34-
run: yarn specs personalization
34+
run: yarn build:specs personalization
3535

3636
- name: Checking analytics specs
37-
run: yarn specs analytics
37+
run: yarn build:specs analytics
3838

3939
- name: Lint
4040
run: yamllint specs
@@ -52,25 +52,25 @@ jobs:
5252
run: yarn generate javascript search
5353

5454
- name: Build search client
55-
run: yarn client:build-js:search
55+
run: yarn build:clients javascript search
5656

5757
- name: Generate recommend client
5858
run: yarn generate javascript recommend
5959

6060
- name: Build recommend client
61-
run: yarn client:build-js:recommend
61+
run: yarn build:clients javascript recommend
6262

6363
- name: Generate personalization client
6464
run: yarn generate javascript personalization
6565

6666
- name: Build personalization client
67-
run: yarn client:build-js:personalization
67+
run: yarn build:clients javascript personalization
6868

6969
- name: Generate analytics client
7070
run: yarn generate javascript analytics
7171

7272
- name: Build analytics client
73-
run: yarn client:build-js:analytics
73+
run: yarn build:clients javascript analytics
7474

7575
- name: Lint
7676
run: yarn lint
@@ -88,7 +88,7 @@ jobs:
8888
run: yarn generate java search
8989

9090
- name: Build search client
91-
run: yarn client:build-java
91+
run: yarn build:clients java search
9292

9393
cts:
9494
runs-on: ubuntu-20.04
@@ -103,7 +103,7 @@ jobs:
103103
run: yarn generate
104104

105105
- name: Build client
106-
run: yarn client:build
106+
run: yarn build:clients
107107

108108
- name: Generate CTS
109109
run: yarn cts:generate

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ARG NODE_VERSION=16.13.0
2+
3+
FROM node:$NODE_VERSION-alpine
4+
5+
ENV DOCKER=true
6+
7+
RUN apk add openjdk11 maven jq bash yamllint perl curl
8+
9+
WORKDIR /app
10+
11+
COPY package.json yarn.lock .yarnrc.yml ./
12+
COPY clients/ ./clients/
13+
COPY .yarn .yarn
14+
RUN yarn install
15+
16+
RUN mkdir dist
17+
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
18+
19+
COPY . .
20+
21+
CMD ["bash"]

README.md

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,93 @@
1-
# How to run
1+
# api-clients-automation
22

3-
## Install and setup env
3+
**Make sure to have Docker installed so you don't have to install the tooling for every API clients.**
4+
5+
## Setup repository tooling
46

57
```bash
68
nvm use && yarn
79
```
810

9-
## Generate clients based on the [`specs`](./specs/)
11+
## Setup dev environment
1012

11-
### All clients
13+
You can also execute docker commands one by one, see [Docker commands](#docker)
1214

1315
```bash
14-
yarn generate
16+
yarn docker:setup
1517
```
1618

17-
Generic command:
19+
### Docker
20+
21+
#### Build
22+
23+
Build docker image from [Dockerfile](./Dockerfile)
1824

1925
```bash
20-
yarn generate <language | all> <client | all>
26+
yarn docker:build
2127
```
2228

23-
### Search client
29+
#### Mount
30+
31+
Mount docker image on `dev` container
2432

2533
```bash
26-
yarn generate all search
34+
yarn docker:mount
2735
```
2836

29-
### Recommend client
37+
#### Clean
38+
39+
Stops `dev` container and clean the built image
3040

3141
```bash
32-
yarn generate all recommend
42+
yarn docker:clean
3343
```
3444

35-
## Build generated clients
45+
## Contributing
46+
47+
You can now make changes locally and run commands through the docker container.
48+
49+
### Generate clients based on the [`specs`](./specs/)
50+
51+
#### Usage
52+
53+
```bash
54+
yarn docker generate <language | all> <client | all>
55+
```
56+
57+
#### Generate all clients
3658

3759
```bash
38-
yarn client:build
60+
yarn docker generate
3961
```
4062

41-
# Testing clients
63+
### Generate specific client for specific language
64+
65+
#### Usage
66+
67+
```bash
68+
yarn docker build:clients <language | all> <client | all>
69+
```
70+
71+
### Build specific client for specific language
72+
73+
```bash
74+
yarn docker build:clients java recommend
75+
```
76+
77+
## Testing clients
4278

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

81+
## Usage
82+
83+
```bash
84+
yarn docker playground:<language>:<client>
85+
```
86+
4587
## JavaScript
4688

4789
```bash
48-
yarn playground:js
90+
yarn docker playground:js:search
4991
```
5092

5193
# Troubleshooting

openapitools.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"modelPropertyNaming": "original",
1919
"supportsES6": true,
2020
"npmName": "@algolia/client-search",
21-
"packageName": "@algolia/client-search",
2221
"npmVersion": "5.0.0",
2322

23+
"packageName": "@algolia/client-search",
2424
"isSearchHost": true
2525
}
2626
},
@@ -39,9 +39,9 @@
3939
"modelPropertyNaming": "original",
4040
"supportsES6": true,
4141
"npmName": "@algolia/recommend",
42-
"packageName": "@algolia/recommend",
4342
"npmVersion": "5.0.0",
4443

44+
"packageName": "@algolia/recommend",
4545
"isSearchHost": true
4646
}
4747
},
@@ -59,9 +59,9 @@
5959
"modelPropertyNaming": "original",
6060
"supportsES6": true,
6161
"npmName": "@algolia/client-personalization",
62-
"packageName": "@algolia/client-personalization",
6362
"npmVersion": "5.0.0",
6463

64+
"packageName": "@algolia/client-personalization",
6565
"hasRegionalHost": true,
6666
"isPersonalizationHost": true
6767
}
@@ -80,9 +80,9 @@
8080
"modelPropertyNaming": "original",
8181
"supportsES6": true,
8282
"npmName": "@algolia/client-analytics",
83-
"packageName": "@algolia/client-analytics",
8483
"npmVersion": "5.0.0",
8584

85+
"packageName": "@algolia/client-analytics",
8686
"hasRegionalHost": true,
8787
"isAnalyticsHost": true
8888
}
@@ -105,7 +105,9 @@
105105
"additionalProperties": {
106106
"sourceFolder": "algoliasearch-core",
107107
"java8": true,
108-
"dateLibrary": "java8"
108+
"dateLibrary": "java8",
109+
110+
"packageName": "algoliasearch-client-java-2"
109111
}
110112
}
111113
}

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
"tests/"
88
],
99
"scripts": {
10+
"build:clients": "./scripts/multiplexer.sh ./scripts/build/clients.sh ${0:-all} ${1:-all}",
11+
"build:specs": "./scripts/build/specs.sh ${0:-all} ${1:-yaml}",
12+
"build": "yarn build:specs && yarn build:clients",
1013
"clean": "rm -rf **/dist **/build **/node_modules",
11-
"client:build-java": "mvn clean install -f clients/algoliasearch-client-java-2/pom.xml",
12-
"client:build-js:analytics": "yarn workspace @algolia/client-analytics build",
13-
"client:build-js:personalization": "yarn workspace @algolia/client-personalization build",
14-
"client:build-js:recommend": "yarn workspace @algolia/recommend build",
15-
"client:build-js:search": "yarn workspace @algolia/client-search build",
16-
"client:build-js": "yarn client:build-js:search && yarn client:build-js:recommend && yarn client:build-js:personalization && yarn client:build-js:analytics",
17-
"client:build": "yarn client:build-js",
1814
"cts:generate": "yarn workspace tests cts:generate",
1915
"cts:test": "yarn workspace tests test",
16+
"docker:build": "./scripts/docker/build.sh",
17+
"docker:clean": "docker stop dev; docker rm -f dev; docker image rm -f api-clients-automation",
18+
"docker:mount": "./scripts/docker/mount.sh",
19+
"docker:setup": "yarn docker:clean && yarn docker:build && yarn docker:mount",
20+
"docker": "docker exec dev yarn $*",
2021
"lint": "eslint --ext=ts .",
2122
"post:generate": "./scripts/post-gen/global.sh",
2223
"generate": "./scripts/multiplexer.sh ./scripts/generate.sh ${0:-all} ${1:-all} && yarn post:generate",
@@ -25,8 +26,7 @@
2526
"playground:js:personalization": "yarn workspace javascript-playground start:personalization",
2627
"playground:js:recommend": "yarn workspace javascript-playground start:recommend",
2728
"playground:js:search": "yarn workspace javascript-playground start:search",
28-
"specs:format": "yarn prettier --write specs",
29-
"specs": "./scripts/specs.sh ${0:-all} ${1:-yaml}"
29+
"specs:format": "yarn prettier --write specs"
3030
},
3131
"devDependencies": {
3232
"@openapitools/openapi-generator-cli": "2.4.18",

scripts/build/clients.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Break on non-zero code
4+
set -e
5+
6+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
7+
# Move to the root (easier to locate other scripts)
8+
cd ${DIR}/../..
9+
10+
lang=$1
11+
client=$2
12+
generator="$lang-$client"
13+
package=$(cat openapitools.json | jq -r --arg generator "$generator" '."generator-cli".generators[$generator].additionalProperties.packageName')
14+
15+
# Commands are based on the lang
16+
build_client(){
17+
echo "> Building $generator..."
18+
19+
if [[ $lang == 'javascript' ]]; then
20+
yarn workspace $package build
21+
elif [[ $lang == 'java' ]]; then
22+
set +e
23+
24+
log=$(mvn clean install -f clients/$package/pom.xml)
25+
26+
if [[ $? != 0 ]]; then
27+
echo "$log"
28+
exit 1
29+
fi
30+
31+
set -e
32+
fi
33+
}
34+
35+
36+
37+
if [[ -z $package ]]; then
38+
echo "Unknown package ${package}"
39+
exit 1
40+
fi
41+
42+
build_client

scripts/specs.sh renamed to scripts/build/specs.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/bash
22

3+
if [[ ! $CI ]] && [[ ! $DOCKER ]]; then
4+
echo "You should run scripts via the docker container, see README.md"
5+
6+
exit 1
7+
fi
8+
39
# Break on non-zero code
410
set -e
511

@@ -10,7 +16,7 @@ SPECS=()
1016

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

1521
find_specs() {
1622
echo "> Searching for available specs..."

scripts/docker/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)/../.."
4+
5+
cd $ROOT
6+
7+
NODE_VERSION=$(cat .nvmrc)
8+
9+
docker build --build-arg NODE_VERSION=$NODE_VERSION -t api-clients-automation .

scripts/docker/mount.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)/../.."
4+
5+
docker run -d -it --name dev --mount type=bind,source=$ROOT/,target=/app api-clients-automation

0 commit comments

Comments
 (0)