Skip to content
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

feat(script): use typescript for all scripts APIC-334 #170

Merged
merged 21 commits into from
Feb 25, 2022
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
29 changes: 13 additions & 16 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
uses: ./.github/actions/cache

- name: Building ${{ matrix.client }} specs
run: yarn build:specs ${{ matrix.client }}
run: yarn cli build specs ${{ matrix.client }}

- name: Check diff with pushed spec
run: exit $(git status --porcelain specs/bundled/${{ matrix.client }}.yml | wc -l)
Expand Down Expand Up @@ -123,15 +123,15 @@ jobs:

- name: Generate ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn generate javascript ${{ matrix.client.name }}
run: yarn cli generate javascript ${{ matrix.client.name }}

- name: Check diff with pushed client
if: steps.cache.outputs.cache-hit != 'true'
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)

- name: Build ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients javascript ${{ matrix.client.name }}
run: yarn cli build clients javascript ${{ matrix.client.name }}

client_java:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -160,15 +160,15 @@ jobs:

- name: Generate ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn generate java ${{ matrix.client.name }}
run: yarn cli generate java ${{ matrix.client.name }}

- name: Check diff with pushed client
if: steps.cache.outputs.cache-hit != 'true'
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)

- name: Build ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients java ${{ matrix.client.name }}
run: yarn cli build clients java ${{ matrix.client.name }}

client_php:
runs-on: ubuntu-20.04
Expand All @@ -190,15 +190,15 @@ jobs:

- name: Generate ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn generate php ${{ matrix.client.name }}
run: yarn cli generate php ${{ matrix.client.name }}

- name: Check diff with pushed client
if: steps.cache.outputs.cache-hit != 'true'
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)

- name: Build ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients php ${{ matrix.client.name }}
run: yarn cli build clients php ${{ matrix.client.name }}

cts:
runs-on: ubuntu-20.04
Expand All @@ -217,20 +217,14 @@ jobs:
with:
job: cts

- name: Check script linting
run: yarn cts:lint:scripts

- name: Test CTS script
run: yarn cts:test:scripts

- name: Generate CTS
run: yarn cts:generate
run: yarn cli cts generate

- name: Check diff with pushed CTS
run: exit $(git status --porcelain ./tests/output | wc -l)

- name: Run CTS
run: yarn cts:test
run: yarn cli cts run

scripts:
runs-on: ubuntu-20.04
Expand All @@ -243,5 +237,8 @@ jobs:
id: restore
uses: ./.github/actions/cache

- name: Check script linting
run: yarn scripts:lint

- name: Test scripts
run: yarn workspace scripts test
run: yarn scripts:test
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,34 @@ You can make changes locally and run commands through the docker container.
#### Usage

```bash
yarn docker build:specs <client | all>
yarn docker build specs <client | all>
```

#### Build all specs

```bash
yarn docker build:specs
yarn docker build specs
```

#### Build specific spec

```bash
yarn docker build:specs recommend
yarn docker build specs recommend
```

#### Fix the specs format

This is used by the build script and should not need to be called manually but if you want to format all specs file do:

```bash
yarn docker specs:fix
yarn specs:fix
```

If you just want to check the format (not override the files), run:

```bash
yarn docker specs:lint <client>
yarn docker specs:lint search
yarn specs:lint <client>
yarn specs:lint search
```

### Generate clients based on the [`specs`](./specs/)
Expand All @@ -102,15 +102,23 @@ yarn docker generate
#### Usage

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

### Build specific client for specific language

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

### Verbose command
millotp marked this conversation as resolved.
Show resolved Hide resolved

You can add `-v` to almost every command to have a more verbose output.

### Interactive command

If you want to choose the language and client from a list you can add the `--interactive` option, or `-i`.

## Testing clients

You can test our generated clients by running:
Expand Down
3 changes: 2 additions & 1 deletion base.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"typeRoots": ["node_modules/@types"],
"types": ["node"],
"resolveJsonModule": true
}
},
"exclude": ["node_modules"]
}
19 changes: 19 additions & 0 deletions clients.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely need a config folder

"java": {
"folder": "clients/algoliasearch-client-java-2",
"tests": {
"extension": ".test.java",
"outputFolder": "src/test/java/com/algolia"
}
},
"javascript": {
"folder": "clients/algoliasearch-client-javascript",
"tests": {
"extension": ".test.ts",
"outputFolder": "src"
}
},
"php": {
"folder": "clients/algoliasearch-client-php"
}
}
14 changes: 7 additions & 7 deletions docs/CTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ It is automaticaly generated for all languages, from a JSON entry point.
> CTS requires all clients to be built

```bash
yarn docker build:specs
yarn docker build:clients
yarn docker cts:generate
yarn docker cts:test
yarn docker build specs all
yarn docker build clients all all
yarn docker cts generate all all
yarn docker cts run all
```

If you only want to generate the tests for a language, you can run:

```bash
yarn docker cts:generate javascript
yarn docker cts generate javascript all
```

Or for a specific client:

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

Or a specific language and client:

```bash
yarn docker cts:generate javascript search
yarn docker cts generate javascript search
```

## How to add test
Expand Down
16 changes: 12 additions & 4 deletions openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@
"sourceFolder": "algoliasearch-core",
"java8": true,
"dateLibrary": "java8",
"packageName": "algoliasearch-client-java-2"
"packageName": "algoliasearch-client-java-2",
"packageVersion": "0.0.1"
}
},
"php-search": {
Expand All @@ -259,7 +260,8 @@
"configClassname": "SearchConfig",
"useCache": true,
"variableNamingConvention": "camelCase",
"packageName": "algoliasearch-client-php"
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1"
}
},
"php-recommend": {
Expand All @@ -277,7 +279,8 @@
"configClassname": "RecommendConfig",
"useCache": true,
"variableNamingConvention": "camelCase",
"packageName": "algoliasearch-client-php"
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1"
}
},
"php-personalization": {
Expand All @@ -297,6 +300,7 @@
"allowedRegions": "us-eu",
"variableNamingConvention": "camelCase",
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"isEuHost": true,
"host": "personalization",
"topLevelDomain": "com"
Expand All @@ -319,6 +323,7 @@
"allowedRegions": "us-de",
"variableNamingConvention": "camelCase",
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"fallbackToAliasHost": true,
"isDeHost": true,
"host": "analytics",
Expand All @@ -342,6 +347,7 @@
"allowedRegions": "us-de",
"variableNamingConvention": "camelCase",
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"fallbackToAliasHost": true,
"isDeHost": true,
"host": "insights",
Expand All @@ -365,6 +371,7 @@
"allowedRegions": "us-de",
"variableNamingConvention": "camelCase",
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"fallbackToAliasHost": true,
"isDeHost": true,
"host": "analytics",
Expand All @@ -388,11 +395,12 @@
"allowedRegions": "us-eu",
"variableNamingConvention": "camelCase",
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"isEuHost": true,
"host": "query-suggestions",
"topLevelDomain": "com"
}
}
}
}
}
}
26 changes: 9 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,24 @@
"clients/algoliasearch-client-javascript/",
"playground/javascript/node/",
"playground/javascript/browser/",
"tests/",
"scripts/"
"scripts/",
"tests/output/javascript"
],
"scripts": {
"build:clients": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/builds/clients.sh ${0:-all} ${1:-all}",
"build:specs": "./scripts/builds/specs.sh ${0:-all} ${1:-yml}",
"build": "yarn build:specs && yarn build:clients",
"cli": "yarn workspace scripts ts-node --transpile-only ./index.ts",
"clean": "rm -rf **/dist **/build **/node_modules **/.gradle",
"cts:generate": "yarn workspace tests build && ./scripts/multiplexer.sh ${2:-nonverbose} yarn workspace tests generate ${0:-all} ${1:-all}",
"cts:test": "./scripts/multiplexer.sh ${1:-nonverbose} ./scripts/runCTS.sh ${0:-all} all",
"cts:test:scripts": "yarn workspace tests test:scripts",
"cts:lint:scripts": "eslint --ext=ts tests/src/",
"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 -it dev yarn $*",
"lint": "eslint --ext=ts .",
"post:generate": "./scripts/post-gen/global.sh",
"generate": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/generate.sh ${0:-all} ${1:-all} && yarn post:generate ${0:-all}",
"docker": "docker exec -it dev yarn cli $*",
"github-actions:lint": "eslint --ext=yml .github/",
"playground:browser": "yarn workspace javascript-browser-playground start",
"playground": "yarn && ./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/playground.sh ${0:-javascript} ${1:-search}",
"release": "yarn workspace scripts createReleaseIssue",
"scripts:lint": "eslint --ext=ts scripts/",
"scripts:test": "yarn workspace scripts test",
"specs:fix": "eslint --ext=yml specs/ --fix",
"specs:lint": "eslint --ext=yml specs/$0",
"github-actions:lint": "eslint --ext=yml .github/",
"release": "yarn workspace scripts createReleaseIssue"
"specs:lint": "eslint --ext=yml specs/$0"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "2.4.26",
Expand Down
Loading