-
-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (172 loc) · 6.82 KB
/
Copy pathci-cd.yml
File metadata and controls
200 lines (172 loc) · 6.82 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
# =============================================================================
# PyExplorer - GitHub Actions CI/CD Pipeline
# =============================================================================
# Este workflow realiza:
# - CI: Build, Lint, Type-check em PRs e pushes
# - CD: Deploy automático para Firebase Hosting na branch main
# =============================================================================
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
NODE_VERSION: '22'
FIREBASE_PROJECT_ID: pyexplorer-cd32d
permissions:
checks: write
contents: read
pull-requests: write
jobs:
# ===========================================================================
# JOB: Build & Lint
# ===========================================================================
build:
name: 🔨 Build & Lint
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v6
- name: 📦 Setup Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: 🌐 Install system dependencies for Puppeteer
run: |
sudo apt-get update
sudo apt-get install -y \
libgbm-dev \
libnss3 \
libatk-bridge2.0-0 \
libgtk-3-0 \
libasound2t64 \
libasound2 \
libxss1 \
libxtst6 \
libxshmfence1 \
libglu1-mesa || true # Ignora erros se algum pacote não existir na versão do Ubuntu
- name: 📥 Install dependencies
run: npm ci
- name: 🔍 Type check (TypeScript)
run: npx tsc --noEmit
- name: 🧹 Lint check
run: npm run lint || true
- name: 🔨 Build production
timeout-minutes: 10
run: npm run build
env:
VITE_FIREBASE_API_KEY: ${{ secrets.VITE_FIREBASE_API_KEY }}
VITE_FIREBASE_AUTH_DOMAIN: ${{ secrets.VITE_FIREBASE_AUTH_DOMAIN }}
VITE_FIREBASE_PROJECT_ID: ${{ secrets.VITE_FIREBASE_PROJECT_ID }}
VITE_FIREBASE_STORAGE_BUCKET: ${{ secrets.VITE_FIREBASE_STORAGE_BUCKET }}
VITE_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.VITE_FIREBASE_MESSAGING_SENDER_ID }}
VITE_FIREBASE_APP_ID: ${{ secrets.VITE_FIREBASE_APP_ID }}
VITE_FIREBASE_MEASUREMENT_ID: ${{ secrets.VITE_FIREBASE_MEASUREMENT_ID }}
VITE_RECAPTCHA_SITE_KEY: ${{ secrets.VITE_RECAPTCHA_SITE_KEY }}
- name: 📊 Report bundle size
run: |
echo "## 📦 Bundle Size Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| File | Size |" >> $GITHUB_STEP_SUMMARY
echo "|------|------|" >> $GITHUB_STEP_SUMMARY
for file in dist/assets/*.js dist/assets/*.css; do
if [ -f "$file" ]; then
size=$(du -h "$file" | cut -f1)
echo "| $(basename $file) | $size |" >> $GITHUB_STEP_SUMMARY
fi
done
- name: 📤 Upload build artifacts
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
retention-days: 7
# ===========================================================================
# JOB: Deploy to Firebase (Production)
# ===========================================================================
deploy-production:
name: 🚀 Deploy to Production
runs-on: ubuntu-24.04
needs: build
# Só faz deploy em push para main (não em PRs)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: production
url: https://pyexplorer.com.br
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v6
- name: 📥 Download build artifacts
uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- name: 🔥 Deploy to Firebase Hosting
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_PYEXPLORER_CD32D }}
projectId: ${{ env.FIREBASE_PROJECT_ID }}
channelId: live
env:
FIREBASE_CLI_EXPERIMENTS: webframeworks
- name: ✅ Deploy Summary
run: |
echo "## 🚀 Deployment Successful!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Environment:** Production" >> $GITHUB_STEP_SUMMARY
echo "**URL:** https://pyexplorer.com.br" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "**Deployed at:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
# ===========================================================================
# JOB: Preview Deploy (Pull Requests)
# ===========================================================================
deploy-preview:
name: 👀 Deploy Preview
runs-on: ubuntu-24.04
needs: build
# Só faz preview em PRs (exceto Dependabot que não tem acesso aos secrets)
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v6
- name: 📥 Download build artifacts
uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- name: 🔥 Deploy Preview to Firebase Hosting
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_PYEXPLORER_CD32D }}
projectId: ${{ env.FIREBASE_PROJECT_ID }}
env:
FIREBASE_CLI_EXPERIMENTS: webframeworks
# ===========================================================================
# JOB: Lighthouse Audit (Performance)
# ===========================================================================
lighthouse:
name: 🔦 Lighthouse Audit
runs-on: ubuntu-24.04
needs: deploy-production
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v6
- name: 🔦 Run Lighthouse
uses: treosh/lighthouse-ci-action@v12
with:
urls: |
https://pyexplorer.com.br/
https://pyexplorer.com.br/game
uploadArtifacts: true
temporaryPublicStorage: true
- name: 📊 Lighthouse Score Summary
if: always()
run: |
echo "## 🔦 Lighthouse Audit Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check the artifacts for detailed reports." >> $GITHUB_STEP_SUMMARY