1+ name : Deploy static content to Pages
2+
3+ on :
4+ push :
5+ branches : ["master"]
6+ paths :
7+ - ' public/**'
8+ - ' .github/workflows/static.yml'
9+ workflow_dispatch :
10+
11+ permissions :
12+ contents : read
13+ pages : write
14+ id-token : write
15+
16+ concurrency :
17+ group : " pages"
18+ cancel-in-progress : true
19+
20+ jobs :
21+ build-and-deploy :
22+ environment :
23+ name : github-pages
24+ url : ${{ steps.deployment.outputs.page_url }}
25+ runs-on : ubuntu-latest
26+
27+ steps :
28+ - name : Checkout repository
29+ uses : actions/checkout@v4
30+ with :
31+ fetch-depth : 0
32+
33+ - name : Setup Node.js
34+ uses : actions/setup-node@v4
35+ with :
36+ node-version : ' 20'
37+ # cache: 'npm'
38+
39+ - name : Install dependencies
40+ run : |
41+ echo "::group::Installing minification tools"
42+ npm install -g html-minifier-terser clean-css-cli terser
43+ echo "::endgroup::"
44+
45+ - name : Verify public directory
46+ run : |
47+ echo "::group::Verifying public directory contents"
48+ echo "Files in public directory:"
49+ find public -type f | head -20
50+ echo "Total files: $(find public -type f | wc -l)"
51+ echo "::endgroup::"
52+
53+ - name : Minify HTML files
54+ run : |
55+ echo "::group::Minifying HTML files in public/"
56+ find public -name "*.html" -type f | while read file; do
57+ echo "Processing: $file"
58+ original_size=$(stat -c%s "$file")
59+ html-minifier-terser \
60+ --collapse-whitespace \
61+ --remove-comments \
62+ --remove-optional-tags \
63+ --remove-redundant-attributes \
64+ --remove-script-type-attributes \
65+ --remove-tag-whitespace \
66+ --use-short-doctype \
67+ --minify-css true \
68+ --minify-js true \
69+ --output "$file" \
70+ "$file"
71+ new_size=$(stat -c%s "$file")
72+ savings=$((original_size - new_size))
73+ echo "✓ $file: ${original_size}B → ${new_size}B (saved ${savings}B)"
74+ done
75+ echo "::endgroup::"
76+
77+ - name : Minify CSS files
78+ run : |
79+ echo "::group::Minifying CSS files in public/"
80+ find public -name "*.css" -type f | while read file; do
81+ echo "Processing: $file"
82+ original_size=$(stat -c%s "$file")
83+ cleancss --output "$file" "$file"
84+ new_size=$(stat -c%s "$file")
85+ savings=$((original_size - new_size))
86+ echo "✓ $file: ${original_size}B → ${new_size}B (saved ${savings}B)"
87+ done
88+ echo "::endgroup::"
89+
90+ - name : Minify JavaScript files
91+ run : |
92+ echo "::group::Minifying JavaScript files in public/"
93+ find public -name "*.js" -type f | while read file; do
94+ echo "Processing: $file"
95+ original_size=$(stat -c%s "$file")
96+ terser "$file" --compress --mangle --output "$file"
97+ new_size=$(stat -c%s "$file")
98+ savings=$((original_size - new_size))
99+ echo "✓ $file: ${original_size}B → ${new_size}B (saved ${savings}B)"
100+ done
101+ echo "::endgroup::"
102+
103+ - name : Generate build report
104+ run : |
105+ echo "::group::Build Summary"
106+ echo "## Build Report" >> $GITHUB_STEP_SUMMARY
107+ echo "| File Type | Count | Total Size |" >> $GITHUB_STEP_SUMMARY
108+ echo "|-----------|-------|------------|" >> $GITHUB_STEP_SUMMARY
109+
110+ html_count=$(find public -name "*.html" | wc -l)
111+ html_size=$(find public -name "*.html" -exec stat -c%s {} + | awk '{sum+=$1} END {print sum}')
112+ echo "| HTML | $html_count | ${html_size:-0} bytes |" >> $GITHUB_STEP_SUMMARY
113+
114+ css_count=$(find public -name "*.css" | wc -l)
115+ css_size=$(find public -name "*.css" -exec stat -c%s {} + | awk '{sum+=$1} END {print sum}')
116+ echo "| CSS | $css_count | ${css_size:-0} bytes |" >> $GITHUB_STEP_SUMMARY
117+
118+ js_count=$(find public -name "*.js" | wc -l)
119+ js_size=$(find public -name "*.js" -exec stat -c%s {} + | awk '{sum+=$1} END {print sum}')
120+ echo "| JavaScript | $js_count | ${js_size:-0} bytes |" >> $GITHUB_STEP_SUMMARY
121+
122+ total_files=$(find public -type f | wc -l)
123+ total_size=$(find public -type f -exec stat -c%s {} + | awk '{sum+=$1} END {print sum}')
124+ echo "| **Total** | **$total_files** | **${total_size:-0} bytes** |" >> $GITHUB_STEP_SUMMARY
125+
126+ echo "Build completed successfully with $total_files files totaling $total_size bytes"
127+ echo "::endgroup::"
128+
129+ - name : Setup Pages
130+ uses : actions/configure-pages@v5
131+
132+ - name : Upload artifact
133+ uses : actions/upload-pages-artifact@v3
134+ with :
135+ path : ' public/'
136+
137+ - name : Deploy to GitHub Pages
138+ id : deployment
139+ uses : actions/deploy-pages@v4
140+
141+ - name : Deployment success notification
142+ if : success()
143+ run : |
144+ echo "::notice::Deployment successful! Site available at ${{ steps.deployment.outputs.page_url }}"
145+
146+ - name : Deployment failure notification
147+ if : failure()
148+ run : |
149+ echo "::error::Deployment failed. Check the logs above for details."
0 commit comments