Skip to content

Commit 309f0e6

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

File tree

5 files changed

+201
-192
lines changed

5 files changed

+201
-192
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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: Install python requirements
13+
working-directory: ./csv_parser
14+
shell: bash
15+
run: pip install -r ./requirements.txt
16+
17+
- name: Run csv_parser and collect OpenAPI & JSON Schemas
18+
working-directory: ./csv_parser
19+
run: python workflow.py --stage parser_and_mv
20+
shell: bash
21+
22+
- name: Run test_case_generator
23+
working-directory: ./csv_parser
24+
run: |
25+
rm -r ./out/test-cases || true
26+
python workflow.py --stage test_case_parser
27+
shell: bash
28+
29+
- name: Commit and push changes
30+
uses: stefanzweifel/git-auto-commit-action@v5
31+
with:
32+
commit_message: ⚙️ Auto-génération des cas de test

.github/workflows/ci.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
jobs:
1313
generate-models:
1414
runs-on: ubuntu-latest
15+
16+
env:
17+
JAVA_POST_PROCESS_FILE: "/usr/bin/clang-format -i"
1518

1619
steps:
1720
- name: Checkout
@@ -36,11 +39,11 @@ jobs:
3639
3740
- name: Run test_cases generation
3841
if: steps.filter.outputs.test_case_parsing_required == 'true'
39-
uses: ./.github/workflows/generate-test-cases.yaml
42+
uses: ./.github/actions/generate-test-cases
4043

4144
- name: Run model generation
4245
if: steps.filter.outputs.parsing_required == 'true'
43-
uses: ./.github/workflows/generate-models.yaml
46+
uses: ./.github/actions/generate-models
4447

4548
- name: Grant execute permission for Gradlew
4649
run: chmod +x ./gradlew

.github/workflows/generate-model.yaml

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

0 commit comments

Comments
 (0)