1+ # Composite action | https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-composite-action
2+ name : Generate Model
3+ description : Generate the java classes & spec based on the model
4+ runs :
5+ using : " composite"
6+ steps :
7+ - name : Install Graphviz
8+ uses : ts-graphviz/setup-graphviz@v1
9+
10+ - name : Setup Python
11+ uses : actions/setup-python@v5
12+ with :
13+ python-version : ' 3.11'
14+
15+ - name : Install python requirements
16+ working-directory : ./csv_parser
17+ shell : bash
18+ run : pip install -r ./requirements.txt
19+
20+ - name : Clean up old generated schemas
21+ working-directory : ./src/main/resources
22+ shell : bash
23+ run : find ./json-schema -type f -name '*.json' ! -name 'customContent.schema.json' ! -name 'EDXL-DE-*.schema.json' -exec rm {} +
24+
25+ - name : Clean up old generated java classes
26+ working-directory : ./src/main/java/com/hubsante/model
27+ # We specifically only remove FOLDERS with the exception of a couple manually created ones
28+ shell : bash
29+ run : find . -mindepth 1 -maxdepth 1 -type d ! -name 'builders' ! -name 'config' ! -name 'custom' ! -name 'edxl' ! -name 'exception' ! -name 'report' -exec rm -r {} +
30+
31+ - name : Run csv_parser and collect OpenAPI & JSON Schemas
32+ working-directory : ./csv_parser
33+ shell : bash
34+ run : python workflow.py --stage parser_and_mv
35+
36+ - name : Run csv_parser to generate schemas.yaml
37+ working-directory : ./csv_parser
38+ shell : bash
39+ run : python workflow.py --stage output_schemas_yaml
40+
41+ - name : Collect schemas.yaml and copy it to json_schema2xsd
42+ working-directory : ./csv_parser
43+ shell : bash
44+ run : |
45+ cp ./out/schemas.yaml ./json_schema2xsd/src/main/resources/schemas.yaml
46+
47+ - name : Setup gomplate
48+ uses :
jason-dour/[email protected] 49+ with :
50+ gomplate-version : v4.2.0
51+ env :
52+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
53+
54+ - name : Run automatic-schema-generator and move generated files to corresponding locations
55+ working-directory : ./automatic-schema-generator
56+ shell : bash
57+ run : |
58+ rm -r output || true
59+ chmod +x ./automatic-generator.sh
60+ ./automatic-generator.sh
61+
62+ # Move generated OpenAPI config files to the corresponding locations
63+ rm -r ../generator/config/generated || true
64+ rsync -a --remove-source-files output/generator ..
65+ rm -r ../generator_ruby/config/generated || true
66+ rsync -a --remove-source-files output/generator_ruby ..
67+ rm -r ../generator_python/config/generated || true
68+ rsync -a --remove-source-files output/generator_python ..
69+ rm -r ../generator_csharp/config/generated || true
70+ rsync -a --remove-source-files output/generator_csharp ..
71+
72+ # Move generated EDXL-DE and JSON Schemas to the corresponding locations
73+ rsync -a --remove-source-files output/edxl ../src/main/java/com/hubsante/model
74+ rsync -a --remove-source-files output/json-schema ../src/main/resources
75+ rsync -a --remove-source-files output/xsd ../src/main/resources
76+
77+ - name : Install JDK 11
78+ uses : actions/setup-java@v4
79+ with :
80+ java-version : ' 11'
81+ distribution : ' temurin'
82+
83+ - name : Generate XSDs
84+ working-directory : ./csv_parser/json_schema2xsd
85+ shell : bash
86+ run : gradle run
87+
88+ - name : Move XSDs to src
89+ working-directory : ./csv_parser/json_schema2xsd
90+ shell : bash
91+ run : |
92+ # Clean XSD repo but keep manual XSDs
93+ 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 {} +
94+ mv out/*.xsd ../../src/main/resources/xsd/
95+
96+ - name : Remove input JSON Schemas
97+ working-directory : ./csv_parser/json_schema2xsd
98+ shell : bash
99+ run : |
100+ rm src/main/resources/*.json
101+
102+ - name : Install node env 🏗
103+ uses : actions/setup-node@v4
104+ with :
105+ node-version : 16
106+
107+ - name : Install openapi-generator-cli
108+ shell : bash
109+ run : npm install -g @openapitools/openapi-generator-cli
110+
111+ - name : Install linter
112+ shell : bash
113+ run : sudo apt install -y clang-format
114+
115+ - name : Generate Java classes
116+ working-directory : ./generator
117+ shell : bash
118+ run : |
119+ # Iterate over each file in the ./config directory, including the entire subfolder structure
120+ # and then run @openapitools/openapi-generator-cli generate for each file found
121+ # Important notice:
122+ # Results of the find command are sorted in an alphabetic order before being passed to xargs
123+ # This means that since the order of class generation is important, it's necessary to maintain an adequately
124+ # named file structure in the ./config/** directories
125+ # generator-config.json (if exists) -> usecase.generator-config.json -> wrapper.generator-config.json
126+ find ./config/ -type f | sort -n | while read -r file; do npx @openapitools/openapi-generator-cli generate -c "$file" --skip-validate-spec; done
127+
128+ - name : Replace src/ with generated classes
129+ shell : bash
130+ run : |
131+ rm -r ./src/main/java/com/hubsante/model/rcde || true
132+ rm -r ./src/main/java/com/hubsante/model/cisu || true
133+ rm -r ./src/main/java/com/hubsante/model/health || true
134+ rm -r ./src/main/java/com/hubsante/model/emsi || true
135+ rm -r ./src/main/java/com/hubsante/model/geolocation || true
136+ rm -r ./src/main/java/com/hubsante/model/resources || true
137+ rm -r ./src/main/java/com/hubsante/model/rpis || true
138+ rm -r ./src/main/java/com/hubsante/model/technical || true
139+ rm -r ./generator/classes/src/main/java/com/hubsante/model/report/ErrorCode.java || true
140+ cp -r ./generator/classes/src/main/java/com/hubsante/model/* ./src/main/java/com/hubsante/model/
141+
142+ - name : Grant execute permission for Gradlew
143+ shell : bash
144+ run : chmod +x ./gradlew
145+
146+ - name : Apply license
147+ shell : bash
148+ run : ./gradlew licenseFormat
149+
150+ - name : Delete old xml files
151+ shell : bash
152+ run : |
153+ find ./src/main/resources/sample/examples -name "*.xml" -type f -delete
154+
155+ - name : Generate XML files
156+ shell : bash
157+ run : |
158+ ./gradlew generateXml
159+ continue-on-error : true
160+
161+ - name : Commit and push changes
162+ uses : stefanzweifel/git-auto-commit-action@v5
163+ with :
164+ commit_message : ⚙️ Auto-génération des classes et des specs
0 commit comments