-
Notifications
You must be signed in to change notification settings - Fork 1
263 lines (229 loc) · 8.38 KB
/
deploy.yml
File metadata and controls
263 lines (229 loc) · 8.38 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: Build and Deploy
# Run on push to main/master/develop branch
on:
push:
branches:
- main
- master
- develop
workflow_dispatch: # Allow manual triggering
# Grant necessary permissions
permissions:
contents: write
pages: write
id-token: write
issues: write
pull-requests: write
jobs:
# Job 1: Build with Vite
build:
name: Build with Vite
needs: []
runs-on: ubuntu-latest
outputs:
build_status: ${{ steps.build_check.outputs.status }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: |
echo "📦 Installing dependencies..."
npm ci
- name: Build with Vite
id: build_check
env:
VITE_BASE_PATH: ${{ github.ref_name == 'develop' && '/development/' || '/' }}
run: |
echo "🏗️ Building with Vite..."
echo "📍 Base path: $VITE_BASE_PATH"
echo "🌿 Branch: ${{ github.ref_name }}"
npm run build
# Check if build succeeded
if [ ! -d "dist" ]; then
echo "❌ Build failed - dist directory not created!"
echo "status=failed" >> $GITHUB_OUTPUT
exit 1
fi
# Verify critical files exist
if [ ! -f "dist/index.html" ]; then
echo "❌ Build failed - index.html not found in dist!"
echo "status=failed" >> $GITHUB_OUTPUT
exit 1
fi
echo "✅ Vite build completed successfully"
echo "📦 Build output:"
ls -lh dist/
echo ""
echo "📦 Assets:"
ls -lh dist/assets/ | head -20
echo "status=success" >> $GITHUB_OUTPUT
- name: Copy additional files to dist
run: |
echo "📋 Copying additional files..."
# Copy files that Vite doesn't process but are needed
cp -r vendor dist/ 2>/dev/null || echo "No vendor directory to copy"
cp -r fonts dist/ 2>/dev/null || echo "No fonts directory to copy"
cp -r PolliLibJS dist/ 2>/dev/null || echo "No PolliLibJS directory to copy"
cp robots.txt dist/ 2>/dev/null || echo "No robots.txt to copy"
cp sitemap.xml dist/ 2>/dev/null || echo "No sitemap.xml to copy"
cp BingSiteAuth.xml dist/ 2>/dev/null || echo "No BingSiteAuth.xml to copy"
cp visitor-tracking.js dist/ 2>/dev/null || echo "No visitor-tracking.js to copy"
# Copy page-specific JS files
cp about/about.js dist/about/ 2>/dev/null || echo "No about.js to copy"
cp ai/demo/age-verification.js dist/ai/demo/ 2>/dev/null || echo "No age-verification.js to copy"
cp ai/demo/js/main.js dist/ai/demo/js/ 2>/dev/null || mkdir -p dist/ai/demo/js && cp ai/demo/js/main.js dist/ai/demo/js/ || echo "No main.js to copy"
echo "✅ Additional files copied"
- name: Upload artifact for deployment
uses: actions/upload-pages-artifact@v3
with:
path: 'dist'
# Job 4a: Report Build Status
report-status:
name: Report Build Status
needs: build
runs-on: ubuntu-latest
if: always()
steps:
- name: Report success
if: needs.build.outputs.build_status == 'success'
run: |
echo "✅ BUILD SUCCESSFUL"
echo "================================"
echo "Built with: Vite"
echo "Status: SUCCESS"
echo "Ready for deployment"
echo "================================"
- name: Report failure
if: needs.build.outputs.build_status == 'failed'
run: |
echo "❌ BUILD FAILED"
echo "================================"
echo "Built with: Vite"
echo "Status: FAILED"
echo "Check build logs for details"
echo "================================"
exit 1
- name: Create status comment (if PR)
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const status = '${{ needs.build.outputs.build_status }}';
const icon = status === 'success' ? '✅' : '❌';
const message = status === 'success' ? 'Build successful!' : 'Build failed!';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${icon} **${message}**\n\n**Built with:** Vite\n**Status:** ${status.toUpperCase()}`
});
# Job 4b: Deploy to GitHub Pages (Develop Branch)
deploy-develop:
name: Deploy to /development/
needs: build
runs-on: ubuntu-latest
if: needs.build.outputs.build_status == 'success' && github.ref_name == 'develop'
# Ensure only one gh-pages deployment runs at a time
concurrency:
group: "gh-pages-deployment"
cancel-in-progress: false
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: github-pages
path: artifact
- name: Extract artifact
run: |
cd artifact
tar -xf artifact.tar
mkdir -p ../dist
mv * ../dist/ 2>/dev/null || true
cd ..
rm -rf artifact
- name: Deploy to /development/ subdirectory
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
destination_dir: development
keep_files: true
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
commit_message: 'Deploy develop branch to /development/'
- name: Report deployment success
run: |
echo "🚀 DEPLOYMENT SUCCESSFUL"
echo "================================"
echo "Branch: develop"
echo "URL: https://www.unityailab.com/development/"
echo "Built with: Vite (optimized)"
echo "================================"
# Job 4c: Deploy to GitHub Pages (Main Branch)
deploy-main:
name: Deploy to Root
needs: build
runs-on: ubuntu-latest
if: needs.build.outputs.build_status == 'success' && (github.ref_name == 'main' || github.ref_name == 'master')
# Ensure only one gh-pages deployment runs at a time
concurrency:
group: "gh-pages-deployment"
cancel-in-progress: false
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages-backup
- name: Preserve /development/ folder
run: |
if [ -d "gh-pages-backup/development" ]; then
cp -r gh-pages-backup/development /tmp/development-backup
echo "💾 Preserved /development/ folder"
else
echo "ℹ️ No /development/ folder to preserve"
fi
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: github-pages
path: artifact
- name: Extract artifact
run: |
cd artifact
tar -xf artifact.tar
mkdir -p ../dist
mv * ../dist/ 2>/dev/null || true
cd ..
rm -rf artifact
- name: Restore /development/ folder to build
run: |
if [ -d "/tmp/development-backup" ]; then
cp -r /tmp/development-backup dist/development
echo "♻️ Restored /development/ folder to deployment"
fi
- name: Deploy to root directory
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
keep_files: false
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
commit_message: 'Deploy main branch to root'
- name: Report deployment success
run: |
echo "🚀 DEPLOYMENT SUCCESSFUL"
echo "================================"
echo "Branch: ${{ github.ref_name }}"
echo "URL: https://www.unityailab.com/"
echo "Built with: Vite (optimized)"
echo "================================"