Skip to content

Commit 2cf54e2

Browse files
Update swagger-json.yml
1 parent 5d7271e commit 2cf54e2

1 file changed

Lines changed: 17 additions & 37 deletions

File tree

.github/workflows/swagger-json.yml

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,77 +23,57 @@ jobs:
2323
- name: Build API (skip tests)
2424
run: mvn clean package -DskipTests
2525

26-
- name: Ensure jq is installed
26+
- name: Install jq
2727
run: sudo apt-get update && sudo apt-get install -y jq
2828

29-
- name: Run API in Swagger profile (background)
29+
- name: Run API in swagger profile
3030
run: |
3131
mvn spring-boot:run \
3232
-Dspring-boot.run.profiles=swagger \
3333
-Dspring-boot.run.arguments=--server.port=9090 \
3434
> app.log 2>&1 &
3535
echo $! > api_pid.txt
3636
37-
- name: Wait for API & fetch Swagger (pretty)
37+
- name: Wait for API & fetch Swagger
3838
run: |
3939
for i in {1..30}; do
40-
HTTP_CODE=$(curl -s -o tmp_swagger.json -w "%{http_code}" http://localhost:9090/v3/api-docs || true)
41-
42-
if [ "$HTTP_CODE" = "200" ]; then
43-
jq . tmp_swagger.json > common-api.json
44-
echo "Swagger JSON fetched and pretty-printed"
40+
CODE=$(curl -s -o swagger_raw.json -w "%{http_code}" http://localhost:9090/v3/api-docs || true)
41+
if [ "$CODE" = "200" ]; then
42+
jq . swagger_raw.json > common-api.json
4543
exit 0
4644
fi
47-
48-
echo "Waiting for API... ($i)"
4945
sleep 5
5046
done
5147
52-
echo "Swagger JSON not generated after waiting"
48+
echo "Swagger not generated"
5349
cat app.log || true
5450
exit 1
5551
56-
- name: Stop Spring Boot API
52+
- name: Stop API
5753
if: always()
5854
run: |
59-
if [ -f api_pid.txt ]; then
60-
kill $(cat api_pid.txt) || true
61-
fi
55+
kill $(cat api_pid.txt) || true
6256
63-
- name: Checkout AMRIT-Docs repo
57+
- name: Checkout AMRIT-Docs
6458
uses: actions/checkout@v4
6559
with:
6660
repository: DurgaPrasad-54/AMRIT-Docs
6761
token: ${{ secrets.DOCS_REPO_TOKEN }}
6862
path: amrit-docs
6963

70-
- name: Update Swagger spec
64+
- name: Copy Swagger JSON
7165
run: |
7266
cp common-api.json amrit-docs/docs/swagger/common-api.json
7367
74-
- name: Commit & push
75-
run: |
76-
cd amrit-docs
77-
git config user.name "github-actions"
78-
git config user.email "github-actions@github.com"
79-
export BRANCH_NAME=auto/swagger-update
80-
git checkout -B $BRANCH_NAME
81-
git add docs/swagger/common-api.json
82-
if git diff --cached --quiet; then
83-
echo "No changes to commit"
84-
echo "SKIP_PR=true" >> $GITHUB_ENV
85-
else
86-
git commit -m "Auto-update Common-API swagger"
87-
git push --force --set-upstream origin $BRANCH_NAME
88-
fi
89-
9068
- name: Create Pull Request
91-
if: env.SKIP_PR != 'true'
9269
uses: peter-evans/create-pull-request@v6
9370
with:
9471
token: ${{ secrets.DOCS_REPO_TOKEN }}
9572
path: amrit-docs
96-
commit-message: "Auto-update Common-API swagger"
97-
title: "Auto-update Common-API swagger"
98-
body: "This PR updates the Common-API Swagger JSON automatically from the latest main branch build."
9973
branch: auto/swagger-update
74+
base: main
75+
commit-message: Auto-update Common-API swagger
76+
title: Auto-update Common-API swagger
77+
body: |
78+
This PR automatically updates the Common-API Swagger JSON
79+
from the latest main branch build.

0 commit comments

Comments
 (0)