From 1d5dee239ba544e2009247b9bc0e9d967eefee8a Mon Sep 17 00:00:00 2001 From: bcronin90 <90203222+bcronin90@users.noreply.github.com> Date: Tue, 8 Aug 2023 13:01:51 +0200 Subject: [PATCH] feat: generate, merge and publish OpenAPI spec 2 (#619) * Automatically create API spec Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Bump Signed-off-by: Brendan Cronin * Allow for direct version input Signed-off-by: Brendan Cronin * Add Signed-off-by: Brendan Cronin * Test Signed-off-by: Brendan Cronin * Remove trigger Signed-off-by: Brendan Cronin * Add trigger Signed-off-by: Brendan Cronin * Remove trigger Signed-off-by: Brendan Cronin --------- Signed-off-by: Brendan Cronin --- .github/workflows/publish-new-release.yml | 7 ++ .github/workflows/publish-swaggerhub.yaml | 95 ++++++++++++++++ .github/workflows/publish.yaml | 16 ++- .github/workflows/verify.yaml | 2 +- .../edc-dataplane-proxy-provider-api.yaml | 12 -- .../yaml/observability-api-customization.yaml | 105 ------------------ 6 files changed, 116 insertions(+), 121 deletions(-) create mode 100644 .github/workflows/publish-swaggerhub.yaml delete mode 100644 resources/openapi/yaml/edc-dataplane-proxy-provider-api.yaml delete mode 100644 resources/openapi/yaml/observability-api-customization.yaml diff --git a/.github/workflows/publish-new-release.yml b/.github/workflows/publish-new-release.yml index 428b2065d..33fb23673 100644 --- a/.github/workflows/publish-new-release.yml +++ b/.github/workflows/publish-new-release.yml @@ -239,3 +239,10 @@ jobs: git commit --message "Introduce new snapshot version $SNAPSHOT_VERSION" git push origin main + + publish-to-swaggerhub: + name: "Publish OpenAPI spec to Swaggerhub" + permissions: + contents: read + needs: [ secret-presence ] + uses: ./.github/workflows/publish-swaggerhub.yaml diff --git a/.github/workflows/publish-swaggerhub.yaml b/.github/workflows/publish-swaggerhub.yaml new file mode 100644 index 000000000..e9e05f048 --- /dev/null +++ b/.github/workflows/publish-swaggerhub.yaml @@ -0,0 +1,95 @@ +# +# Copyright (c) 2023 Mercedes-Benz Tech Innovation GmbH +# Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +--- +name: "Publish OpenAPI to Swaggerhub" + +on: + workflow_call: + inputs: + downstream-version: + required: false + type: string + upstream-version: + required: false + type: string + +jobs: + swagger-api: + runs-on: ubuntu-latest + env: + SWAGGERHUB_API_KEY: ${{ secrets.SWAGGERHUB_API_KEY }} + SWAGGERHUB_USER: ${{ secrets.SWAGGERHUB_USER }} + steps: + - uses: actions/checkout@v3 + + - name: Setup JDK 17 + uses: actions/setup-java@v3.11.0 + with: + java-version: '17' + distribution: 'temurin' + cache: 'gradle' + + - name: Setup node + uses: actions/setup-node@v3 + + - name: Install tools + run: | + npm i -g swaggerhub-cli + + - name: Extract versions + run: | + if [ -z ${{ inputs.downstream-version }} ]; then + export DOWNSTREAM_VERSION=$(sed -nr "{ :l /^version[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" ./gradle.properties | tr -d ' ' | tr -d '"') + else + export DOWNSTREAM_VERSION=${{ inputs.downstream-version }} + fi + + if [ -z ${{ inputs.upstream-version }} ]; then + export UPSTREAM_VERSION=$(sed -nr "/^\[versions\]/ { :l /^edc[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" ./gradle/libs.versions.toml | tr -d ' ' | tr -d '"')-SNAPSHOT + else + export UPSTREAM_VERSION=${{ inputs.upstream-version }} + fi + + - name: Resolve TX EDC API Spec + shell: bash + run: | + ./gradlew :edc-extensions:dataplane-proxy:edc-dataplane-proxy-provider-api:resolve + ./gradlew :edc-extensions:dataplane-proxy:edc-dataplane-proxy-consumer-api:resolve + + - name: Download upstream API specs + run: | + swaggerhub api:get eclipse-edc-bot/management-api/${{ env.UPSTREAM_VERSION }} > resources/openapi/yaml/upstream-management-api.yaml + swaggerhub api:get eclipse-edc-bot/control-api/${{ env.UPSTREAM_VERSION }} > resources/openapi/yaml/upstream-control-api.yaml + + - name: Merge API specs + run: | + ./gradlew -PapiTitle="tractusx-edc-api" -PapiDescription="Tractus EDC API Doc" :mergeApiSpec --input=./resources/openapi/yaml --output=./resources/openapi/yaml/tractusx-edc-api.yaml + + # create API, will fail if exists + - name: Create API + continue-on-error: true + run: | + swaggerhub api:create ${{ env.SWAGGERHUB_USER }}/tractusx-edc/${{ env.DOWNSTREAM_VERSION }} -f ./resources/openapi/yaml/tractusx-edc-api.yaml --visibility=public --published=unpublish + + # Post the API to SwaggerHub as "unpublished", because published APIs cannot be overwritten + - name: Publish API Specs to SwaggerHub + run: | + swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/tractusx-edc/${{ env.DOWNSTREAM_VERSION }} -f ./resources/openapi/yaml/tractusx-edc-api.yaml --visibility=public --published=unpublish diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index dcd78346d..ded6ae2cc 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -50,6 +50,7 @@ jobs: outputs: DOCKER_HUB_TOKEN: ${{ steps.secret-presence.outputs.DOCKER_HUB_TOKEN }} HAS_OSSRH: ${{ steps.secret-presence.outputs.HAS_OSSRH }} + HAS_SWAGGER: ${{ steps.secret-presence.outputs.HAS_SWAGGER }} steps: - name: Check whether secrets exist id: secret-presence @@ -58,8 +59,9 @@ jobs: [ ! -z "${{ secrets.ORG_GPG_PASSPHRASE }}" ] && [ ! -z "${{ secrets.ORG_GPG_PRIVATE_KEY }}" ] && [ ! -z "${{ secrets.ORG_OSSRH_USERNAME }}" ] && - [ ! -z "${{ secrets.ORG_OSSRH_PASSWORD }}" ] && - echo "HAS_OSSRH=true" >> $GITHUB_OUTPUT + [ ! -z "${{ secrets.ORG_OSSRH_PASSWORD }}" ] && echo "HAS_OSSRH=true" >> $GITHUB_OUTPUT + [ ! -z "${{ secrets.SWAGGERHUB_API_KEY }}" ] && + [ ! -z "${{ secrets.SWAGGERHUB_USER }}" ] && echo "HAS_SWAGGER=true >> $GITHUB_OUTPUT exit 0 build-docker-images: @@ -126,4 +128,12 @@ jobs: cmd="closeAndReleaseSonatypeStagingRepository"; fi echo "Publishing Version $VERSION to Sonatype" - ./gradlew publishToSonatype ${cmd} --no-parallel -Pversion=$VERSION -Psigning.gnupg.executable=gpg -Psigning.gnupg.passphrase="${{ secrets.ORG_GPG_PASSPHRASE }}" \ No newline at end of file + ./gradlew publishToSonatype ${cmd} --no-parallel -Pversion=$VERSION -Psigning.gnupg.executable=gpg -Psigning.gnupg.passphrase="${{ secrets.ORG_GPG_PASSPHRASE }}" + + publish-to-swaggerhub: + name: "Publish OpenAPI spec to Swaggerhub" + permissions: + contents: read + needs: [ secret-presence ] + if: needs.secret-presence.output.HAS_SWAGGER + uses: ./.github/workflows/publish-swaggerhub.yaml diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml index 8ee57b0f7..b0b58f4a1 100644 --- a/.github/workflows/verify.yaml +++ b/.github/workflows/verify.yaml @@ -199,4 +199,4 @@ jobs: run: | pwd ./gradlew compileJava compileTestJava - ./gradlew -p edc-tests/e2e-tests test -DincludeTags="MiwIntegrationTest" -PverboseTest=true \ No newline at end of file + ./gradlew -p edc-tests/e2e-tests test -DincludeTags="MiwIntegrationTest" -PverboseTest=true diff --git a/resources/openapi/yaml/edc-dataplane-proxy-provider-api.yaml b/resources/openapi/yaml/edc-dataplane-proxy-provider-api.yaml deleted file mode 100644 index 1a55c51b7..000000000 --- a/resources/openapi/yaml/edc-dataplane-proxy-provider-api.yaml +++ /dev/null @@ -1,12 +0,0 @@ -openapi: 3.0.1 -paths: - /gateway/{paths}: - get: - operationId: requestAsset - responses: - default: - content: - application/json: {} - description: Gets asset data - tags: - - Data Plane Proxy API diff --git a/resources/openapi/yaml/observability-api-customization.yaml b/resources/openapi/yaml/observability-api-customization.yaml deleted file mode 100644 index 063a3122a..000000000 --- a/resources/openapi/yaml/observability-api-customization.yaml +++ /dev/null @@ -1,105 +0,0 @@ -openapi: 3.0.1 -paths: - /check/health: - get: - description: Performs a health check to determine whether the runtime is working - properly. - operationId: checkHealth - responses: - "200": - content: - application/json: - schema: - type: array - example: null - items: - $ref: '#/components/schemas/HealthStatus' - tags: - - Application Observability - /check/liveness: - get: - description: Performs a liveness probe to determine whether the runtime is working - properly. - operationId: getLiveness - responses: - "200": - content: - application/json: - schema: - type: array - example: null - items: - $ref: '#/components/schemas/HealthStatus' - tags: - - Application Observability - /check/readiness: - get: - description: Performs a readiness probe to determine whether the runtime is - able to accept requests. - operationId: getReadiness - responses: - "200": - content: - application/json: - schema: - type: array - example: null - items: - $ref: '#/components/schemas/HealthStatus' - tags: - - Application Observability - /check/startup: - get: - description: Performs a startup probe to determine whether the runtime has completed - startup. - operationId: getStartup - responses: - "200": - content: - application/json: - schema: - type: array - example: null - items: - $ref: '#/components/schemas/HealthStatus' - tags: - - Application Observability -components: - schemas: - Failure: - type: object - example: null - properties: - failureDetail: - type: string - example: null - messages: - type: array - example: null - items: - type: string - example: null - HealthCheckResult: - type: object - example: null - properties: - component: - type: string - example: null - failure: - $ref: '#/components/schemas/Failure' - isHealthy: - type: boolean - example: null - HealthStatus: - type: object - example: null - properties: - componentResults: - type: array - example: null - items: - $ref: '#/components/schemas/HealthCheckResult' - isSystemHealthy: - type: boolean - example: null