Skip to content

Commit

Permalink
chore(fix): resolved versioning issue to the swagger workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
saudkhan116 committed Apr 23, 2024
1 parent 3980aa7 commit 522bf9c
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions .github/workflows/publish-swagger-hub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ name: "Publish OpenAPI to Swaggerhub"

on:
push:
branches: [ "main", "develop" ]
branches: [ "main", "bugfix/fix-swagger-workflow" ]
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_call:
Expand Down Expand Up @@ -61,19 +61,15 @@ jobs:
run: |
npm i -g swaggerhub-cli
- name: Get version tag
- name: Extract version tag
id: version
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

- name: Set version tag
run: |
echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
if [ -z ${{ inputs.version }} ]; then
export DOWNSTREAM_VERSION=${{ steps.version.outputs.tag }}
echo "downstream_version=$tag" >> $GITHUB_OUTPUT
else
export DOWNSTREAM_VERSION=${{ inputs.version }}
echo "downstream_version=${{ inputs.version }}" >> $GITHUB_OUTPUT
fi
echo "[INFO] - DOWNSTREAM_VERSION=$DOWNSTREAM_VERSION" >> "$GITHUB_ENV"
- name: Create and Download API specs
shell: bash
Expand All @@ -96,16 +92,5 @@ jobs:
- name: Create API
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=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/${{ 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 }}
else
echo "[INFO] - snapshot, will set the API to 'unpublished'";
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/digital-product-pass/${{ env.DOWNSTREAM_VERSION }} -f ./dpp-backend/digitalproductpass/tractusx-dpp-api.yaml --visibility=public --published=unpublish
fi
DOWNSTREAM_VERSION=${{ steps.version.outputs.downstream_version }} >> "$GITHUB_ENV"
swaggerhub api:setdefault ${{ env.SWAGGERHUB_USER }}/digital-product-pass/$DOWNSTREAM_VERSION

0 comments on commit 522bf9c

Please sign in to comment.