Skip to content

Commit ba70dd6

Browse files
authored
👷‍♂️ Add CI Action to AutoGenerate TypeScript Code (#141)
* add Github Action to autogenerate ts classes * update json_schemas (after #127)
1 parent b85e52c commit ba70dd6

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Generate TypeScript Classes from JSONSchemas
2+
on:
3+
push:
4+
paths:
5+
- "json_schemas/**.json"
6+
jobs:
7+
generate:
8+
name: Generate TypeScript Classes from JSONSchemas
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check out Git repository
12+
uses: actions/checkout@v2
13+
- name: Set up Node.js
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: 14
17+
- name: Install Code Generator
18+
run: npm install json-schema-to-typescript -g
19+
- name: Run Code Generator
20+
run: json2ts -i 'json_schemas/**.json' -o ts_models/
21+
- name: Upload TypeScript Files
22+
uses: actions/upload-artifact@master
23+
with:
24+
name: TypeScriptClasses
25+
path: ts_models
26+
- name: Push ts_models content to type script models repo
27+
uses: cpina/[email protected]
28+
env:
29+
API_TOKEN_GITHUB: ${{ secrets.TS_MODELS_PUSH_TOKEN }}
30+
with:
31+
source-directory: "ts_models"
32+
target-directory: "src"
33+
destination-github-username: "Hochfrequenz"
34+
destination-repository-name: "ahbicht-ts-models"
35+
user-email: [email protected]
36+
target-branch: main

‎json_schemas/CategorizedKeyExtractSchema.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
},
5454
"title": "requirement_constraint_keys",
5555
"type": "array"
56+
},
57+
"time_condition_keys": {
58+
"items": {
59+
"title": "time_condition_keys",
60+
"type": "string"
61+
},
62+
"title": "time_condition_keys",
63+
"type": "array"
5664
}
5765
},
5866
"type": "object"

‎json_schemas/README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ This is thought to reduce manual efforts and allow for easy integration of AHBic
99
The files in this directory are autogenerated from the marshmallow classes that are also used for (de-)serialization.
1010
There is a tox environment that executes [`generate_json_schemas.py`](generate_json_schemas.py) and overwrites any `.json` files in this directory.
1111
Simply run:
12+
1213
```bash
1314
tox -e json_schemas
1415
```
16+
17+
### Github Action and Type Script Models
18+
19+
The JSON Schemas in this directory are used to autogenerate TypeScript Model classes.
20+
Therefore, [a Github Action](../.github/workflows/typescript_from_json_schemas.yml) is triggered whenever something is written to this directory.
21+
The generated classes are uploaded as Action artifact and pushed to [ahbicht-ts-models](https://github.com/Hochfrequenz/ahbicht-ts-models).

0 commit comments

Comments
 (0)