Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add self serve action to enable specs based service virtualization #715

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
9ee9b80
chore: test
OmarAlJarrah Sep 3, 2024
2b8aa78
chore: test
OmarAlJarrah Sep 3, 2024
68ff4a7
chore: test
OmarAlJarrah Sep 3, 2024
ec318f2
chore: test
OmarAlJarrah Sep 3, 2024
0d312c0
chore: test
OmarAlJarrah Sep 3, 2024
19d6bf6
chore: test
OmarAlJarrah Sep 3, 2024
58e7fb4
chore: test
OmarAlJarrah Sep 3, 2024
1c151a6
chore: test
OmarAlJarrah Sep 3, 2024
af962f7
Merge branch 'main' into OmarAlJarrah/add-service-mock-server-action
OmarAlJarrah Sep 24, 2024
2e5bb2c
Merge branch 'main' into OmarAlJarrah/add-service-mock-server-action
OmarAlJarrah Sep 25, 2024
571b3f4
Merge branch 'main' into OmarAlJarrah/add-service-mock-server-action
OmarAlJarrah Sep 26, 2024
459cff5
chore: add workflow to generate and upload contract test sources
OmarAlJarrah Sep 29, 2024
c4a2f73
chore: remove old workflow and add updated mock tests workflow
OmarAlJarrah Sep 29, 2024
e9744d1
chore: refactor workflows to consolidate spec handling and SDK genera…
OmarAlJarrah Sep 29, 2024
aaff1ba
chore: add secrets configuration to workflow
OmarAlJarrah Sep 29, 2024
c8e740a
chore: update dependencies for generate-contract-tests workflow
OmarAlJarrah Sep 29, 2024
d2f3ff2
chore: add SDK generator module installation step
OmarAlJarrah Sep 29, 2024
571a6b5
chore: add Java 21 setup to workflow
OmarAlJarrah Sep 29, 2024
e8ec99e
chore: update path for specs.yaml file in workflow
OmarAlJarrah Sep 29, 2024
25b82f0
Merge branch 'main' into OmarAlJarrah/add-service-mock-server-action
OmarAlJarrah Sep 29, 2024
6cfcc53
chore: update path for specs.yaml file in workflow
OmarAlJarrah Sep 29, 2024
a54dc6e
chore: update paths in GitHub Actions workflows
OmarAlJarrah Sep 29, 2024
e1ec168
chore: update paths in GitHub workflow
OmarAlJarrah Sep 29, 2024
c6bc86d
chore: update CLI and workflow for target artifact metadata
OmarAlJarrah Sep 29, 2024
cc7e29a
chore: update run-tests workflow to include sdk_artifact_id
OmarAlJarrah Sep 29, 2024
0f6deaa
chore: add temporary test step for debugging
OmarAlJarrah Sep 29, 2024
3bbb1f1
chore: update test artifact upload key in CI workflow
OmarAlJarrah Sep 29, 2024
ca1be62
chore: update artifact name in GitHub Action
OmarAlJarrah Sep 29, 2024
822a90c
chore: rename job in GitHub Actions workflow
OmarAlJarrah Sep 29, 2024
5128571
chore: Add file listing for debugging in GitHub workflow
OmarAlJarrah Sep 29, 2024
6feb151
chore: update test source generation command
OmarAlJarrah Sep 29, 2024
0978535
chore: streamline test source generation step
OmarAlJarrah Sep 29, 2024
fa59e2f
chore: fix path in GitHub Actions upload artifact step
OmarAlJarrah Sep 29, 2024
37c865b
chore: update workflow artifact input handling
OmarAlJarrah Sep 30, 2024
d974f1a
chore: enhance workflow debug and artifact naming
OmarAlJarrah Sep 30, 2024
fdfe8cd
chore: update artifact upload path in CI workflow
OmarAlJarrah Sep 30, 2024
669467d
chore: update test command to include secrets
OmarAlJarrah Sep 30, 2024
a174a93
chore: update artifact path in GitHub Actions workflow
OmarAlJarrah Sep 30, 2024
95c59db
chore: update artifact upload path in GitHub workflow
OmarAlJarrah Sep 30, 2024
a11424a
chore: update test workflow directory path
OmarAlJarrah Sep 30, 2024
84b5360
chore: update test run steps in GitHub workflow
OmarAlJarrah Sep 30, 2024
216387d
chore: add directory listing before running tests
OmarAlJarrah Sep 30, 2024
2d7d12e
chore: update test directory path in CI workflow
OmarAlJarrah Sep 30, 2024
dfc28bb
chore: update test directory path in CI workflow
OmarAlJarrah Sep 30, 2024
c3605a2
chore: add Guava dependency and update file resource path
OmarAlJarrah Sep 30, 2024
be1ff12
chore: simplify GitHub workflow configurations
OmarAlJarrah Sep 30, 2024
e9ca5e9
chore: update JSON deserialization method in executor template
OmarAlJarrah Sep 30, 2024
cadf74e
chore: remove debug command and add JSON deserialization annotation
OmarAlJarrah Sep 30, 2024
72e5770
chore: add Jackson deserialization annotation to data class template
OmarAlJarrah Sep 30, 2024
b17bd65
chore: remove JsonDeserialize annotation from data class template
OmarAlJarrah Sep 30, 2024
294f8cc
chore: configure Jackson deserialization in templates
OmarAlJarrah Oct 1, 2024
1ae1162
chore: add imports for Jackson Kotlin features
OmarAlJarrah Oct 1, 2024
fa9c8d9
chore: add imports for Jackson Kotlin features
OmarAlJarrah Oct 1, 2024
dba239c
chore: simplify jacksonObjectMapper initialization
OmarAlJarrah Oct 1, 2024
566931a
chore: Add @JvmStatic annotations to singleton objects
OmarAlJarrah Oct 1, 2024
e6769af
chore: enhance request deserialization logic
OmarAlJarrah Oct 1, 2024
faeb164
chore: update endpoint URL scheme in executor.mustache
OmarAlJarrah Oct 1, 2024
46dc2a6
chore: update Java version in workflow and add missing setup
OmarAlJarrah Oct 1, 2024
d7f0609
chore: add spec transformation step and remove mapdb dependency
OmarAlJarrah Oct 1, 2024
e8aaf81
chore: add Node.js setup in GitHub workflow
OmarAlJarrah Oct 1, 2024
588fea9
chore: update download path in GitHub workflow
OmarAlJarrah Oct 1, 2024
f25f64a
Merge branch 'main' into OmarAlJarrah/add-service-mock-server-action
anssari1 Oct 2, 2024
33885cb
chore: add JavaTimeModule registration in executor
OmarAlJarrah Oct 2, 2024
f9000b4
chore: add @JsonProperty annotation to enum variables
OmarAlJarrah Oct 2, 2024
b2ff0ba
chore: add file to inputStream type mapping
OmarAlJarrah Oct 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .github/workflows/generator-test-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,7 @@ on:
value: ${{ jobs.sdk-metadata.outputs.version }}

jobs:
download-specs:
uses: ./.github/workflows/generator-download-specs.yaml
with:
url: ${{ inputs.specs_url }}

transform-specs:
needs: [ download-specs ]
uses: ./.github/workflows/selfserve-transform-specs.yaml
with:
specs_key: 'raw-specs'
transformations: -th -te ${{ inputs.endpoint_prefix }} --operationIdsToTags

upload-templates:
uses: ./.github/workflows/selfserve-checkout-and-upload.yaml
with:
artifact_key: 'templates'
artifact_path: 'generator/openapi/src/main/resources/templates/expediagroup-sdk'
repository: 'ExpediaGroup/expediagroup-java-sdk'
ref: "${{ github.head_ref || github.ref_name }}"

upload-repo:
uses: ./.github/workflows/selfserve-checkout-and-upload.yaml
with:
artifact_key: 'sdk-repo'
artifact_path: ''
repository: 'ExpediaGroup/expediagroup-java-sdk'
ref: "${{ github.head_ref || github.ref_name }}"

generate-sdk:
needs: [ transform-specs, upload-repo ]
uses: ./.github/workflows/selfserve-generate-sdk.yaml
with:
name: ${{ inputs.namespace }}
Expand Down
86 changes: 78 additions & 8 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ on:
default: ''
sdk_version:
description: 'Run tests based on SDK'
required: false
type: string
default: 'LATEST'
sdk_namespace:
description: 'SDK to test'
required: true
type: string
default: 'rapid'
sdk_artifact_id:
description: 'SDK artifactId'
type: string
default: 'rapid-sdk'
endpoint_prefix:
description: 'Endpoint to prepend specs paths with'
required: true
Expand All @@ -42,7 +44,7 @@ on:
workflow_call:
inputs:
source:
description: 'Source of tests'
description: 'Source of tests. Can be `sdk` or `specs`'
required: true
type: string
default: 'sdk'
Expand All @@ -58,9 +60,12 @@ on:
default: 'LATEST'
sdk_namespace:
description: 'SDK to test'
required: true
type: string
default: 'rapid'
sdk_artifact_id:
description: 'SDK artifactId'
type: string
default: 'rapid-sdk'
endpoint_prefix:
description: 'Endpoint to prepend specs paths with'
required: true
Expand All @@ -80,26 +85,91 @@ jobs:
print('::error::Invalid SDK version: ${{ inputs.sdk_version }}')
exit(1)

download-specs:
uses: ./.github/workflows/generator-download-specs.yaml
with:
url: ${{ inputs.specs_url }}

transform-and-upload-specs:
needs: [ download-specs ]
uses: ./.github/workflows/selfserve-transform-specs.yaml
with:
specs_key: 'raw-specs'
transformations: -th -te ${{ inputs.endpoint_prefix }} --operationIdsToTags

upload-templates:
uses: ./.github/workflows/selfserve-checkout-and-upload.yaml
with:
artifact_key: 'templates'
artifact_path: 'generator/openapi/src/main/resources/templates/expediagroup-sdk'
repository: 'ExpediaGroup/expediagroup-java-sdk'
ref: "${{ github.head_ref || github.ref_name }}"

upload-test-templates:
uses: ./.github/workflows/selfserve-checkout-and-upload.yaml
with:
artifact_key: 'test-templates'
artifact_path: 'sdk-test/src/main/resources/templates/expediagroup-sdk'
repository: 'ExpediaGroup/expediagroup-java-sdk'
ref: "${{ github.head_ref || github.ref_name }}"

upload-repo:
uses: ./.github/workflows/selfserve-checkout-and-upload.yaml
with:
artifact_key: 'sdk-repo'
artifact_path: ''
repository: 'ExpediaGroup/expediagroup-java-sdk'
ref: "${{ github.head_ref || github.ref_name }}"

generate-test-sdk:
if: inputs.source == 'specs'
needs: [ inputs-validation ]
needs: [ inputs-validation, transform-and-upload-specs, upload-templates, upload-repo ]
uses: ./.github/workflows/generator-test-sdk.yaml
with:
version: ${{ inputs.sdk_version }}
namespace: ${{ inputs.sdk_namespace }}
endpoint_prefix: ${{ inputs.endpoint_prefix }}
specs_url: ${{ inputs.specs_url }}
secrets: inherit

generate-contract-tests:
needs: [ inputs-validation, generate-test-sdk ]
uses: ./.github/workflows/selfserve-generate-contract-test-sources.yaml
with:
artifact_key: 'sdk-test'
repo_key: 'sdk-repo'
templates_key: 'test-templates'
specs_key: 'transformedSpecs'
namespace: ${{ inputs.sdk_namespace }}
generation_options: '--version 0.0.1 --target-group com.expediagroup --target-artifact ${{ inputs.sdk_artifact_id }} --target-version ${{ inputs.sdk_version }} -m 5' # TODO: remove -m param

run-rapid-examples:
strategy:
matrix:
jdk: [8, 11, 17, 21]
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') && inputs.sdk_namespace == 'rapid'
needs: [ generate-test-sdk ]
uses: "ExpediaGroup/rapid-java-sdk/.github/workflows/run-examples.yaml@main"
with:
source: 'specs'
sdk_version: ${{ needs.generate-test-sdk.outputs.version }}
jdk: ${{ matrix.jdk }}
secrets:
KEY: ${{ secrets.RAPID_KEY }}
SECRET: ${{ secrets.RAPID_SECRET }}
strategy:
matrix:
jdk: [ 8, 11, 17, 21 ]

run-rapid-contract-tests:
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') && inputs.sdk_namespace == 'rapid'
needs: [ generate-contract-tests ]
uses: ./.github/workflows/selfserve-run-mocked-service-tests.yaml
with:
specs_key: 'transformedSpecs'
test_sources_key: 'sdk-test'
sdk_key: 'sdk'
jdk: ${{ matrix.jdk }}
secrets:
KEY: ${{ secrets.RAPID_KEY }}
SECRET: ${{ secrets.RAPID_SECRET }}
strategy:
matrix:
jdk: [ 8, 11, 17, 21 ]
69 changes: 69 additions & 0 deletions .github/workflows/selfserve-generate-contract-test-sources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Generate & Upload Tests Sources

on:
workflow_call:
inputs:
artifact_key:
description: 'Generated output artifact key. Defaults to `sdk-test`'
type: string
default: 'sdk-test'
repo_key:
description: 'SDK repository artifact key'
type: string
templates_key:
description: 'Templates artifact key'
type: string
required: true
specs_key:
description: 'Specs artifact key'
type: string
required: true
namespace:
description: 'Namespace of the product'
type: string
required: true
generation_options:
description: 'Options to pass to the generator. Includes `--version` and `--max-test-combinations`'
type: string
required: true

jobs:
generate-and-upload-contract-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'corretto'

- name: Download Repository
uses: actions/download-artifact@v4
with:
name: ${{ inputs.repo_key }}
path: sdk-repo

- name: Download Templates
uses: actions/download-artifact@v4
with:
name: ${{ inputs.templates_key }}
path: templates

- name: Download Specs
uses: actions/download-artifact@v4
with:
name: ${{ inputs.specs_key }}
path: specs

- name: Install SDK Generator Module
working-directory: sdk-repo/generator/openapi
run: mvn clean install
continue-on-error: true

- name: Generate Test Sources
run: mvn -f sdk-repo/sdk-test clean install exec:java -Dexec.args="--input-spec specs/${{ inputs.specs_key }}.yaml --templates-dir templates --namespace ${{ inputs.namespace }} ${{ inputs.generation_options }}"

- name: Upload Generated Sources
uses: actions/upload-artifact@v4
with:
path: target/sdk/*-sdk-test/**
name: ${{ inputs.artifact_key }}
99 changes: 99 additions & 0 deletions .github/workflows/selfserve-run-mocked-service-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: SelfServe Run Service Mocked Tests
on:
workflow_call:
inputs:
specs_key:
description: 'Specs artifact key. Defaults to `specs`'
type: string
default: 'transformedSpecs'
required: true
test_sources_key:
description: 'Test sources artifact key. Defaults to `sdk-test`'
type: string
default: 'sdk-test'
required: true
sdk_key:
description: 'SDK artifact key to download'
type: string
required: false
default: ''
jdk:
description: 'JDK version to use'
type: string
default: '21'
secrets:
KEY:
description: 'API Key'
required: true
SECRET:
description: 'API Key'
required: true

jobs:
run-tests-with-mocked-service:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'corretto'

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.18.2

- name: Download Specs
uses: actions/download-artifact@v4
with:
name: ${{ inputs.specs_key }}
path: specs

- name: Transform Specs
working-directory: specs
run: npx --yes -p @expediagroup/spec-transformer cli -i ${{ inputs.specs_key }}.yaml -o ${{ inputs.specs_key }}.yaml -to

- name: Download Test Sources Artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.test_sources_key }}
path: test

- name: Download SDK Artifact
if: inputs.sdk_key != ''
uses: actions/download-artifact@v4
with:
name: ${{ inputs.sdk_key }}
path: sdk

- name: Install SDK into Local Repository
if: inputs.sdk_key != ''
working-directory: sdk
run: mvn clean install

- name: Download Latest Specmatic Executable
working-directory: specs
run: |
curl -s https://api.github.com/repos/znsio/specmatic/releases/latest \
| grep "browser_download_url.*specmatic.jar" \
| cut -d : -f 2,3 \
| tr -d \" \
| xargs curl -L -o specmatic.jar

- name: Run Mock Server
working-directory: specs
run: java -jar specmatic.jar stub ${{ inputs.specs_key }}.yaml --port 8080 & disown

- uses: actions/setup-java@v4
with:
java-version: ${{ inputs.jdk }}
distribution: 'corretto'

- name: Wait for Mock Server to Start
run: sleep 10

- name: Run Tests
working-directory: test
run: |
cd $(find . -type d -name "*-sdk-test" -print -quit)
mvn clean install exec:java -Dsdk.key="${{ secrets.KEY }}" -Dsdk.secret="${{ secrets.SECRET }}"
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class OpenApiSdkGenerator {
if (ProductFamily.isRapid(product.namespace)) {
rapidHelpers.forEach { (name, function) -> addAdditionalProperty(name, function()) }
}

addTypeMapping("java.io.File", "java.io.InputStream")
}

val generatorInput =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
) {
{{#allowableValues}}
{{#enumVars}}
@JsonProperty({{{value}}})
{{name}}({{{value}}})
{{^-last}},{{/-last}}
{{/enumVars}}
Expand Down
Loading
Loading