-
Notifications
You must be signed in to change notification settings - Fork 90
55 lines (46 loc) · 1.59 KB
/
swagger-validation.yml
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
name: Swagger Validation
on:
pull_request:
branches:
- main
jobs:
ensure-up-to-date:
name: Ensure Up-to-date
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
# Detect Go version from go.mod
- name: Detect Go version from go.mod
id: detect-go-version
run: |
go_version=$(grep '^go ' go.mod | awk '{print $2}')
echo "Go version detected: $go_version"
echo "golang-version=$go_version" >> $GITHUB_ENV
# Setup Go using the detected version
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.golang-version }}
cache: true
# Install swag (Swagger generator)
- name: Install Swag
run: |
go install github.com/swaggo/swag/cmd/swag@latest
# Verify swag installation
- name: Verify Swag Installation
run: |
if ! command -v swag &> /dev/null; then
echo "Swag is not installed. Please ensure Go is properly configured and Swag is installed."
exit 1
fi
# Generate the swagger.json
- name: Generate Swagger file
run: make generate-swagger
# Compare the newly generated swagger.json with the committed swagger.json
- name: Check for Swagger differences
run: |
git diff --exit-code pkg/swagger/swagger.json || (echo "Swagger is outdated. Please regenerate it with 'make generate-swagger' and commit the changes." && exit 1)