Skip to content

Commit 1885291

Browse files
committed
ci: test composite actions
1 parent d471f27 commit 1885291

File tree

5 files changed

+175
-192
lines changed

5 files changed

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

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ jobs:
3636
3737
- name: Run test_cases generation
3838
if: steps.filter.outputs.test_case_parsing_required == 'true'
39-
uses: ./.github/workflows/generate-test-cases.yaml
39+
uses: ./.github/actions/generate-test-cases
4040

4141
- name: Run model generation
4242
if: steps.filter.outputs.parsing_required == 'true'
43-
uses: ./.github/workflows/generate-models.yaml
43+
uses: ./.github/actions/generate-models
4444

4545
- name: Grant execute permission for Gradlew
4646
run: chmod +x ./gradlew

.github/workflows/generate-model.yaml

Lines changed: 0 additions & 157 deletions
This file was deleted.

.github/workflows/generate-test-cases.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)