Skip to content

Commit 8c6c3f7

Browse files
Merge pull request #118 from DurgaPrasad-54/main
Swagger json automation
1 parent a0ee3a7 commit 8c6c3f7

3 files changed

Lines changed: 130 additions & 0 deletions

File tree

.github/workflows/swagger-json.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Sync Swagger to AMRIT-Docs
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
swagger-sync:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 20
12+
13+
steps:
14+
- name: Checkout API repo
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Java 17
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: 17
22+
cache: maven
23+
24+
- name: Build API (skip tests)
25+
run: mvn -B clean package -DskipTests
26+
27+
- name: Install jq
28+
run: sudo apt-get update && sudo apt-get install -y jq
29+
30+
- name: Run API in swagger profile
31+
run: |
32+
mvn spring-boot:run \
33+
-Dspring-boot.run.profiles=swagger \
34+
-Dspring-boot.run.arguments=--server.port=9090 \
35+
> app.log 2>&1 &
36+
echo $! > api_pid.txt
37+
38+
- name: Wait for API & fetch Swagger
39+
run: |
40+
for i in {1..40}; do
41+
CODE=$(curl --connect-timeout 2 --max-time 5 -s -o swagger_raw.json -w "%{http_code}" http://localhost:9090/v3/api-docs || true)
42+
43+
if [ "$CODE" = "200" ]; then
44+
jq . swagger_raw.json > admin-api.json || {
45+
echo "Swagger JSON invalid"
46+
cat swagger_raw.json
47+
exit 1
48+
}
49+
50+
if [ "$(jq '.paths | length' admin-api.json)" -eq 0 ]; then
51+
echo "Swagger paths empty – failing"
52+
exit 1
53+
fi
54+
55+
echo "Swagger generated successfully"
56+
exit 0
57+
fi
58+
59+
echo "Waiting for API... ($i)"
60+
sleep 4
61+
done
62+
63+
echo "Swagger not generated"
64+
cat app.log || true
65+
exit 1
66+
67+
- name: Stop API
68+
if: always()
69+
run: |
70+
# Graceful shutdown of the process group
71+
sleep 5
72+
# Force kill the process group if still running
73+
if [ -f api_pid.txt ]; then
74+
PID=$(cat api_pid.txt)
75+
kill -TERM -- -"$PID" 2>/dev/null || true
76+
sleep 2
77+
kill -9 -- -"$PID" 2>/dev/null || true
78+
fi
79+
# Fallback: kill any remaining java process on port 9090
80+
fuser -k 9090/tcp 2>/dev/null || true
81+
82+
- name: Checkout AMRIT-Docs
83+
uses: actions/checkout@v4
84+
with:
85+
repository: PSMRI/AMRIT-Docs
86+
token: ${{ secrets.DOCS_REPO_TOKEN }}
87+
path: amrit-docs
88+
fetch-depth: 0
89+
90+
- name: Copy Swagger JSON
91+
run: |
92+
mkdir -p amrit-docs/docs/swagger
93+
cp admin-api.json amrit-docs/docs/swagger/admin-api.json
94+
95+
- name: Create Pull Request
96+
uses: peter-evans/create-pull-request@v8
97+
with:
98+
token: ${{ secrets.DOCS_REPO_TOKEN }}
99+
path: amrit-docs
100+
branch: auto/swagger-update-${{ github.run_id }}-${{ github.run_attempt }}
101+
base: main
102+
commit-message: "chore(docs): auto-update Admin-API swagger"
103+
title: "chore(docs): auto-update Admin-API swagger"
104+
delete-branch: true
105+
body: |
106+
This PR automatically updates Admin-API Swagger JSON
107+
from the latest main branch build.

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@
271271
<version>0.12.6</version>
272272
<scope>runtime</scope>
273273
</dependency>
274+
<dependency>
275+
<groupId>com.h2database</groupId>
276+
<artifactId>h2</artifactId>
277+
<scope>runtime</scope>
278+
</dependency>
274279
<!-- end newly added dependencies -->
275280
</dependencies>
276281

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
spring.datasource.url=jdbc:h2:mem:swaggerdb
2+
spring.datasource.driver-class-name=org.h2.Driver
3+
spring.datasource.username=sa
4+
spring.datasource.password=
5+
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
6+
spring.jpa.hibernate.ddl-auto=none
7+
8+
# Disable Redis if not needed for docs (optional)
9+
spring.redis.host=localhost
10+
spring.redis.port=6379
11+
12+
# CORS for Swagger UI
13+
cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localhost:8080}
14+
15+
# Logging
16+
logging.level.root=INFO
17+
18+
jwt.secret=JWT_SECRET

0 commit comments

Comments
 (0)