Repository navigation
170 lines (145 loc) · 4.53 KB
/
Copy pathfrontend-deploy.yml
File metadata and controls
170 lines (145 loc) · 4.53 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: CI/CD - Frontend Deploy to Hostinger
on:
push:
branches: [master]
paths:
- "src/**"
- "public/**"
- "index.html"
- "package.json"
- "vite.config.ts"
- "tailwind.config.ts"
- "tsconfig*.json"
- ".github/workflows/frontend-deploy.yml"
workflow_dispatch:
inputs:
environment:
description: "Deployment environment"
required: true
default: "production"
type: choice
options:
- production
env:
NODE_VERSION: "20"
jobs:
check:
name: Lint & Type Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Lint
run: bun run lint || true
- name: Type check
run: bun run tsc --noEmit || true
- name: Build (verify)
env:
VITE_API_URL: https://applens.space/api
run: bun run build
deploy:
name: Build & Deploy to Hostinger
needs: check
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Build for production
env:
VITE_API_URL: ${{ secrets.VITE_API_URL || 'https://applens.space/api' }}
run: |
bun run build
echo "Build output:"
ls -lh dist/
du -sh dist/
- name: Compress build output
run: |
cd dist
tar -czf ../frontend-dist.tar.gz .
cd ..
ls -lh frontend-dist.tar.gz
- name: Upload build to Hostinger
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.HOSTINGER_HOST }}
username: ${{ secrets.HOSTINGER_USERNAME }}
key: ${{ secrets.HOSTINGER_SSH_KEY }}
port: ${{ secrets.HOSTINGER_SSH_PORT || 22 }}
source: "frontend-dist.tar.gz"
target: "/tmp/"
strip_components: 0
- name: Upload deploy script
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.HOSTINGER_HOST }}
username: ${{ secrets.HOSTINGER_USERNAME }}
key: ${{ secrets.HOSTINGER_SSH_KEY }}
port: ${{ secrets.HOSTINGER_SSH_PORT || 22 }}
source: "scripts/deploy-frontend.sh"
target: "~/applens/"
strip_components: 0
- name: Deploy on Hostinger
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.HOSTINGER_HOST }}
username: ${{ secrets.HOSTINGER_USERNAME }}
key: ${{ secrets.HOSTINGER_SSH_KEY }}
port: ${{ secrets.HOSTINGER_SSH_PORT || 22 }}
script: |
set -e
cd ~/applens
chmod +x scripts/deploy-frontend.sh
./scripts/deploy-frontend.sh
- name: Verify deployment
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.HOSTINGER_HOST }}
username: ${{ secrets.HOSTINGER_USERNAME }}
key: ${{ secrets.HOSTINGER_SSH_KEY }}
port: ${{ secrets.HOSTINGER_SSH_PORT || 22 }}
script: |
set -e
echo "Verifying frontend deployment..."
if [ -f "/var/www/applens/index.html" ]; then
echo "Frontend files deployed successfully!"
echo "File count: $(find /var/www/applens -type f | wc -l)"
echo "Total size: $(du -sh /var/www/applens | cut -f1)"
else
echo "Frontend files not found!"
exit 1
fi
for i in $(seq 1 10); do
if curl -sf http://localhost/ > /dev/null 2>&1; then
echo "Nginx is serving the frontend!"
exit 0
fi
echo " Waiting for nginx... ($i/10)"
sleep 2
done
echo "Nginx check failed"
exit 1
- name: Notify on failure
if: failure()
run: |
echo "::error::Frontend deployment to Hostinger failed! Check the logs above."