Repository navigation
383 lines (329 loc) Β· 11.7 KB
/
Copy pathdeploy.yml
File metadata and controls
383 lines (329 loc) Β· 11.7 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
name: Deploy to GitHub Pages
on:
push:
branches: [ master, main ]
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'production'
type: choice
options:
- production
- staging
env:
RUBY_VERSION: '3.2.2'
NODE_VERSION: '20'
JEKYLL_ENV: production
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Build job
build:
name: Build for Deployment
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Setup Pages
id: pages
uses: actions/configure-pages@v4
- name: Install Node dependencies
run: npm ci
- name: Restore Jekyll cache
uses: actions/cache@v4
with:
path: |
.jekyll-cache
_site
.sass-cache
tmp/
key: jekyll-deploy-${{ runner.os }}-${{ hashFiles('_config.yml', 'Gemfile.lock', 'package-lock.json') }}-${{ github.sha }}
restore-keys: |
jekyll-deploy-${{ runner.os }}-${{ hashFiles('_config.yml', 'Gemfile.lock', 'package-lock.json') }}-
jekyll-deploy-${{ runner.os }}-
- name: Clean previous builds
run: npm run clean
- name: Generate dynamic pages with caching
run: |
echo "Generating dynamic pages..."
npm run generate:pages:cached
echo "Page generation completed"
- name: Build Jekyll site for production
run: |
echo "Building Jekyll site..."
JEKYLL_ENV=production bundle exec jekyll build --config _config.yml
npm run copy:indexes
echo "Jekyll build completed"
env:
JEKYLL_ENV: production
- name: Optimize build
run: |
echo "Optimizing build..."
# Remove unnecessary files
find _site -name "*.map" -delete
find _site -name ".DS_Store" -delete
# Compress CSS if available
if command -v cleancss >/dev/null 2>&1; then
find _site -name "*.css" -not -name "*.min.css" -exec cleancss -o {}.min {} \; || true
fi
echo "Build optimization completed"
- name: Validate deployment build
run: |
echo "=== Deployment Validation ==="
# Check critical files
REQUIRED_FILES=(
"_site/index.html"
"_site/pt-BR/index.html"
"_site/api/categories.json"
"_site/api/categories/en-US.json"
"_site/api/categories/pt-BR.json"
)
for file in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$file" ]; then
echo "β Critical file missing: $file"
exit 1
else
echo "β
Found: $file"
fi
done
# Basic HTML validation on key pages
if command -v htmlhint >/dev/null 2>&1; then
htmlhint _site/index.html || echo "Warning: HTML issues in index.html"
htmlhint _site/pt-BR/index.html || echo "Warning: HTML issues in pt-BR/index.html"
fi
echo "Build validation completed successfully"
- name: Generate deployment report
run: |
echo "=== Deployment Report ===" > deployment-report.txt
echo "Build Date: $(date -u)" >> deployment-report.txt
echo "Commit: ${{ github.sha }}" >> deployment-report.txt
echo "Branch: ${{ github.ref_name }}" >> deployment-report.txt
echo "Jekyll Environment: $JEKYLL_ENV" >> deployment-report.txt
echo "" >> deployment-report.txt
echo "Site Statistics:" >> deployment-report.txt
echo "- Total Size: $(du -sh _site/ | cut -f1)" >> deployment-report.txt
echo "- HTML Files: $(find _site/ -name '*.html' | wc -l)" >> deployment-report.txt
echo "- English Pages: $(find _site/en-US -name '*.html' | wc -l)" >> deployment-report.txt
echo "- Portuguese Pages: $(find _site/pt-BR -name '*.html' | wc -l)" >> deployment-report.txt
echo "- JSON APIs: $(find _site/api -name '*.json' | wc -l)" >> deployment-report.txt
echo "" >> deployment-report.txt
echo "Build completed successfully at $(date -u)" >> deployment-report.txt
cat deployment-report.txt
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: _site/
- name: Upload deployment report
uses: actions/upload-artifact@v4
with:
name: deployment-report
path: deployment-report.txt
retention-days: 30
# Deployment job
deploy:
name: Deploy to GitHub Pages
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Get deployment URL
run: |
echo "π Site deployed successfully!"
echo "π URL: ${{ steps.deployment.outputs.page_url }}"
echo "β° Deployed at: $(date -u)"
# Post-deployment testing
post-deploy-tests:
name: Post-Deployment Tests
runs-on: ubuntu-latest
needs: [build, deploy]
if: success()
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Lighthouse CI
run: |
npm install -g @lhci/cli@0.12.x
npm install -g puppeteer
- name: Wait for deployment
run: |
echo "Waiting for deployment to be ready..."
sleep 30
- name: Test site accessibility
run: |
SITE_URL="${{ needs.deploy.outputs.page_url || 'https://iplibrary.org' }}"
echo "Testing site: $SITE_URL"
# Basic curl test
if curl -sS --fail --connect-timeout 30 "$SITE_URL" > /dev/null; then
echo "β
Site is accessible"
else
echo "β Site is not accessible"
exit 1
fi
- name: Test multilingual pages
run: |
SITE_URL="${{ needs.deploy.outputs.page_url || 'https://iplibrary.org' }}"
# Test English page
if curl -sS --fail "${SITE_URL}en-US/" > /dev/null; then
echo "β
English site accessible"
else
echo "β οΈ English site may not be accessible"
fi
# Test Portuguese page
if curl -sS --fail "${SITE_URL}pt-BR/" > /dev/null; then
echo "β
Portuguese site accessible"
else
echo "β οΈ Portuguese site may not be accessible"
fi
- name: Test API endpoints
run: |
SITE_URL="${{ needs.deploy.outputs.page_url || 'https://iplibrary.org' }}"
# Test main categories API
if curl -sS --fail "${SITE_URL}api/categories.json" | jq . > /dev/null 2>&1; then
echo "β
Main categories API working"
else
echo "β οΈ Main categories API may have issues"
fi
# Test language-specific APIs
if curl -sS --fail "${SITE_URL}api/categories/en-US.json" | jq . > /dev/null 2>&1; then
echo "β
English categories API working"
else
echo "β οΈ English categories API may have issues"
fi
if curl -sS --fail "${SITE_URL}api/categories/pt-BR.json" | jq . > /dev/null 2>&1; then
echo "β
Portuguese categories API working"
else
echo "β οΈ Portuguese categories API may have issues"
fi
- name: Performance audit with Lighthouse
run: |
SITE_URL="${{ needs.deploy.outputs.page_url || 'https://iplibrary.org' }}"
echo "Running Lighthouse audit on: $SITE_URL"
# Create LHCI config
cat > .lighthouserc.json << EOF
{
"ci": {
"collect": {
"url": [
"$SITE_URL",
"${SITE_URL}en-US/",
"${SITE_URL}pt-BR/"
],
"numberOfRuns": 1,
"settings": {
"chromeFlags": "--no-sandbox --headless"
}
},
"assert": {
"assertions": {
"categories:performance": ["warn", {"minScore": 0.7}],
"categories:accessibility": ["warn", {"minScore": 0.8}],
"categories:best-practices": ["warn", {"minScore": 0.8}],
"categories:seo": ["warn", {"minScore": 0.8}]
}
},
"upload": {
"target": "temporary-public-storage"
}
}
}
EOF
# Run Lighthouse CI
lhci autorun || echo "Lighthouse audit completed with warnings"
continue-on-error: true
- name: Upload Lighthouse reports
uses: actions/upload-artifact@v4
if: always()
with:
name: lighthouse-reports
path: .lighthouseci/
retention-days: 30
# Notification job
notify:
name: Deployment Notification
runs-on: ubuntu-latest
needs: [build, deploy, post-deploy-tests]
if: always()
steps:
- name: Download deployment report
uses: actions/download-artifact@v4
with:
name: deployment-report
- name: Deployment Summary
run: |
echo "=== IPLibrary Deployment Summary ==="
echo "π Site: IPLibrary Website"
echo "π
Date: $(date -u)"
echo "π Commit: ${{ github.sha }}"
echo "πΏ Branch: ${{ github.ref_name }}"
echo "π€ Actor: ${{ github.actor }}"
echo ""
echo "π Job Results:"
echo "- Build: ${{ needs.build.result }}"
echo "- Deploy: ${{ needs.deploy.result }}"
echo "- Post-Deploy Tests: ${{ needs.post-deploy-tests.result }}"
echo ""
if [[ "${{ needs.build.result }}" == "success" && "${{ needs.deploy.result }}" == "success" ]]; then
echo "β
Deployment completed successfully!"
echo "π Site is live and accessible"
if [[ "${{ needs.post-deploy-tests.result }}" == "success" ]]; then
echo "β
All post-deployment tests passed"
else
echo "β οΈ Some post-deployment tests had issues"
fi
else
echo "β Deployment failed"
echo "Please check the logs above for details"
fi
echo ""
echo "π Deployment Report:"
if [ -f deployment-report.txt ]; then
cat deployment-report.txt
else
echo "Report not available"
fi
# Optional: Send deployment notification to external service
# - name: Send deployment notification
# if: success()
# run: |
# # Example webhook notification
# # curl -X POST "${{ secrets.WEBHOOK_URL }}" \
# # -H "Content-Type: application/json" \
# # -d '{
# # "text": "IPLibrary website deployed successfully",
# # "url": "${{ needs.deploy.outputs.page_url }}",
# # "commit": "${{ github.sha }}",
# # "branch": "${{ github.ref_name }}"
# # }'
# echo "Deployment notification sent (placeholder)"