Skip to content

Commit d5ad0cf

Browse files
HeyItsGilbertclaude
andcommitted
Split Hugo workflow into separate build and deploy jobs
Build runs on PRs (read-only) to validate the site compiles. Deploy runs on push to main and commits the built site to docs/. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 85969eb commit d5ad0cf

2 files changed

Lines changed: 96 additions & 27 deletions

File tree

.github/workflows/build.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Build Hugo Site
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
env:
13+
HUGO_VERSION: 0.155.1
14+
steps:
15+
- name: Install Hugo CLI
16+
run: |
17+
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
18+
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
19+
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
submodules: recursive
24+
fetch-depth: 0
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '18'
30+
31+
- name: Install Node dependencies
32+
run: |
33+
if [ -f package.json ]; then
34+
npm install
35+
fi
36+
37+
- name: Create data directory
38+
run: mkdir -p data
39+
40+
- name: Update community stats
41+
run: |
42+
if [ -f .github/scripts/fetch-discourse-activity.js ]; then
43+
echo "Running Discourse activity script..."
44+
node .github/scripts/fetch-discourse-activity.js || true
45+
fi
46+
47+
if [ ! -f data/community_stats.json ]; then
48+
echo "Creating fallback community stats..."
49+
cat > data/community_stats.json << 'EOF'
50+
{
51+
"activities": [
52+
{
53+
"message": "PowerShell community thriving",
54+
"time": "Ongoing",
55+
"type": "community",
56+
"color": "bg-blue-500"
57+
}
58+
],
59+
"stats": {
60+
"total_topics": 15000,
61+
"total_posts": 80000,
62+
"active_users": 12000,
63+
"topics_this_week": 40
64+
},
65+
"last_updated": "2024-01-01T00:00:00.000Z",
66+
"fallback": true
67+
}
68+
EOF
69+
fi
70+
71+
- name: Build with Hugo
72+
env:
73+
HUGO_ENVIRONMENT: production
74+
HUGO_ENV: production
75+
run: |
76+
hugo \
77+
--gc \
78+
--minify \
79+
--destination docs
Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
name: Build and Deploy Hugo Site
1+
name: Deploy Hugo Site
22

33
on:
44
push:
55
branches:
66
- main
7-
pull_request:
87

98
permissions:
109
contents: write
11-
pages: write
12-
id-token: write
1310

1411
jobs:
15-
build-and-deploy:
12+
deploy:
1613
runs-on: ubuntu-latest
1714
env:
1815
HUGO_VERSION: 0.155.1
@@ -21,27 +18,27 @@ jobs:
2118
run: |
2219
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
2320
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
24-
21+
2522
- name: Checkout
2623
uses: actions/checkout@v4
2724
with:
2825
submodules: recursive
2926
fetch-depth: 0
30-
27+
3128
- name: Setup Node.js
3229
uses: actions/setup-node@v4
3330
with:
3431
node-version: '18'
35-
32+
3633
- name: Install Node dependencies
3734
run: |
3835
if [ -f package.json ]; then
3936
npm install
4037
fi
41-
38+
4239
- name: Create data directory
4340
run: mkdir -p data
44-
41+
4542
- name: Update community stats
4643
run: |
4744
if [ -f .github/scripts/fetch-discourse-activity.js ]; then
@@ -116,49 +113,42 @@ jobs:
116113
}
117114
EOF
118115
fi
119-
116+
120117
- name: Verify community stats file exists
121118
run: |
122119
if [ -f data/community_stats.json ]; then
123-
echo "✅ Community stats file created successfully"
124-
echo "File contents:"
120+
echo "Community stats file created successfully"
125121
cat data/community_stats.json
126122
else
127-
echo "Community stats file not found"
123+
echo "Community stats file not found"
128124
exit 1
129125
fi
130-
126+
131127
- name: Build with Hugo
132128
env:
133129
HUGO_ENVIRONMENT: production
134130
HUGO_ENV: production
135131
run: |
136-
# Clean docs directory
137132
rm -rf docs
138-
139-
# Build Hugo site to docs directory
140133
hugo \
141134
--gc \
142135
--minify \
143-
--destination docs \
144-
136+
--destination docs
137+
145138
- name: Add .nojekyll file
146139
run: touch docs/.nojekyll
147-
140+
148141
- name: Commit and push to main
149142
run: |
150143
git config --local user.email "action@github.com"
151144
git config --local user.name "GitHub Action"
152-
153-
# Add files that exist
145+
154146
git add docs/ || echo "No docs directory to add"
155-
156-
# Only add data files if they exist
147+
157148
if [ -f data/community_stats.json ]; then
158149
git add data/community_stats.json
159150
fi
160-
161-
# Only commit if there are changes
151+
162152
if ! git diff --staged --quiet; then
163153
git commit -m "Deploy Hugo site to docs/ [skip ci]"
164154
git push

0 commit comments

Comments
 (0)