-
Notifications
You must be signed in to change notification settings - Fork 1
257 lines (218 loc) · 9.29 KB
/
ci-cd.yml
File metadata and controls
257 lines (218 loc) · 9.29 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
name: SkyNest Frontend CI/CD
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
# Frontend Build and Test
build:
name: Build React Application
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🟢 Setup Node.js 18
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: 📦 Install dependencies
run: |
echo "Installing frontend dependencies..."
npm ci
- name: 🏗️ Build React application
run: |
echo "Building production bundle..."
npm run build
env:
CI: false
NODE_ENV: production
- name: 📊 Build size report
run: |
echo "Build artifacts created:"
ls -lh build/
du -sh build/
- name: 📤 Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: react-build-${{ github.sha }}
path: build/
retention-days: 7
# Code Quality Analysis
quality:
name: Code Quality Check
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 📁 Validate project structure
run: |
echo "📁 Checking frontend structure..."
echo "----------------------------------------"
# Check required directories
test -d src && echo "✅ src/ directory exists" || echo "❌ src/ directory missing"
test -d public && echo "✅ public/ directory exists" || echo "❌ public/ directory missing"
test -f package.json && echo "✅ package.json exists" || echo "❌ package.json missing"
# List structure
echo ""
echo "Frontend structure:"
ls -la src/ 2>/dev/null || echo "Cannot list src/"
echo ""
echo "Public files:"
ls -la public/ 2>/dev/null || echo "Cannot list public/"
- name: 🔍 Check for development artifacts
run: |
echo "🔍 Scanning for development artifacts..."
# Check for console.log (non-blocking)
echo "Checking for console.log statements:"
grep -rn "console\.log" src/ --include="*.js" --include="*.jsx" || echo "✅ No console.log found"
# Check for debugger statements
echo ""
echo "Checking for debugger statements:"
grep -rn "debugger" src/ --include="*.js" --include="*.jsx" || echo "✅ No debugger statements found"
# Check for TODO/FIXME comments
echo ""
echo "Checking for TODO/FIXME comments:"
grep -rn "TODO\|FIXME" src/ --include="*.js" --include="*.jsx" || echo "✅ No TODO/FIXME found"
continue-on-error: true
# Security Scanning
security:
name: Security Analysis
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🟢 Setup Node.js 18
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: 📦 Install dependencies
run: npm ci
- name: 🔒 Run npm audit
run: |
echo "Running security audit for frontend dependencies..."
npm audit --production --audit-level=moderate || echo "⚠️ Vulnerabilities detected, review required"
continue-on-error: true
- name: 🔐 Check for sensitive data
run: |
echo "🔐 Scanning for potential security issues..."
echo "----------------------------------------"
# Check for hardcoded passwords
echo "Checking for hardcoded passwords..."
grep -rn "password\s*=\s*['\"]" src/ --include="*.js" --include="*.jsx" || echo "✅ No hardcoded passwords"
# Check for API keys
echo ""
echo "Checking for hardcoded API keys..."
grep -rn "api[_-]key\s*=\s*['\"]" src/ --include="*.js" --include="*.jsx" || echo "✅ No hardcoded API keys"
# Check for tokens
echo ""
echo "Checking for hardcoded tokens..."
grep -rn "token\s*=\s*['\"]" src/ --include="*.js" --include="*.jsx" || echo "✅ No hardcoded tokens"
continue-on-error: true
# Deploy to GitHub Pages
deploy:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
needs: [build]
if: github.ref == 'refs/heads/main' && needs.build.result == 'success'
permissions:
contents: write
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🟢 Setup Node.js 18
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: 📦 Install dependencies
run: npm ci
- name: 🏗️ Build with production env
run: npm run build
env:
CI: false
NODE_ENV: production
REACT_APP_API_BASE: https://skynest-backend-api.onrender.com
REACT_APP_ENV: production
REACT_APP_DEBUG: false
- name: 🚀 Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
publish_branch: gh-pages
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
commit_message: 'Deploy from main: ${{ github.event.head_commit.message }}'
# Final Report
report:
name: Pipeline Summary
runs-on: ubuntu-latest
needs: [build, quality, security, deploy]
if: always()
steps:
- name: 📊 Generate Summary Report
run: |
echo "========================================"
echo " SkyNest Frontend CI/CD Pipeline "
echo "========================================"
echo ""
echo "Pipeline Results:"
echo " 🏗️ Build: ${{ needs.build.result }}"
echo " 📊 Quality: ${{ needs.quality.result }}"
echo " 🔒 Security: ${{ needs.security.result }}"
echo " 🚀 Deploy: ${{ needs.deploy.result }}"
echo ""
echo "Repository: ${{ github.repository }}"
echo "Branch: ${{ github.ref_name }}"
echo "Commit: ${{ github.sha }}"
echo "Author: ${{ github.actor }}"
echo "========================================"
if [ "${{ needs.build.result }}" == "success" ]; then
echo "✅ Frontend build completed successfully!"
echo "✅ React application is ready for deployment"
if [ "${{ needs.deploy.result }}" == "success" ]; then
echo "✅ Deployed to GitHub Pages!"
fi
echo ""
echo "💡 Backend validation runs in separate repository:"
echo " https://github.com/${{ github.repository_owner }}/Database-Back"
else
echo "❌ Build failed - please check the logs above"
exit 1
fi
- name: 📝 Create GitHub Summary
run: |
echo "## 🎯 SkyNest Frontend CI/CD Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Pipeline Status" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| 🏗️ Build | ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| 📊 Quality | ${{ needs.quality.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| 🔒 Security | ${{ needs.security.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| 🚀 Deploy | ${{ needs.deploy.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.build.result }}" == "success" ]; then
echo "### ✅ Build Successful!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- React application built successfully" >> $GITHUB_STEP_SUMMARY
echo "- Production bundle ready for deployment" >> $GITHUB_STEP_SUMMARY
echo "- All frontend checks passed" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.deploy.result }}" == "success" ]; then
echo "- ✅ **Deployed to GitHub Pages**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🌐 **Live URL:** https://${{ github.repository_owner }}.github.io/Database-Project" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "💡 **Note:** Backend validation runs separately in [Database-Back](https://github.com/${{ github.repository_owner }}/Database-Back) repository" >> $GITHUB_STEP_SUMMARY
else
echo "### ❌ Build Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Please review the error logs above and fix the issues." >> $GITHUB_STEP_SUMMARY
fi