-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from eclipse-tractusx/feature/swaggerhub-work…
…flow [ 11º ] - Feature/swaggerhub workflow: Prepared workflow to host backend API specs to the central swaggerhub
- Loading branch information
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
################################################################################# | ||
# Catena-X - Product Passport Consumer Application | ||
# | ||
# Copyright (c) 2022, 2023 BASF SE, BMW AG, Henkel AG & Co. KGaA | ||
# | ||
# 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: "Setup Java 19" | ||
description: "Setup Java 19" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Setup Java | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '19' | ||
distribution: 'adopt' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
################################################################################# | ||
# Catena-X - Product Passport Consumer Application | ||
# | ||
# Copyright (c) 2022, 2023 BASF SE, BMW AG, Henkel AG & Co. KGaA | ||
# | ||
# 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", "develop" ] | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' | ||
workflow_call: | ||
inputs: | ||
version: | ||
required: false | ||
default: 'main' | ||
type: string | ||
|
||
workflow_dispatch: | ||
inputs: | ||
version: | ||
required: false | ||
description: "Version of the DPP API is to be published" | ||
default: 'main' | ||
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 versions | ||
run: | | ||
export DOWNSTREAM_VERSION=${{ inputs.version }} | ||
echo "[INFO] - DOWNSTREAM_VERSION=$DOWNSTREAM_VERSION" >> "$GITHUB_ENV" | ||
- name: Create and Download API specs | ||
shell: bash | ||
run: | | ||
cd backend/productpass | ||
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 8 | ||
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/${{ env.DOWNSTREAM_VERSION }} -f ./backend/productpass/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 ./backend/productpass/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 ./backend/productpass/tractusx-dpp-api.yaml --visibility=public --published=unpublish | ||
fi |