Skip to content

Commit 2d3e5e2

Browse files
committed
feat(ci): GitHub Workflow for Swagger APIs doc checks
1. Check if the latest swagger docs are commited with the PR. 2. Check if the swagger docs are formatted. Signed-off-by: Gaurav Mishra <[email protected]>
1 parent 2d25768 commit 2d3e5e2

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

.github/workflows/api-swagger.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# SPDX-FileCopyrightText: 2023 Siemens AG
2+
# SPDX-FileContributor: Gaurav Mishra <[email protected]>
3+
# SPDX-License-Identifier: GPL-2.0-only
4+
5+
name: Swagger API Updated
6+
7+
on:
8+
pull_request:
9+
branches: [ "main" ]
10+
workflow_dispatch:
11+
12+
jobs:
13+
14+
doc-diff:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v4
21+
with:
22+
go-version: '1.20'
23+
check-latest: true
24+
cache: true
25+
26+
- name: Install swag
27+
run: |
28+
go install github.com/swaggo/swag/cmd/swag@latest
29+
30+
- name: Build Swagger documents
31+
run: |
32+
swag init --generalInfo api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils --output ./swag/docs
33+
34+
- name: Check doc diff
35+
run: |
36+
diff swag/docs/docs.go cmd/laas/docs/docs.go > swagger-diff.txt
37+
# Check if file swagger-diff.txt is empty
38+
if [ -s swagger-diff.txt ]
39+
then
40+
# If file is not empty, echo a message and exit 1
41+
echo "Swagger docs are not up to date. Please run 'swag init' and commit the changes."
42+
exit 1
43+
fi
44+
45+
doc-fmt:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v3
49+
50+
- name: Set up Go
51+
uses: actions/setup-go@v4
52+
with:
53+
go-version: '1.20'
54+
check-latest: true
55+
cache: true
56+
57+
- name: Install swag
58+
run: |
59+
go install github.com/swaggo/swag/cmd/swag@latest
60+
61+
- name: Format Swagger documents
62+
run: |
63+
swag fmt --generalInfo ./pkg/api/api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils
64+
65+
- name: Check file diff
66+
run: |
67+
git diff --exit-code

0 commit comments

Comments
 (0)