Skip to content

Commit 60f3d62

Browse files
authored
Merge pull request #74 from YAPP-Github/ci/PRODUCT-154
[Ci] 자동 ERD 생성 워크플로 구현
2 parents 2824185 + 6e9f2ec commit 60f3d62

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: ERD to GitHub Pages
2+
3+
on:
4+
pull_request:
5+
branches: [ "**" ]
6+
paths: [ "**" ]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
jobs:
17+
generate-erd-from-flyway:
18+
runs-on: ubuntu-latest
19+
20+
services:
21+
mysql:
22+
image: mysql:8.0
23+
env:
24+
MYSQL_USER: ${{ secrets.TEST_DB_USER }}
25+
MYSQL_PASSWORD: ${{ secrets.TEST_DB_PASSWORD }}
26+
MYSQL_ROOT_PASSWORD: ${{ secrets.TEST_DB_ROOT_PASSWORD }}
27+
MYSQL_DATABASE: testdb
28+
ports:
29+
- 3306:3306
30+
options: >-
31+
--health-cmd="mysqladmin ping"
32+
--health-interval=10s
33+
--health-timeout=5s
34+
--health-retries=3
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: Set up JDK 21
41+
uses: actions/setup-java@v4
42+
with:
43+
java-version: '21'
44+
distribution: 'temurin'
45+
46+
- name: Download Flyway
47+
run: |
48+
curl -sSL "https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/10.13.0/flyway-commandline-10.13.0-linux-x64.tar.gz" -o flyway.tar.gz
49+
tar -xzf flyway.tar.gz
50+
echo "$(pwd)/flyway-10.13.0" >> $GITHUB_PATH
51+
52+
- name: Run Flyway migrations
53+
run: |
54+
flyway -url="jdbc:mysql://127.0.0.1:3306/testdb?allowPublicKeyRetrieval=true&useSSL=false" -user=${{ secrets.TEST_DB_USER }} -password=${{ secrets.TEST_DB_PASSWORD }} -locations=filesystem:src/main/resources/db/migration migrate
55+
shell: bash
56+
57+
- name: Dump database schema
58+
run: |
59+
mkdir -p erd
60+
mysqldump -h 127.0.0.1 -u ${{ secrets.TEST_DB_USER }} -p${{ secrets.TEST_DB_PASSWORD }} --no-data --skip-comments testdb > erd/schema.sql
61+
62+
- name: Set up Node.js
63+
uses: actions/setup-node@v4
64+
with:
65+
node-version: '20'
66+
67+
- name: Install DBML Tools
68+
run: npm install -g @dbml/cli @softwaretechnik/dbml-renderer
69+
70+
- name: Convert SQL to DBML
71+
run: |
72+
npx sql2dbml erd/schema.sql --mysql -o erd/schema.dbml
73+
74+
- name: Render ERD to SVG
75+
run: |
76+
npx dbml-renderer -i erd/schema.dbml -o erd/erd.svg
77+
78+
- name: Generate HTML wrapper
79+
run: |
80+
echo "<html><head><title>ERD Preview</title></head><body><h2>ERD Preview for PR #${{ github.event.pull_request.number }}</h2><img src='erd.svg' style='max-width:100%;'/></body></html>" > erd/index.html
81+
82+
- name: Deploy ERD to GitHub Pages
83+
uses: peaceiris/actions-gh-pages@v4
84+
with:
85+
github_token: ${{ secrets.GITHUB_TOKEN }}
86+
publish_dir: ./erd
87+
force_orphan: true
88+
89+
- name: Comment on PR with ERD Link
90+
uses: peter-evans/create-or-update-comment@v4
91+
with:
92+
issue-number: ${{ github.event.pull_request.number }}
93+
body: |
94+
📌 최신 ERD가 자동 생성되었습니다.
95+
96+
👉 [ERD 보러가기](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/)

0 commit comments

Comments
 (0)