-
Notifications
You must be signed in to change notification settings - Fork 25
78 lines (69 loc) · 2.96 KB
/
apidoc.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
name: Publish OpenAPI Specs
on:
workflow_call:
inputs:
version:
required: true
description: "The version under which the API should be published"
type: string
workflow_dispatch:
inputs:
version:
required: true
description: "The version under which the API should be published"
type: string
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
Publish-To-SwaggerHub:
# do NOT run on forks. The Org ("edc") is unique all across SwaggerHub
# Disable temporarily, because we can only have 3 APIs in the SwaggerHub free tier
if: github.repository == 'eclipse-edc/IdentityHub' && false
runs-on: ubuntu-latest
strategy:
matrix:
apiGroup: [ 'ih-resolution-api', 'ih-management-api' ]
env:
rootDir: resources/openapi/yaml/${{ matrix.apiGroup }}
SWAGGERHUB_API_KEY: ${{ secrets.SWAGGERHUB_TOKEN }}
SWAGGERHUB_USER: ${{ secrets.SWAGGERHUB_USER }}
VERSION: ${{ github.event.inputs.version || inputs.version }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-build
- uses: actions/setup-node@v4
# merge together all api groups
- name: Generate API Specs
run: |
# give option to override
cmd=""
if [ ! -z $VERSION ]; then
cmd="-Pversion=$VERSION"
fi
./gradlew resolve
./gradlew ${cmd} -PapiTitle="${{ matrix.apiGroup }}" -PapiDescription="REST API documentation for the ${{ matrix.apiGroup }}" :mergeApiSpec --input=${{ env.rootDir }} --output=${{ matrix.apiGroup }}.yaml
# install swaggerhub CLI
- name: Install SwaggerHub CLI
run: npm i -g swaggerhub-cli
# create API, will fail if exists
- name: Create API
continue-on-error: true
run: |
swaggerhub api:create ${{ env.SWAGGERHUB_USER }}/${{ matrix.apiGroup }} -f ${{ matrix.apiGroup }}.yaml --visibility=public --published=unpublish
# Post snapshots of the API to SwaggerHub as "unpublished", because published APIs cannot be overwritten
- name: Publish API Specs to SwaggerHub
run: |
# coalesce $VERSION, or whatever's stored in gradle.properties
vers=${VERSION:-$(grep "version" gradle.properties | awk -F= '{print $2}')}
if [[ $vers != *-SNAPSHOT ]]; then
echo "no snapshot, will set the API to 'published'";
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/${{ matrix.apiGroup }} -f ${{ matrix.apiGroup }}.yaml --visibility=public --published=publish
swaggerhub api:setdefault ${{ env.SWAGGERHUB_USER }}/${{ matrix.apiGroup }}/$vers
else
echo "snapshot, will set the API to 'unpublished'";
swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/${{ matrix.apiGroup }} -f ${{ matrix.apiGroup }}.yaml --visibility=public --published=unpublish
fi