diff --git a/.github/scripts/combine_templates.py b/.github/scripts/combine_templates.py new file mode 100644 index 000000000..f0f3d1444 --- /dev/null +++ b/.github/scripts/combine_templates.py @@ -0,0 +1,37 @@ +import os +import shutil + + +def copy_files(src_dir, dst_dir, base_dir): + for root, _, files in os.walk(src_dir): + for file in files: + src = os.path.join(root, file) + dst = os.path.join(dst_dir, os.path.relpath(src, base_dir)) + os.makedirs(os.path.dirname(dst), exist_ok=True) + shutil.copy2(src, dst) + print(f"Copied {src} to {dst}") + + +def handle_versions(base_templates, version, output_dir): + for i in range(1, version + 1): + version_dir = os.path.join(base_templates, f"v{i}") + if not os.path.exists(version_dir): + print(f"Version {i} does not exist - skipping") + continue + print(f"Copying version v{i} from {version_dir}") + copy_files(version_dir, output_dir, version_dir) + + +if __name__ == "__main__": + base_templates = os.getenv('INPUT_BASE_TEMPLATES') + custom_templates = os.getenv('INPUT_CUSTOM_TEMPLATES') + version = int(os.getenv('INPUT_VERSION')) + output_dir = 'tmp/templates' + + print(f"Base templates: {base_templates}") + print(f"Custom templates: {custom_templates}") + print(f"Version: {version}") + print(f"Output templates: {output_dir}") + + handle_versions(base_templates, version, output_dir) + copy_files(custom_templates, output_dir, custom_templates) diff --git a/.github/workflows/selfserve-combine-templates.yaml b/.github/workflows/selfserve-combine-templates.yaml new file mode 100644 index 000000000..872b3b8f8 --- /dev/null +++ b/.github/workflows/selfserve-combine-templates.yaml @@ -0,0 +1,47 @@ +name: Combine Templates + +on: + workflow_dispatch: + inputs: + base_templates: + description: 'Base SDK templates path (without the versioned directories)' + type: string + default: 'sdk-repo/generator/openapi/src/main/resources/templates/expediagroup-sdk' + version: + description: 'Base templates version' + type: number + default: 1 + custom_templates: + description: 'Custom templates path to merge with base templates' + type: string + default: '' + combined_templates_key: + description: 'Key to the combined templates artifact' + type: string + default: 'templates' + +jobs: + combine-templates: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Combine templates + run: python .github/scripts/combine_templates.py + env: + INPUT_BASE_TEMPLATES: ${{ github.event.inputs.base_templates }} + INPUT_CUSTOM_TEMPLATES: ${{ github.event.inputs.custom_templates }} + INPUT_VERSION: ${{ github.event.inputs.version }} + INPUT_OUTPUT_DIR: 'tmp/templates' + + - name: Upload combined templates + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.combined_templates_key }} + path: tmp/templates diff --git a/.github/workflows/selfserve-full-workflow.yaml b/.github/workflows/selfserve-full-workflow.yaml index 59dfc39aa..9deed6d49 100644 --- a/.github/workflows/selfserve-full-workflow.yaml +++ b/.github/workflows/selfserve-full-workflow.yaml @@ -13,13 +13,27 @@ on: E.g., 1.0.0, 1.0.1, 1.0.0-SNAPSHOT, etc. required: true type: string - templates: + custom_templates: description: | - Path to the templates directory. + Path to the custom templates directory. + Make sure to checkout the custom templates directory before setting this input. + type: string + default: '-NA-' + base_templates: + description: | + Path to the base templates directory (without the version number). Use the default path if you are using the default templates. Use `sdk-repo` to refer to the `expediagroup-sdk` repo root path if needed. type: string default: 'sdk-repo/generator/openapi/src/main/resources/templates/expediagroup-sdk' + templates_version: + description: 'Base templates version' + type: number + default: 1 + combined_templates_key: + description: 'Key to the combined templates artifact' + type: string + default: 'templates' repository: description: | Repository to generate the SDK in. @@ -76,7 +90,9 @@ jobs: run: | echo "SDK Name: ${{ inputs.name }}" echo "SDK Version: ${{ inputs.version }}" - echo "Templates: ${{ inputs.templates }}" + echo "Base Templates: ${{ inputs.base_templates }}" + echo "Base Templates Version: v${{ inputs.templates_version }}" + echo "Custom Templates: ${{ inputs.custom_templates }}" echo "Repository: ${{ inputs.repository }}" echo "Ref: ${{ inputs.ref }}" echo "Specs Key: ${{ inputs.specs_key }}" @@ -102,14 +118,22 @@ jobs: transformations: ${{ inputs.transformations }} transformed_specs_key: ${{ inputs.transformed_specs_key }} + combine-templates: + uses: ./.github/workflows/selfserve-combine-templates.yaml + with: + base_templates: ${{ inputs.base_templates }} + version: ${{ inputs.templates_version }} + custom_templates: ${{ inputs.custom_templates }} + combined_templates_key: ${{ inputs.combined_templates_key }} + generate-sdk: uses: ./.github/workflows/selfserve-generate.yaml needs: [ transform-specs ] with: name: ${{ inputs.name }} version: ${{ inputs.version }} - templates: ${{ inputs.templates }} specs_key: ${{ inputs.transformed_specs_key }} + templates_key: ${{ inputs.combined_templates_key }} sdk_key: ${{ inputs.sdk_key }} publish-sources: diff --git a/.github/workflows/selfserve-generate.yaml b/.github/workflows/selfserve-generate.yaml index f3ac113b0..a892554cf 100644 --- a/.github/workflows/selfserve-generate.yaml +++ b/.github/workflows/selfserve-generate.yaml @@ -11,8 +11,8 @@ on: description: 'SDK Version' required: true type: string - templates: - description: 'Path to the templates directory' + templates_key: + description: 'Key to the combined templates artifact' required: true type: string specs_key: @@ -45,6 +45,11 @@ jobs: with: name: ${{ inputs.specs_key }} + - name: Download Templates + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.templates_key }} + - name: Set up JDK 21 uses: actions/setup-java@v4 with: @@ -53,12 +58,11 @@ jobs: - name: Generate Product SDK run: | - mvn -f sdk-repo/generator/openapi clean install exec:java "-Dnamespace=${{ inputs.name }}" -DsdkVersion=${{ inputs.version }} "-Dspec=./${{ inputs.specs_key }}.yaml" -DtemplatesDir=./${{ inputs.templates }} + mvn -f sdk-repo/generator/openapi clean install exec:java "-Dnamespace=${{ inputs.name }}" -DsdkVersion=${{ inputs.version }} "-Dspec=./${{ inputs.specs_key }}.yaml" -DtemplatesDir=./${{ inputs.templates_key }} - name: Install SDK - working-directory: sdk-repo/generator/openapi/target/sdk run: | - mvn clean install + mvn clean install -f sdk-repo/generator/openapi/target/sdk - name: Persist SDK Artifact uses: actions/upload-artifact@v4 @@ -67,6 +71,7 @@ jobs: path: | sdk-repo/generator/openapi/target/sdk !sdk-repo/generator/openapi/target/sdk/target + - name: Persist JAR Artifact # TODO: Remove when product config is proposed uses: actions/upload-artifact@v4 with: diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/README.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/README.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/README.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/README.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/api.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/api.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/api.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/api.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/client.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/client.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/client/apiParam.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client/apiParam.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/client/apiParam.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client/apiParam.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/client/apiParamsDecleration.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client/apiParamsDecleration.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/client/apiParamsDecleration.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client/apiParamsDecleration.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/client/apiParamsPassed.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client/apiParamsPassed.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/client/apiParamsPassed.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client/apiParamsPassed.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/client/paginatorMethods.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client/paginatorMethods.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/client/paginatorMethods.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/client/paginatorMethods.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/data_class.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/data_class.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/data_class.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/data_class.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/data_class_opt_var.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/data_class_opt_var.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/data_class_opt_var.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/data_class_opt_var.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/data_class_req_var.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/data_class_req_var.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/data_class_req_var.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/data_class_req_var.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/enum_class.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/enum_class.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/enum_class.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/enum_class.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/imports/core.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/imports/core.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/imports/core.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/imports/core.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/imports/defaults.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/imports/defaults.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/imports/defaults.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/imports/defaults.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/imports/domain.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/imports/domain.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/imports/domain.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/imports/domain.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/imports/helpers.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/imports/helpers.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/imports/helpers.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/imports/helpers.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/interface_opt_var.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/interface_opt_var.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/interface_opt_var.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/interface_opt_var.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/interface_req_var.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/interface_req_var.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/interface_req_var.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/interface_req_var.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/linkable_operation.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/linkable_operation.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/linkable_operation.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/linkable_operation.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/models/apiException.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/models/apiException.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/models/apiException.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/models/apiException.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/models/constraints.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/models/constraints.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/models/constraints.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/models/constraints.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/operation_context.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/operation_context.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/operation_context.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/operation_context.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/operation_params.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/operation_params.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/operation_params.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/operation_params.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/partials/authEndpoint.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/partials/authEndpoint.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/partials/authEndpoint.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/partials/authEndpoint.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/partials/clientBase.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/partials/clientBase.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/partials/clientBase.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/partials/clientBase.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/partials/clientConfiguration.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/partials/clientConfiguration.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/partials/clientConfiguration.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/partials/clientConfiguration.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/partials/helpers.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/partials/helpers.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/partials/helpers.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/partials/helpers.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/pom.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/pom.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/pom.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/pom.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/validation/propertyConstraintViolation.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/validation/propertyConstraintViolation.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/validation/propertyConstraintViolation.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/validation/propertyConstraintViolation.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/validation/propertyConstraintViolationException.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/validation/propertyConstraintViolationException.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/validation/propertyConstraintViolationException.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/validation/propertyConstraintViolationException.mustache diff --git a/generator/openapi/src/main/resources/templates/expediagroup-sdk/validation/propertyConstraintsValidator.mustache b/generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/validation/propertyConstraintsValidator.mustache similarity index 100% rename from generator/openapi/src/main/resources/templates/expediagroup-sdk/validation/propertyConstraintsValidator.mustache rename to generator/openapi/src/main/resources/templates/expediagroup-sdk/v1/validation/propertyConstraintsValidator.mustache