Skip to content

Commit 81d7c2c

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

File tree

2 files changed

+167
-184
lines changed

2 files changed

+167
-184
lines changed
Lines changed: 146 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,148 @@
1+
# Composite action | https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-composite-action
12
name: Generate Model
2-
3-
# Allow workflow to be triggered by another workflow: https://docs.github.com/en/actions/sharing-automations/reusing-workflows#creating-a-reusable-workflow
4-
on:
5-
workflow_call:
6-
7-
jobs:
8-
generate:
9-
runs-on: ubuntu-latest
10-
11-
env:
12-
JAVA_POST_PROCESS_FILE: "/usr/bin/clang-format -i"
13-
14-
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v4
17-
18-
- name: Install Graphviz
19-
uses: ts-graphviz/setup-graphviz@v1
20-
21-
- name: Setup Python
22-
uses: actions/setup-python@v5
23-
with:
24-
python-version: '3.11'
25-
26-
- name: Install python requirements
27-
working-directory: ./csv_parser
28-
run: pip install -r ./requirements.txt
29-
30-
- name: Clean up old generated schemas
31-
working-directory: ./src/main/resources
32-
run: find ./json-schema -type f -name '*.json' ! -name 'customContent.schema.json' ! -name 'EDXL-DE-*.schema.json' -exec rm {} +
33-
34-
- name: Clean up old generated java classes
35-
working-directory: ./src/main/java/com/hubsante/model
36-
# We specifically only remove FOLDERS with the exception of a couple manually created ones
37-
run: find . -mindepth 1 -maxdepth 1 -type d ! -name 'builders' ! -name 'config' ! -name 'custom' ! -name 'edxl' ! -name 'exception' ! -name 'report' -exec rm -r {} +
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 {} +
3824

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

3-
# Allow workflow to be triggered by another workflow: https://docs.github.com/en/actions/sharing-automations/reusing-workflows#creating-a-reusable-workflow
4-
on:
5-
workflow_call:
12+
- name: Run csv_parser and collect OpenAPI & JSON Schemas
13+
working-directory: ./csv_parser
14+
run: python workflow.py --stage parser_and_mv
615

7-
jobs:
8-
ci:
9-
runs-on: ubuntu-latest
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
1021
11-
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v4
14-
15-
- name: Setup Python
16-
uses: actions/setup-python@v5
17-
with:
18-
python-version: '3.11'
19-
20-
- name: Run csv_parser and collect OpenAPI & JSON Schemas
21-
working-directory: ./csv_parser
22-
run: python workflow.py --stage parser_and_mv
23-
24-
- name: Run test_case_generator
25-
working-directory: ./csv_parser
26-
run: |
27-
rm -r ./out/test-cases || true
28-
python workflow.py --stage test_case_parser
29-
30-
- name: Commit and push changes
31-
uses: stefanzweifel/git-auto-commit-action@v5
32-
with:
33-
commit_message: ⚙️ Auto-génération des cas de test
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

0 commit comments

Comments
 (0)