-
Notifications
You must be signed in to change notification settings - Fork 1
156 lines (152 loc) · 5.82 KB
/
publish_api.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
###############################################################
# Copyright (c) 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 governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
###############################################################
name: Publish APIs
on:
workflow_dispatch:
schedule:
- cron: "0 4 * * *"
env:
# API collector and specs download "docs" path
API_COLLECTOR_DIR: "src/api-collector"
jobs:
collect_openapi:
runs-on: ubuntu-latest
outputs:
specs_exists: ${{ steps.check_specs.outputs.exists }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "${{ env.API_COLLECTOR_DIR }}/go.mod"
- name: Collect OpenAPI specs
id: collect_specs
run: |
RANDOM=$(uuidgen)
echo "RANDOM=${RANDOM}" >> $GITHUB_OUTPUT
cd ${{ env.API_COLLECTOR_DIR }}
go run main.go -owner ${{ github.repository_owner }} -token ${{ secrets.GITHUB_TOKEN }}
- name: Move multiple OpenAPI specs files in one directory into individual directories
run: |
# Find all directories containing multiple *.yaml or *.yml files
find "${{ env.API_COLLECTOR_DIR }}/docs" -type d | while read -r DIR; do
# Count how many YAML/YML files are in the current directory
FILES=($(find "$DIR" -maxdepth 1 -type f \( -name "*.yaml" -o -name "*.yml" \)))
# If there are more than one YAML file in the directory
if [ ${#FILES[@]} -gt 1 ]; then
# Loop through each YAML file
for FILE in "${FILES[@]}"; do
# Extract the filename without the extension
FILENAME=$(basename "$FILE")
BASENAME="${FILENAME%.*}"
# Create a directory named after the file (without the extension)
TARGET_DIR="$DIR/$BASENAME"
mkdir -p "$TARGET_DIR"
# Move the file into the newly created directory
mv "$FILE" "$TARGET_DIR/"
done
fi
done
echo "Multiple OpenAPI specs files in one directory have been organized into individual directories."
- name: Check for specs
id: check_specs
run: |
if [ -d "${{ env.API_COLLECTOR_DIR }}/docs" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- uses: actions/upload-artifact@v4
if: steps.check_specs.outputs.exists == 'true'
with:
name: openapi-${{ steps.collect_specs.outputs.RANDOM }}
path: ${{ env.API_COLLECTOR_DIR }}/docs
generate_matrix:
runs-on: ubuntu-latest
needs: collect_openapi
if: needs.collect_openapi.outputs.specs_exists == 'true'
outputs:
specs: ${{ steps.create_specs_list.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Download OpenAPI specs artifacts
uses: actions/download-artifact@v4
with:
path: docs
pattern: openapi-*
merge-multiple: true
- name: Create OpenAPI specs list
id: create_specs_list
run: |
FILES_ARRAY=$(find docs -type f \( -name "*.yaml" -o -name "*.yml" \) | sed 's/.*/\"&\"/' | paste -sd "," -)
echo "matrix={\"specs\": [${FILES_ARRAY}]}" >> $GITHUB_OUTPUT
generate_swagger_ui:
needs: generate_matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.generate_matrix.outputs.specs) }}
steps:
- uses: actions/checkout@v4
- name: Download OpenAPI specs artifacts
uses: actions/download-artifact@v4
with:
path: docs
pattern: openapi-*
merge-multiple: true
- name: Determine spec file directory
id: determine_directory
run: |
FILE_PATH="${{ matrix.specs }}"
DIR_PATH=$(dirname "${FILE_PATH}")
PRODUCT_PATH=$(dirname "${DIR_PATH}")
RANDOM=$(uuidgen)
echo "DIR_PATH=${DIR_PATH}" >> $GITHUB_OUTPUT
echo "PRODUCT_PATH=${PRODUCT_PATH}" >> $GITHUB_OUTPUT
echo "RANDOM=${RANDOM}" >> $GITHUB_OUTPUT
- name: Generate Swagger UI
uses: Legion2/swagger-ui-action@v1
with:
output: ${{ steps.determine_directory.outputs.DIR_PATH }}/swagger-ui
spec-file: ${{ matrix.specs }}
- name: Generate Directory Listings
uses: jayanta525/[email protected]
with:
FOLDER: ${{ steps.determine_directory.outputs.DIR_PATH }}
- uses: actions/upload-artifact@v4
with:
name: swagger-${{ steps.determine_directory.outputs.RANDOM }}
path: docs
deploy_swagger_ui:
needs: generate_swagger_ui
runs-on: ubuntu-latest
steps:
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: docs
pattern: swagger-*
merge-multiple: true
- name: Generate Directory Listings
uses: jayanta525/[email protected]
with:
FOLDER: docs
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs