Skip to content

Commit

Permalink
ci: test composite actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemsazert committed Jan 9, 2025
1 parent d471f27 commit 1885291
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 192 deletions.
148 changes: 148 additions & 0 deletions .github/actions/generate-model/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Composite action | https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-composite-action
name: Generate Model
description: Generate the java classes & spec based on the model
runs:
using: "composite"
env:
JAVA_POST_PROCESS_FILE: "/usr/bin/clang-format -i"
steps:
- name: Install Graphviz
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
run: pip install -r ./requirements.txt

- name: Clean up old generated schemas
working-directory: ./src/main/resources
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
# 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 and collect OpenAPI & JSON Schemas
working-directory: ./csv_parser
run: python workflow.py --stage parser_and_mv

- name: Run csv_parser to generate schemas.yaml
working-directory: ./csv_parser
run: python workflow.py --stage output_schemas_yaml

- name: Collect schemas.yaml and copy it to json_schema2xsd
working-directory: ./csv_parser
run: |
cp ./out/schemas.yaml ./json_schema2xsd/src/main/resources/schemas.yaml
- name: Setup gomplate
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
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
with:
java-version: '11'
distribution: 'temurin'

- name: Generate XSDs
working-directory: ./csv_parser/json_schema2xsd
run: gradle run

- name: Move XSDs to src
working-directory: ./csv_parser/json_schema2xsd
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
run: |
rm src/main/resources/*.json
- name: Install node env 🏗
uses: actions/setup-node@v4
with:
node-version: 16

- name: Install openapi-generator-cli
run: npm install -g @openapitools/openapi-generator-cli

- name: Install linter
run: sudo apt install -y clang-format

- name: Generate Java classes
working-directory: ./generator
run: |
# 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/openapi-generator-cli generate -c "$file" --skip-validate-spec; done
- name: Replace src/ with generated classes
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
run: ./gradlew licenseFormat

- name: Delete old xml files
run: |
find ./src/main/resources/sample/examples -name "*.xml" -type f -delete
- name: Generate XML files
run: |
./gradlew generateXml
continue-on-error: true

- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: ⚙️ Auto-génération des classes et des specs
25 changes: 25 additions & 0 deletions .github/actions/generate-test-cases/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Composite action | https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-composite-action
name: Generate test cases
description: Generate the json containing the test cases
runs:
using: "composite"
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Run csv_parser and collect OpenAPI & JSON Schemas
working-directory: ./csv_parser
run: python workflow.py --stage parser_and_mv

- name: Run test_case_generator
working-directory: ./csv_parser
run: |
rm -r ./out/test-cases || true
python workflow.py --stage test_case_parser
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: ⚙️ Auto-génération des cas de test
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ jobs:
- name: Run test_cases generation
if: steps.filter.outputs.test_case_parsing_required == 'true'
uses: ./.github/workflows/generate-test-cases.yaml
uses: ./.github/actions/generate-test-cases

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

- name: Grant execute permission for Gradlew
run: chmod +x ./gradlew
Expand Down
157 changes: 0 additions & 157 deletions .github/workflows/generate-model.yaml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/generate-test-cases.yaml

This file was deleted.

0 comments on commit 1885291

Please sign in to comment.