-
Notifications
You must be signed in to change notification settings - Fork 0
245 lines (207 loc) · 9.96 KB
/
generate-model.yaml
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: Generate Model
on:
pull_request:
branches:
- '**'
release:
types:
- published
workflow_dispatch:
jobs:
generate:
runs-on: ubuntu-latest
env:
JAVA_POST_PROCESS_FILE: "/usr/bin/clang-format -i"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for changes requiring running the parser
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
parsing_required:
- 'csv_parser/csv_parser.py'
- 'csv_parser/uml_generator.py'
- 'csv_parser/workflow.py'
- 'csv_parser/models/**'
- 'csv_parser/nomenclature_parser/**'
- 'csv_parser/json_schema2xsd/**'
test_case_parsing_required:
- 'csv_parser/test_case_generator.py'
- 'csv_parser/workflow.py'
- 'csv_parser/test-cases-sources/**'
- name: Install Graphviz
if: steps.filter.outputs.parsing_required == 'true'
uses: ts-graphviz/setup-graphviz@v1
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install python requirements
working-directory: ./csv_parser
if: steps.filter.outputs.parsing_required == 'true' || steps.filter.outputs.test_case_parsing_required == 'true'
run: pip install -r ./requirements.txt
- name: Clean up old generated schemas
working-directory: ./src/main/resources
if: steps.filter.outputs.parsing_required == 'true'
run: find ./json-schema -type f -name '*.json' ! -name 'customContent.schema.json' ! -name 'EDXL-DE-*.schema.json' -exec rm {} +
- name: Clean up old generated java classes
working-directory: ./src/main/java/com/hubsante/model
if: steps.filter.outputs.parsing_required == 'true'
# We specifically only remove FOLDERS with the exception of a couple manually created ones
run: find . -mindepth 1 -maxdepth 1 -type d ! -name 'builders' ! -name 'config' ! -name 'custom' ! -name 'edxl' ! -name 'exception' ! -name 'report' -exec rm -r {} +
- name: Run csv_parser to generate schemas.yaml
working-directory: ./csv_parser
if: steps.filter.outputs.parsing_required == 'true'
run: python workflow.py --stage output_schemas_yaml
- name: Run csv_parser and collect OpenAPI & JSON Schemas
working-directory: ./csv_parser
if: steps.filter.outputs.parsing_required == 'true'
run: python workflow.py --stage parser_and_mv
- name: Run test_case_generator
working-directory: ./csv_parser
if: steps.filter.outputs.test_case_parsing_required == 'true'
run: |
rm -r ./out/test-cases || true
python workflow.py --stage test_case_parser
- name: Collect schemas.yaml and copy it to json_schema2xsd
working-directory: ./csv_parser
if: steps.filter.outputs.parsing_required == 'true'
run: |
cp ./out/schemas.yaml ./json_schema2xsd/src/main/resources/schemas.yaml
- name: Setup gomplate
if: steps.filter.outputs.parsing_required == 'true'
uses: jason-dour/[email protected]
with:
gomplate-version: v4.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run automatic-schema-generator and move generated files to corresponding locations
if: steps.filter.outputs.parsing_required == 'true'
working-directory: ./automatic-schema-generator
run: |
rm -r output || true
chmod +x ./automatic-generator.sh
./automatic-generator.sh
# Move generated OpenAPI config files to the corresponding locations
rm -r ../generator/config/generated || true
rsync -a --remove-source-files output/generator ..
rm -r ../generator_ruby/config/generated || true
rsync -a --remove-source-files output/generator_ruby ..
rm -r ../generator_python/config/generated || true
rsync -a --remove-source-files output/generator_python ..
rm -r ../generator_csharp/config/generated || true
rsync -a --remove-source-files output/generator_csharp ..
# Move generated EDXL-DE and JSON Schemas to the corresponding locations
rsync -a --remove-source-files output/edxl ../src/main/java/com/hubsante/model
rsync -a --remove-source-files output/json-schema ../src/main/resources
rsync -a --remove-source-files output/xsd ../src/main/resources
- name: Install JDK 11
uses: actions/setup-java@v4
if: steps.filter.outputs.parsing_required == 'true'
with:
java-version: '11'
distribution: 'temurin'
- name: Generate XSDs
working-directory: ./csv_parser/json_schema2xsd
if: steps.filter.outputs.parsing_required == 'true'
run: gradle run
- name: Move XSDs to src
working-directory: ./csv_parser/json_schema2xsd
if: steps.filter.outputs.parsing_required == 'true'
run: |
# Clean XSD repo but keep manual XSDs
find ../../src/main/resources/xsd -type f -name '*.xsd' ! -name 'EDXL-DE-*.xsd' ! -name 'customContent.xsd' ! -name 'RC-DE.xsd' ! -name 'RC-XML-ContentType.xsd' ! -name 'RS-ERROR.xsd' ! -path '**/other-supporting-schema/*' -exec rm {} +
mv out/*.xsd ../../src/main/resources/xsd/
- name: Remove input JSON Schemas
working-directory: ./csv_parser/json_schema2xsd
if: steps.filter.outputs.parsing_required == 'true'
run: |
rm src/main/resources/*.json
- name: Install node env 🏗
uses: actions/setup-node@v4
if: steps.filter.outputs.parsing_required == 'true'
with:
node-version: 16
- name: Install openapi-generator-cli
if: steps.filter.outputs.parsing_required == 'true'
run: npm install -g @openapitools/[email protected]
- name: Install linter
if: steps.filter.outputs.parsing_required == 'true'
run: sudo apt install -y clang-format
- name: Generate Java classes
if: steps.filter.outputs.parsing_required == 'true'
working-directory: ./generator
run: |
# Setup OpenAPI version
npx openapi-generator-cli version-manager set 7.4.0
# Iterate over each file in the ./config directory, including the entire subfolder structure
# and then run @openapitools/openapi-generator-cli generate for each file found
# Important notice:
# Results of the find command are sorted in an alphabetic order before being passed to xargs
# This means that since the order of class generation is important, it's necessary to maintain an adequately
# named file structure in the ./config/** directories
# generator-config.json (if exists) -> usecase.generator-config.json -> wrapper.generator-config.json
find ./config/ -type f | sort -n | while read -r file; do npx @openapitools/[email protected] generate -c "$file" --skip-validate-spec; done
- name: Replace src/ with generated classes
if: steps.filter.outputs.parsing_required == 'true'
run: |
rm -r ./src/main/java/com/hubsante/model/rcde || true
rm -r ./src/main/java/com/hubsante/model/cisu || true
rm -r ./src/main/java/com/hubsante/model/health || true
rm -r ./src/main/java/com/hubsante/model/emsi || true
rm -r ./src/main/java/com/hubsante/model/geolocation || true
rm -r ./src/main/java/com/hubsante/model/resources || true
rm -r ./src/main/java/com/hubsante/model/rpis || true
rm -r ./src/main/java/com/hubsante/model/technical || true
rm -r ./generator/classes/src/main/java/com/hubsante/model/report/ErrorCode.java || true
cp -r ./generator/classes/src/main/java/com/hubsante/model/* ./src/main/java/com/hubsante/model/
- name: Grant execute permission for Gradlew
run: chmod +x ./gradlew
- name: Apply license
if: steps.filter.outputs.parsing_required == 'true'
run: ./gradlew licenseFormat
- name: Delete old xml files
if: steps.filter.outputs.parsing_required == 'true'
run: |
find ./src/main/resources/sample/examples -name "*.xml" -type f -delete
- name: Generate XML files
if: steps.filter.outputs.parsing_required == 'true'
run: |
./gradlew generateXml
continue-on-error: true
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
if: steps.filter.outputs.parsing_required == 'true'
with:
commit_message: ⚙️ Auto-génération des classes et des specs
- name: Build and run TECHNICAL tests
run: ./gradlew test --info -Ptechnical=true
- name: Build and run REAL MESSAGES tests
run: ./gradlew test --info -Pfunctional=true
# Ref.: https://github.com/gradle/gradle-build-action/issues/619#issuecomment-1453244157
- name: Upload test report
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-report
path: build/reports/tests/test/**
- name: Add coverage to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: ${{ github.workspace }}/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60
- name: Setup .NET Core # Required to execute ReportGenerator
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.x
dotnet-quality: 'ga'
- name: Run ReportGenerator for test coverage
uses: danielpalme/[email protected]
with:
reports: ${{ github.workspace }}/build/reports/jacoco/test/jacocoTestReport.xml
targetdir: coveragereport