|
8 | 8 | - 'client/**' |
9 | 9 |
|
10 | 10 | jobs: |
11 | | - deploy: |
| 11 | + # ================= FRONTEND ================= |
| 12 | + frontend: |
12 | 13 | runs-on: ubuntu-latest |
13 | 14 |
|
14 | 15 | steps: |
15 | | - - name: Checkout code |
16 | | - uses: actions/checkout@v4 |
| 16 | + - uses: actions/checkout@v4 |
17 | 17 | with: |
18 | | - fetch-depth: 2 # Needed for clean diff logic |
| 18 | + fetch-depth: 2 |
19 | 19 |
|
20 | | - # ---------- FRONTEND BUILD (CI SIDE) ---------- |
21 | 20 | - name: Build frontend |
22 | 21 | run: | |
23 | 22 | if git diff --name-only HEAD^ HEAD | grep '^client/' >/dev/null; then |
24 | 23 | echo "Frontend changed → building" |
25 | 24 | cd client |
| 25 | +
|
26 | 26 | echo "VITE_API_URL=${{ secrets.VITE_API_URL }}" > .env.production |
27 | 27 | echo "VITE_IC_CREDENTIAL=${{ secrets.VITE_IC_CREDENTIAL }}" >> .env.production |
28 | 28 | echo "VITE_IC_USERNAME=${{ secrets.VITE_IC_USERNAME }}" >> .env.production |
29 | 29 | echo "VITE_SONG_URL=${{ secrets.VITE_SONG_URL }}" >> .env.production |
30 | | - npm ci |
| 30 | +
|
| 31 | + npm install --no-audit --no-fund |
31 | 32 | npm run build |
32 | 33 | tar -czf ../client-dist.tar.gz dist |
33 | 34 | else |
34 | 35 | echo "Frontend unchanged → skipping" |
35 | 36 | fi |
36 | 37 |
|
37 | 38 | - name: Upload frontend to VPS |
38 | | - if: success() |
| 39 | + if: success() && exists('client-dist.tar.gz') |
39 | 40 | uses: appleboy/scp-action@v0.1.4 |
40 | 41 | with: |
41 | 42 | host: ${{ secrets.SERVER_HOST }} |
|
45 | 46 | target: /home/ubuntu/ |
46 | 47 | overwrite: true |
47 | 48 |
|
48 | | - # ---------- BACKEND DEPLOY (VPS SIDE) ---------- |
49 | | - - name: Deploy backend + unpack frontend |
| 49 | + # ================= BACKEND ================= |
| 50 | + backend: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + fetch-depth: 2 |
| 57 | + |
| 58 | + - name: Deploy backend |
50 | 59 | uses: appleboy/ssh-action@v1.0.3 |
51 | 60 | with: |
52 | 61 | host: ${{ secrets.SERVER_HOST }} |
|
57 | 66 | git fetch origin |
58 | 67 | git reset --hard origin/main |
59 | 68 |
|
60 | | - # Backend |
61 | 69 | if git diff --name-only HEAD@{1} HEAD | grep '^server/' >/dev/null; then |
62 | 70 | echo "Backend code changed" |
63 | 71 |
|
|
74 | 82 | echo "Backend unchanged" |
75 | 83 | fi |
76 | 84 |
|
77 | | - # Frontend |
78 | 85 | if [ -f /home/ubuntu/client-dist.tar.gz ]; then |
79 | | - echo "Deploying frontend" |
80 | 86 | sudo rm -rf /var/www/syncvibe-web/* |
81 | 87 | sudo tar -xzf /home/ubuntu/client-dist.tar.gz -C /var/www/syncvibe-web |
82 | 88 | rm /home/ubuntu/client-dist.tar.gz |
83 | | - else |
84 | | - echo "Frontend unchanged" |
85 | 89 | fi |
0 commit comments