diff --git a/.github/workflows/generator-download-specs.yml b/.github/workflows/generator-download-specs.yml new file mode 100644 index 000000000..e79f1ac25 --- /dev/null +++ b/.github/workflows/generator-download-specs.yml @@ -0,0 +1,20 @@ +name: Download API Specs +on: + workflow_call: + inputs: + url: + description: 'URL to download API specs from' + required: true + type: string + +jobs: + download_specs: + runs-on: ubuntu-latest + steps: + - id: download_specs + run: | + curl -L ${{ inputs.url }} -o raw-specs.yaml + - uses: actions/upload-artifact@v3 + with: + name: raw-specs + path: raw-specs.yaml diff --git a/.github/workflows/generator-generate.yml b/.github/workflows/generator-generate.yml index bdf696a16..a22dabdf6 100644 --- a/.github/workflows/generator-generate.yml +++ b/.github/workflows/generator-generate.yml @@ -2,16 +2,12 @@ name: Generate SDK - Generate on: workflow_call: inputs: - version: - description: 'generated sdk version' - required: true - type: string name: - description: 'generated sdk name' + description: 'SDK Name' required: true type: string - fileAsBase64: - description: 'generated sdk file as base64 encoded' + version: + description: 'SDK Version' required: true type: string jobs: @@ -27,11 +23,15 @@ jobs: - id: build working-directory: generator run: mvn clean install + - uses: actions/download-artifact@v3 + with: + name: specs + path: generator/openapi - name: generate working-directory: generator/openapi run: | mvn clean install - mvn exec:java "-Dnamespace=${{ inputs.name }}" -DsdkVersion=${{ inputs.version }} "-Dspec=${{ inputs.fileAsBase64 }}" + mvn exec:java "-Dnamespace=${{ inputs.name }}" -DsdkVersion=${{ inputs.version }} "-Dspec=./specs.yaml" - uses: actions/upload-artifact@v3 with: name: sdk diff --git a/.github/workflows/generator-main.yml b/.github/workflows/generator-main.yml index 22020a468..30490e2eb 100644 --- a/.github/workflows/generator-main.yml +++ b/.github/workflows/generator-main.yml @@ -2,35 +2,50 @@ name: Generate SDK - Main on: workflow_dispatch: inputs: + name: + description: 'SDK Name' + required: true version: - description: 'Generated SDK version' + description: 'SDK Version' required: false default: '' - name: - description: 'Generated SDK name' - required: true - fileAsBase64: - description: 'Generated SDK file as base64 encoded' + specs_url: + description: 'URL to download API specs from' required: true + type: string test: - description: 'Release snapshot?' + description: 'Release a Snapshot? (Leave blank for no, anything else for yes)' required: false jobs: prepare_version: uses: ./.github/workflows/generator-prepare-version.yml with: - version: ${{ github.event.inputs.version }} name: ${{ github.event.inputs.name }} + version: ${{ github.event.inputs.version }} + download_specs: + uses: ./.github/workflows/generator-download-specs.yml + with: + url: ${{ github.event.inputs.specs_url }} + transform_specs: + needs: [ download_specs ] + uses: ./.github/workflows/generator-transform-specs.yml + with: + configurations: -th -te -tt ${{ github.event.inputs.name }} generate: - needs: [ prepare_version ] + needs: [ prepare_version, transform_specs ] uses: ./.github/workflows/generator-generate.yml with: - version: ${{ needs.prepare_version.outputs.version }} name: ${{ github.event.inputs.name }} - fileAsBase64: ${{ github.event.inputs.fileAsBase64 }} - publish: + version: ${{ needs.prepare_version.outputs.version }} + publish_sources: needs: [ generate ] - uses: ./.github/workflows/generator-publish.yml + uses: ./.github/workflows/generator-publish-sources.yml + with: + name: ${{ github.event.inputs.name }} + version: ${{ github.event.inputs.version }} + publish_artifact: + needs: [ publish_sources ] + uses: ./.github/workflows/generator-publish-artifact.yml secrets: inherit with: test: ${{ github.event.inputs.test }} diff --git a/.github/workflows/generator-prepare-version.yml b/.github/workflows/generator-prepare-version.yml index 239b08062..6c7d72f08 100644 --- a/.github/workflows/generator-prepare-version.yml +++ b/.github/workflows/generator-prepare-version.yml @@ -2,10 +2,10 @@ name: Generate SDK - Prepare Version on: workflow_call: inputs: - version: + name: required: true type: string - name: + version: required: true type: string outputs: diff --git a/.github/workflows/generator-publish.yml b/.github/workflows/generator-publish-artifact.yml similarity index 99% rename from .github/workflows/generator-publish.yml rename to .github/workflows/generator-publish-artifact.yml index 7016f43e0..7fc762687 100644 --- a/.github/workflows/generator-publish.yml +++ b/.github/workflows/generator-publish-artifact.yml @@ -7,7 +7,7 @@ on: type: string required: false jobs: - job: + publish: runs-on: ubuntu-latest outputs: version: ${{ steps.publish.outputs.version }} diff --git a/.github/workflows/generator-publish-sources.yml b/.github/workflows/generator-publish-sources.yml new file mode 100644 index 000000000..14cebf713 --- /dev/null +++ b/.github/workflows/generator-publish-sources.yml @@ -0,0 +1,46 @@ +name: Generate and Publish Sources +on: + workflow_call: + inputs: + name: + description: 'SDK Name' + required: true + type: string + version: + description: 'SDK Version' + required: true + type: string + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: sdk + path: generator/sdk + - uses: actions/download-artifact@v3 + with: + name: specs + path: generator/sdk + - name: Publish Code + working-directory: generator/sdk + run: | + git config --global user.email "oss@expediagroup.com" + git config --global user.name "Expedia Group Open Source" + rm -rf ../../release/"${{github.event.inputs.name}}" + mkdir -p ../../release/"${{github.event.inputs.name}}" + cp -r ./src ../../release/"${{github.event.inputs.name}}"/ + cp ./pom.xml ../../release/"${{github.event.inputs.name}}"/ + cp ./README.md ../../release/"${{github.event.inputs.name}}"/ + cp ./specs.yaml ../../release/"${{github.event.inputs.name}}"/specs.yaml + git checkout main + git pull + git checkout -b "${{github.event.inputs.name}}-${{github.event.inputs.version}}" + git add ../../release/\* + git commit -m "chore: Publish ${{github.event.inputs.name}} [${{github.event.inputs.version}}] SDK" + git push --set-upstream origin "${{github.event.inputs.name}}-${{github.event.inputs.version}}" + gh pr create -B main -H "${{github.event.inputs.name}}-${{github.event.inputs.version}}" --title 'chore: Publish ${{github.event.inputs.name}} [${{github.event.inputs.version}}] SDK' --fill + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/generator-transform-specs.yml b/.github/workflows/generator-transform-specs.yml new file mode 100644 index 000000000..d14367a26 --- /dev/null +++ b/.github/workflows/generator-transform-specs.yml @@ -0,0 +1,22 @@ +name: Transform Specs +on: + workflow_call: + inputs: + configurations: + description: 'Spec Transformer CLI Configurations' + type: string + required: true + +jobs: + transform-specs: + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + with: + name: raw-specs + - run: | + npx --yes -p @expediagroup/spec-transformer cli ${{ inputs.configurations }} -i raw-specs.yaml -o specs.yaml + - uses: actions/upload-artifact@v3 + with: + name: specs + path: specs.yaml diff --git a/.github/workflows/generator-verify.yml b/.github/workflows/generator-verify.yml index 0a2bab07f..2ea912476 100644 --- a/.github/workflows/generator-verify.yml +++ b/.github/workflows/generator-verify.yml @@ -24,7 +24,7 @@ jobs: run: | mvn clean install mvn exec:java "-Dnamespace=exemplar" "-DsdkVersion=1.0.0" "-Dspec=./src/test/resources/exemplar.yaml" - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: sdk path: generator/openapi/target/sdk @@ -32,7 +32,7 @@ jobs: runs-on: ubuntu-latest needs: generate-sdk steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: sdk path: generator/sdk