-
Notifications
You must be signed in to change notification settings - Fork 49
add swagger json automate #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6736e1b
chore(swagger): automate swagger json export
DurgaPrasad-54 757eef2
chore(swagger): address coderabbit feedback
DurgaPrasad-54 cb69d11
chore(swagger): define cors.allowed-origins for swagger profile
DurgaPrasad-54 9091c5e
chore(swagger): define jwt for swagger profile
DurgaPrasad-54 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| # Stop app | ||
| - name: Stop application | ||
| if: always() | ||
| run: | | ||
| if [ -f /tmp/app.pid ]; then | ||
| kill $(cat /tmp/app.pid) || true | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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