-
Notifications
You must be signed in to change notification settings - Fork 1
82 lines (70 loc) · 2.39 KB
/
generate-python.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Generate Python
on:
push:
branches:
- "**"
- "!main"
paths:
- "src/**/*.json"
- ".github/workflows/generate-python.yml"
# Allow only one generate workflow to run at a time. This avoids race conditions when
# pushing to the same branch.
concurrency: "generate"
jobs:
generate-python:
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.DAPLA_BOT_APP_ID }}
private-key: ${{ secrets.DAPLA_BOT_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}
- name: Configure Git
run: |
git config user.name "dapla-bot[bot]"
git config user.email "143391972+dapla-bot[bot]@users.noreply.github.com"
- uses: actions/setup-python@v2
with:
python-version: 3.11.5
- name: Install pipx
run: |
python -m pip install --upgrade pipx
python -m pipx ensurepath
- name: Install datamodel-codegen
run: |
python -m pipx install datamodel-code-generator==0.25.2
- name: Generate Python
run: >
datamodel-codegen
--input-file-type jsonschema
--input src/metadata-container-json-schema.json
--output-model-type pydantic_v2.BaseModel
--base-class "datadoc_model.datadoc_base_model.DatadocBaseModel"
--use-default
--use-title-as-name
--use-one-literal-as-default
--force-optional
--use-subclass-enum
--use-standard-collections
--use-double-quotes
--target-python-version 3.10
--output generated/python/datadoc_model/datadoc_model/model.py
- name: Check for modified files
id: git-check
run: echo modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi) >> $GITHUB_OUTPUT
- name: Commit
if: steps.git-check.outputs.modified == 'true'
run: |
git add -A
git commit -m '[GENERATE] Pydantic models from JSON Schema'
- name: Push
if: steps.git-check.outputs.modified == 'true'
run: |
git pull --rebase origin "${GITHUB_REF}"
git push origin "${GITHUB_REF}"