chore(fix): resolved versioning issue to the swagger workflow #97
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################# | |
# Tractus-X - Digital Product Passport Application | |
# | |
# Copyright (c) 2022, 2024 BASF SE, BMW AG, Henkel AG & Co. KGaA | |
# 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: | |
branches: [ "main", "bugfix/fix-swagger-workflow" ] | |
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 }} | |
DOWNSTREAM_VERSION: '' | |
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: Get version tag | |
id: version | |
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT | |
- name: Set version tag | |
run: | | |
if [ -z ${{ inputs.version }} ]; then | |
DOWNSTREAM_VERSION=${{ steps.version.outputs.tag }} | |
else | |
DOWNSTREAM_VERSION=${{ inputs.version }} | |
fi | |
echo "[INFO] - 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 API | |
continue-on-error: true | |
run: | | |
swaggerhub api:create ${{ env.SWAGGERHUB_USER }}/digital-product-pass/$DOWNSTREAM_VERSION -f ./dpp-backend/digitalproductpass/tractusx-dpp-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: | | |
if [[ ${{ env.DOWNSTREAM_VERSION }} != *-SNAPSHOT ]]; then | |
echo "[INFO] - no snapshot, will set the API to 'published'"; | |
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/digital-product-pass/$DOWNSTREAM_VERSION -f ./dpp-backend/digitalproductpass/tractusx-dpp-api.yaml --visibility=public --published=publish | |
swaggerhub api:setdefault ${{ env.SWAGGERHUB_USER }}/digital-product-pass/$DOWNSTREAM_VERSION | |
else | |
echo "[INFO] - snapshot, will set the API to 'unpublished'"; | |
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/digital-product-pass/$DOWNSTREAM_VERSION -f ./dpp-backend/digitalproductpass/tractusx-dpp-api.yaml --visibility=public --published=unpublish | |
fi |