-
Notifications
You must be signed in to change notification settings - Fork 54
101 lines (85 loc) · 4.05 KB
/
publish-swaggerhub.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#################################################################################
# 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
#################################################################################
# DEPRECATED: openapi are published on github-pages now, please look at publish-openapi-ui
---
name: "Publish OpenAPI to Swaggerhub"
on:
workflow_call:
inputs:
downstream-version:
required: false
type: string
workflow_dispatch:
inputs:
downstream-version:
required: false
description: "Version of the Tractus-X EDC API to be should 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
run: |
if [ -z ${{ inputs.downstream-version }} ]; then
export DOWNSTREAM_VERSION=$(grep "version" gradle.properties | awk -F= '{print $2}')
else
export DOWNSTREAM_VERSION=${{ inputs.downstream-version }}
fi
echo "DOWNSTREAM_VERSION=$DOWNSTREAM_VERSION" >> "$GITHUB_ENV"
- name: Resolve TX EDC API Spec
shell: bash
run: |
./gradlew resolve
- name: Download upstream API specs for control-plane and data-plane
run: |
./gradlew :edc-controlplane:edc-controlplane-base:downloadOpenapi
cp edc-controlplane/edc-controlplane-base/build/docs/openapi/* resources/openapi/yaml/
./gradlew :edc-dataplane:edc-dataplane-base:downloadOpenapi
cp edc-dataplane/edc-dataplane-base/build/docs/openapi/* resources/openapi/yaml/
- name: Merge API specs
run: |
./gradlew -PapiTitle="Tractus-X EDC REST API" -PapiDescription="Tractus-X EDC API Documentation" :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: |
if [[ ${{ env.DOWNSTREAM_VERSION }} != *-SNAPSHOT ]]; then
echo "no snapshot, will set the API to 'published'";
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/tractusx-edc/${{ env.DOWNSTREAM_VERSION }} -f ./resources/openapi/yaml/tractusx-edc-api.yaml --visibility=public --published=publish
swaggerhub api:setdefault ${{ env.SWAGGERHUB_USER }}/tractusx-edc/${{ env.DOWNSTREAM_VERSION }}
else
echo "snapshot, will set the API to 'unpublished'";
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/tractusx-edc/${{ env.DOWNSTREAM_VERSION }} -f ./resources/openapi/yaml/tractusx-edc-api.yaml --visibility=public --published=unpublish
fi