1+ # PR validation workflow - test builds and content quality
2+ name : PR Validation
3+
4+ on :
5+ pull_request :
6+ branches :
7+ - main
8+ paths :
9+ - ' content/**'
10+ - ' config.yaml'
11+ - ' go.mod'
12+ - ' layouts/**'
13+ - ' assets/**'
14+ - ' static/**'
15+ - ' .github/workflows/**'
16+
17+ jobs :
18+ validate-build :
19+ runs-on : ubuntu-latest
20+ steps :
21+ - uses : actions/checkout@v4.1.7
22+ with :
23+ fetch-depth : 0
24+
25+ - name : Setup Go
26+ uses : actions/setup-go@v5.2.0
27+ with :
28+ go-version : ' 1.20.14'
29+
30+ - name : Setup Hugo
31+ uses : peaceiris/actions-hugo@v2.6.0
32+ with :
33+ hugo-version : ' 0.148.1'
34+ extended : true
35+
36+ - name : Setup Hugo Modules
37+ run : |
38+ hugo mod tidy
39+ hugo mod get github.com/jpanther/congo/v2@v2.12.2
40+
41+ - name : Validate Hugo Configuration
42+ run : |
43+ echo "Validating Hugo configuration..."
44+ hugo config
45+ echo "✅ Configuration is valid"
46+
47+ - name : Check for Draft Posts
48+ run : |
49+ echo "Checking for draft posts..."
50+ DRAFTS=$(hugo list drafts | wc -l)
51+ if [ $DRAFTS -gt 1 ]; then
52+ echo "⚠️ Found $((DRAFTS-1)) draft posts"
53+ hugo list drafts
54+ else
55+ echo "✅ No draft posts found"
56+ fi
57+
58+ - name : Check for Future Posts
59+ run : |
60+ echo "Checking for future posts..."
61+ FUTURE=$(hugo list future | wc -l)
62+ if [ $FUTURE -gt 1 ]; then
63+ echo "⚠️ Found $((FUTURE-1)) future posts"
64+ hugo list future
65+ echo "Note: Future posts are built with --buildFuture flag in production"
66+ else
67+ echo "✅ No future posts found"
68+ fi
69+
70+ - name : Test Build (Development)
71+ run : |
72+ echo "Testing development build..."
73+ hugo --buildDrafts --buildFuture --verbose
74+ echo "✅ Development build successful"
75+
76+ - name : Test Build (Production)
77+ run : |
78+ echo "Testing production build..."
79+ hugo --minify --buildFuture --verbose
80+ echo "✅ Production build successful"
81+
82+ - name : Check Build Output
83+ run : |
84+ echo "Analysing build output..."
85+ echo "Total pages: $(find public -name "*.html" | wc -l)"
86+ echo "Total assets: $(find public -type f ! -name "*.html" | wc -l)"
87+ echo "Site size: $(du -sh public | cut -f1)"
88+
89+ # Check for common issues
90+ if [ ! -f "public/index.html" ]; then
91+ echo "❌ Missing homepage!"
92+ exit 1
93+ fi
94+
95+ if [ ! -f "public/posts/index.html" ]; then
96+ echo "❌ Missing posts index!"
97+ exit 1
98+ fi
99+
100+ echo "✅ Build output looks good"
101+
102+ validate-content :
103+ runs-on : ubuntu-latest
104+ steps :
105+ - uses : actions/checkout@v4.1.7
106+ with :
107+ fetch-depth : 0
108+
109+ - name : Check Markdown Files
110+ run : |
111+ echo "Validating markdown files..."
112+
113+ # Check for files with missing front matter
114+ for file in content/posts/*.md; do
115+ if [ -f "$file" ]; then
116+ if ! head -1 "$file" | grep -q "^---"; then
117+ echo "❌ Missing front matter in $file"
118+ exit 1
119+ fi
120+ fi
121+ done
122+
123+ # Check for required front matter fields
124+ for file in content/posts/*.md; do
125+ if [ -f "$file" ]; then
126+ if ! grep -q "^title:" "$file"; then
127+ echo "❌ Missing title in $file"
128+ exit 1
129+ fi
130+ if ! grep -q "^date:" "$file"; then
131+ echo "❌ Missing date in $file"
132+ exit 1
133+ fi
134+ fi
135+ done
136+
137+ echo "✅ All markdown files have valid front matter"
138+
139+ - name : Check for Broken Internal Links
140+ run : |
141+ echo "Checking for potential broken internal links..."
142+
143+ # Look for common broken link patterns
144+ if grep -r "](http://localhost" content/; then
145+ echo "❌ Found localhost links in content"
146+ exit 1
147+ fi
148+
149+ # Check for missing project references
150+ if grep -r "](/projects/" content/; then
151+ echo "Found internal project links, checking they exist..."
152+ for link in $(grep -ro "](/projects/[^)]*)" content/ | sed 's/.*](/projects//;s/[)].*//' | sort -u); do
153+ if [ ! -d "content/projects$link" ] && [ ! -f "content/projects$link.md" ] && [ ! -f "content/projects$link/index.md" ]; then
154+ echo "❌ Broken internal link: /projects$link"
155+ exit 1
156+ fi
157+ done
158+ fi
159+
160+ echo "✅ No obvious broken internal links found"
161+
162+ validate-images :
163+ runs-on : ubuntu-latest
164+ steps :
165+ - uses : actions/checkout@v4.1.7
166+
167+ - name : Check Image References
168+ run : |
169+ echo "Checking image references in content..."
170+
171+ # Find all image references in markdown
172+ for file in content/**/*.md; do
173+ if [ -f "$file" ]; then
174+ # Check for markdown image syntax
175+ grep -n "!\[.*\](" "$file" | while read -r line; do
176+ image_path=$(echo "$line" | sed 's/.*!\[.*\](\([^)]*\)).*/\1/')
177+
178+ # Skip external URLs
179+ if [[ "$image_path" =~ ^https?:// ]]; then
180+ continue
181+ fi
182+
183+ # Check if local image exists
184+ if [[ "$image_path" =~ ^/ ]]; then
185+ # Absolute path
186+ full_path="static${image_path}"
187+ else
188+ # Relative path
189+ dir=$(dirname "$file")
190+ full_path="${dir}/${image_path}"
191+ fi
192+
193+ if [ ! -f "$full_path" ]; then
194+ echo "❌ Missing image: $image_path referenced in $file"
195+ echo " Expected at: $full_path"
196+ fi
197+ done
198+ fi
199+ done
200+
201+ echo "✅ Image reference check complete"
202+
203+ summary :
204+ runs-on : ubuntu-latest
205+ needs : [validate-build, validate-content, validate-images]
206+ if : always()
207+ steps :
208+ - name : PR Validation Summary
209+ run : |
210+ echo "## PR Validation Results 📝" >> $GITHUB_STEP_SUMMARY
211+ echo "" >> $GITHUB_STEP_SUMMARY
212+
213+ if [ "${{ needs.validate-build.result }}" == "success" ]; then
214+ echo "✅ **Build Validation**: Passed" >> $GITHUB_STEP_SUMMARY
215+ else
216+ echo "❌ **Build Validation**: Failed" >> $GITHUB_STEP_SUMMARY
217+ fi
218+
219+ if [ "${{ needs.validate-content.result }}" == "success" ]; then
220+ echo "✅ **Content Validation**: Passed" >> $GITHUB_STEP_SUMMARY
221+ else
222+ echo "❌ **Content Validation**: Failed" >> $GITHUB_STEP_SUMMARY
223+ fi
224+
225+ if [ "${{ needs.validate-images.result }}" == "success" ]; then
226+ echo "✅ **Image Validation**: Passed" >> $GITHUB_STEP_SUMMARY
227+ else
228+ echo "❌ **Image Validation**: Failed" >> $GITHUB_STEP_SUMMARY
229+ fi
230+
231+ echo "" >> $GITHUB_STEP_SUMMARY
232+ echo "Your PR is ready to merge! 🚀" >> $GITHUB_STEP_SUMMARY
0 commit comments