-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (80 loc) · 3.03 KB
/
auto-generate-openapi.yml
File metadata and controls
93 lines (80 loc) · 3.03 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Validate and Autocommit OpenAPI Spec & Client Code
on:
pull_request:
paths:
- 'src/main/java/**/*.java'
jobs:
validate-and-commit-openapi:
name: Validate & Autocommit OpenAPI Spec + Client
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
services:
postgres:
image: postgres:18
env:
POSTGRES_DB: harmonia
POSTGRES_USER: postgres
POSTGRES_PASSWORD: harmonia
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
token: ${{ secrets.BOT_USER_TOKEN }}
- name: Set up Java
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '25'
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'npm'
cache-dependency-path: 'src/main/webapp/package-lock.json'
- name: Install Node Dependencies
working-directory: src/main/webapp
run: npm ci
- name: Generate OpenAPI Spec
env:
SPRING_PROFILES_ACTIVE: openapi
run: ./gradlew generateApiDocs -x webapp
- name: Generate Client Code
run: ./gradlew openApiGenerate
- name: Format Client Code
working-directory: src/main/webapp
run: npx prettier --write src/app/generated
- name: Check for Changes
id: check_changes
run: |
git add openapi/openapi.yaml src/main/webapp/src/app/generated -f
if git diff --cached --quiet; then
echo "no_changes_detected=true" >> $GITHUB_OUTPUT
else
echo "no_changes_detected=false" >> $GITHUB_OUTPUT
fi
- name: Commit OpenAPI + Client changes
if: steps.check_changes.outputs.no_changes_detected == 'false'
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "chore: update OpenAPI spec and generated client"
git push https://x-access-token:${{ secrets.BOT_USER_TOKEN }}@github.com/${{ github.repository }} HEAD:${{ github.event.pull_request.head.ref }}
- name: Comment on PR
run: |
COMMENT=$([[ "${{ steps.check_changes.outputs.no_changes_detected }}" == "true" ]] && echo "🤖 No OpenAPI or client changes needed." || echo "🤖 OpenAPI spec and client code auto-updated and committed.")
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"body\":\"$COMMENT\"}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"