Skip to content

Publish OpenAPI to Swaggerhub #126

Publish OpenAPI to Swaggerhub

Publish OpenAPI to Swaggerhub #126

#################################################################################
# Tractus-X - Digital Product Passport Application
#
# Copyright (c) 2022, 2024 BMW AG, Henkel AG & Co. KGaA
# Copyright (c) 2023, 2024 CGI Deutschland B.V. & Co. KG
# Copyright (c) 2022, 2024 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 govern in permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
#################################################################################
---
name: "Publish OpenAPI to Swaggerhub"
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_call:
inputs:
version:
required: false
type: string
workflow_dispatch:
inputs:
version:
required: false
description: "Version of the DPP API is to be published"
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@v4
- uses: ./.github/actions/setup-java
- name: Setup node
uses: actions/setup-node@v4
- name: Install Swagger CLI
run: |
npm i -g swaggerhub-cli
- name: Extract version tag
id: version
run: |
echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
if [ -z ${{ inputs.version }} ]; then
export DOWNSTREAM_VERSION=${GITHUB_REF#refs/*/}
else
export DOWNSTREAM_VERSION=${{ inputs.version }}
fi
echo "DOWNSTREAM_VERSION=$DOWNSTREAM_VERSION" >> "$GITHUB_ENV"
- name: Create and Download API specs
shell: bash
run: |
cd dpp-backend/digitalproductpass
echo "[INFO] - Compiling the backend"
mvn -B clean install
echo "[INFO] - Building a docker image - backend:test"
docker build . --tag dpp-backend:test
echo "[INFO] - Starting a docker container to download API specs - test-container"
docker run -p 8888:8888 --name test-container -d dpp-backend:test
echo "[INFO] - Wait for some seconds until the docker container comes up"
sleep 20
curl -X GET http://localhost:8888/v3/api-docs.yaml > ./tractusx-dpp-api.yaml
echo "[INFO] - Stopping and removing docker container"
docker stop test-container
docker rm test-container
# create API, will fail if exists
- name: Create and publish API Specs to SwaggerHub
continue-on-error: true
run: |
swaggerhub api:create ${{ env.SWAGGERHUB_USER }}/digital-product-pass/${{ env.DOWNSTREAM_VERSION }} -f ./dpp-backend/digitalproductpass/tractusx-dpp-api.yaml --visibility=public --published=publish
swaggerhub api:setdefault ${{ env.SWAGGERHUB_USER }}/digital-product-pass/${{ env.DOWNSTREAM_VERSION }}