Skip to content

Commit

Permalink
ci: add prism-agent client generator (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
amagyar-iohk authored Aug 4, 2023
1 parent 9cef8c0 commit 5b7afbe
Show file tree
Hide file tree
Showing 25 changed files with 2,398 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/release-clients.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Publish prism-agent clients

on:
push:
tags:
- "prism-agent-v*"

jobs:
publish-clients:
name: 'Build and publish Prism-Agent clients'
runs-on: ubuntu-latest
env:
VERSION_TAG: ${{github.ref_name}}
ATALA_GITHUB_ACTOR: ${{secrets.ATALA_GITHUB_ACTOR}}
ATALA_GITHUB_TOKEN: ${{secrets.ATALA_GITHUB_TOKEN}}
NODE_AUTH_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
registry-url: https://npm.pkg.github.com/
scope: "@input-output-hk"

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Login to Github Hub
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.ATALA_GITHUB_ACTOR }}
password: ${{ secrets.ATALA_GITHUB_TOKEN }}

- name: Install generator dependencies
working-directory: prism-agent/client/generator
run: yarn install

- name: Generate clients
working-directory: prism-agent/client/generator
run: yarn generate:all

- name: Publish clients
working-directory: prism-agent/client/generator
run: yarn publish:clients
45 changes: 45 additions & 0 deletions prism-agent/client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
target
node_modules/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
.idea

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
38 changes: 38 additions & 0 deletions prism-agent/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Prism-agent client generator

This project goal is to generate the models based on the OpenAPI Specification.

## Generating models

Then run the generator scripts:

```bash
cd generator
yarn generate
```

To publish the clients:

```bash
cd generator
yarn publish:clients
```

## Prism-agent lifecycle

`prism-client-generator` creates the clients after the `prism-agent-v*` tag is created.

## Supported clients

1. Kotlin
2. Typescript

### Work in progress

1. Python

# Caution note

Some of the OAS3 schema types are not fully supported.

The generated files that are not supported were fixed manually and ignored from the generation, in the `.openapi-generator-ignore` file, therefore it requires a diligence work to keep them updated.
6 changes: 6 additions & 0 deletions prism-agent/client/generator/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

git clean -dfx ../kotlin
git clean -dfx ../python
git clean -dfx ../typescript
20 changes: 20 additions & 0 deletions prism-agent/client/generator/generate-clients.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e

# generate kotlin models
yarn openapi-generator-cli generate \
-g kotlin \
-i ../../service/api/http/prism-agent-openapi-spec.yaml \
-o ../kotlin \
--ignore-file-override ../kotlin/.openapi-generator-ignore \
--additional-properties=packageName=io.iohk.atala.prism,serializationLibrary=gson

# generate typescript models
yarn openapi-generator-cli generate \
-g typescript \
-i ../../service/api/http/prism-agent-openapi-spec.yaml \
-o ../typescript \
--ignore-file-override ../typescript/.openapi-generator-ignore

# generate python models
# yarn openapi-generator-cli generate -g python -i oas.yml --skip-validate-spec -o ../python --ignore-file-override ../python/.openapi-generator-ignore
7 changes: 7 additions & 0 deletions prism-agent/client/generator/openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "6.6.0"
}
}
19 changes: 19 additions & 0 deletions prism-agent/client/generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "prism-agent-clients-generator",
"version": "1.0.0",
"description": "Generates the clients based on the OAS for many languages",
"author": "Allain Magyar",
"license": "Apache-2.0",
"private": true,
"type": "module",
"scripts": {
"generate": "npm-run-all clean:all generate:all",
"generate:all": "./generate-clients.sh",
"clean:all": "./clean.sh",
"publish:clients": "./publish-clients.sh"
},
"dependencies": {
"@openapitools/openapi-generator-cli": "2.7.0",
"npm-run-all": "^4.1.5"
}
}
16 changes: 16 additions & 0 deletions prism-agent/client/generator/publish-clients.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

PRISM_AGENT_VERSION=${VERSION_TAG:13}

# install dependencies
yarn

# kotlin
gradle -p ../kotlin -Pversion=${PRISM_AGENT_VERSION} publish

# typescript
yarn --cwd ../typescript
yarn --cwd ../typescript publish --new-version ${PRISM_AGENT_VERSION} --no-git-tag-version

# python
Loading

0 comments on commit 5b7afbe

Please sign in to comment.