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

feat: generate, merge and publish OpenAPI spec 2 #619

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .github/workflows/publish-new-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
95 changes: 95 additions & 0 deletions .github/workflows/publish-swaggerhub.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
16 changes: 13 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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 }}"
./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 ]
bcronin90 marked this conversation as resolved.
Show resolved Hide resolved
if: needs.secret-presence.output.HAS_SWAGGER
uses: ./.github/workflows/publish-swaggerhub.yaml
2 changes: 1 addition & 1 deletion .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ jobs:
run: |
pwd
./gradlew compileJava compileTestJava
./gradlew -p edc-tests/e2e-tests test -DincludeTags="MiwIntegrationTest" -PverboseTest=true
./gradlew -p edc-tests/e2e-tests test -DincludeTags="MiwIntegrationTest" -PverboseTest=true
12 changes: 0 additions & 12 deletions resources/openapi/yaml/edc-dataplane-proxy-provider-api.yaml

This file was deleted.

105 changes: 0 additions & 105 deletions resources/openapi/yaml/observability-api-customization.yaml

This file was deleted.