Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/swagger-export.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Export Swagger

on:
push:
branches:
- main

jobs:
swagger:
runs-on: ubuntu-latest

steps:
# Checkout Common-API (current repo)
- uses: actions/checkout@v4

# Setup Java
- name: Set up Java 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: maven

# Build WAR
- name: Build Common-API
run: mvn clean package -DskipTests

# Run application with swagger profile
- name: Run application
run: |
WAR_FILE=$(find target -name "*.war" | grep -v original | head -1)
if [ -z "$WAR_FILE" ]; then
echo "WAR file not found"
exit 1
fi

echo "Starting app using $WAR_FILE"
java -jar "$WAR_FILE" --spring.profiles.active=swagger > /tmp/app.log 2>&1 &
echo $! > /tmp/app.pid

# Wait for Swagger to be available
- name: Wait for Swagger endpoint
run: |
for i in {1..40}; do
if curl -sf http://localhost:8083/v3/api-docs > /dev/null; then
echo "Swagger is available"
exit 0
fi
sleep 2
done

echo "Application failed to start"
cat /tmp/app.log
exit 1

# Fetch Swagger JSON
- name: Fetch Swagger JSON
run: |
curl http://localhost:8083/v3/api-docs -o common-api.json
test -s common-api.json

# Clone AMRIT-Docs
- name: Clone AMRIT-Docs
run: |
git clone --depth 1 https://github.com/PSMRI/AMRIT-Docs.git amrit-docs

# Copy Swagger
- name: Copy Swagger JSON
run: |
mkdir -p amrit-docs/docs/swagger
cp common-api.json amrit-docs/docs/swagger/common-api.json

# Commit & push only if changed
- name: Commit and push
run: |
cd amrit-docs

# Check if file is tracked and detect changes
if git ls-files --error-unmatch docs/swagger/common-api.json > /dev/null 2>&1; then
# File is tracked, check for changes
if git diff --quiet docs/swagger/common-api.json; then
echo "No Swagger changes"
exit 0
fi
else
# File is untracked, stage it and check if there are staged changes
git add docs/swagger/common-api.json
if git diff --staged --quiet docs/swagger/common-api.json; then
echo "No Swagger changes"
exit 0
fi
fi

git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

git add docs/swagger/common-api.json
git commit -m "chore: update Common-API Swagger [skip ci]" \
-m "Source: ${{ github.repository }}@${{ github.sha }}"

git push https://x-access-token:${{ secrets.AMRIT_DOCS_PAT }}@github.com/PSMRI/AMRIT-Docs.git HEAD:main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this going to be generated? What does this variable mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMRIT_DOCS_PAT is a GitHub Personal Access Token created by a maintainer with write access to PSMRI/AMRIT-Docs and stored as a repository secret. It’s used only to authenticate the push from this workflow; for fork-based PRs the secret won’t be available, so the push step is expected to fail


# Stop app
- name: Stop application
if: always()
run: |
if [ -f /tmp/app.pid ]; then
kill $(cat /tmp/app.pid) || true
fi
46 changes: 46 additions & 0 deletions src/main/resources/application-swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
server:
port: 8083

spring:
datasource:
url: jdbc:h2:mem:swaggerdb;DB_CLOSE_DELAY=-1
driver-class-name: org.h2.Driver
username: sa
password: ""

jpa:
hibernate:
ddl-auto: none
show-sql: false

flyway:
enabled: false

liquibase:
enabled: false

session:
store-type: none

task:
scheduling:
enabled: false

springdoc:
api-docs:
enabled: true
path: /v3/api-docs
swagger-ui:
enabled: false

logging:
level:
root: INFO

# CORS configuration for Swagger profile
cors:
allowed-origins: http://localhost:*

# JWT configuration for Swagger profile
jwt:
secret: test-secret-key-for-swagger-profile-only
Loading