Skip to content

Commit 055ba2b

Browse files
committed
Simplify staging workflow: remove copy logic, add test post, trigger on PR
1 parent e716cf4 commit 055ba2b

2 files changed

Lines changed: 42 additions & 75 deletions

File tree

.github/workflows/preview.yml

Lines changed: 13 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
name: Deploy Staging Preview
22

33
on:
4-
push:
5-
branches: [post/updates] # Build staging when changes pushed to updates branch
6-
paths:
7-
- '_posts/**'
8-
- 'staging/**'
9-
- '_config*.yml'
10-
- '_layouts/**'
11-
- '_includes/**'
12-
- 'assets/**'
4+
pull_request:
5+
types: [opened, synchronize, reopened]
136
workflow_dispatch: # Allow manual trigger
147

158
permissions:
@@ -30,40 +23,10 @@ jobs:
3023
ruby-version: '3.1'
3124
bundler-cache: true
3225

33-
- name: Setup staging posts
26+
- name: Show staging content
3427
run: |
35-
echo "=== Setting up staging posts ==="
36-
37-
# Ensure staging directory exists
38-
mkdir -p staging
39-
40-
# Find new or modified .md files in _posts directory
41-
echo "Checking for new/modified posts to stage..."
42-
43-
# Get posts that are new or modified compared to main branch
44-
if git rev-parse origin/main >/dev/null 2>&1; then
45-
echo "Comparing with main branch..."
46-
MODIFIED_POSTS=$(git diff --name-only origin/main...HEAD | grep "^_posts/.*\.md$" || true)
47-
else
48-
echo "Main branch not found, staging all posts..."
49-
MODIFIED_POSTS=$(find _posts -name "*.md" 2>/dev/null || true)
50-
fi
51-
52-
if [ -n "$MODIFIED_POSTS" ]; then
53-
echo "Posts to stage:"
54-
echo "$MODIFIED_POSTS" | while read -r file; do
55-
if [ -f "$file" ]; then
56-
echo " - Staging: $file"
57-
cp "$file" "staging/$(basename "$file")"
58-
fi
59-
done
60-
else
61-
echo "No new/modified posts found to stage"
62-
fi
63-
64-
# Show current staging content
65-
echo "=== Current staging content ==="
66-
echo "Staged posts:"
28+
echo "=== Staging content ==="
29+
echo "Staging posts:"
6730
find staging/ -name "*.md" -not -name "README.md" -not -name "index.md" | sort || echo " (none)"
6831
6932
echo "Published posts:"
@@ -76,49 +39,24 @@ jobs:
7639
# Remove CNAME file for previews to avoid routing conflicts
7740
rm -f CNAME
7841
79-
# Show current directory structure before build
80-
echo "Files before build:"
81-
ls -la
82-
8342
# Build Jekyll site - staging posts will be included as a collection
84-
echo "Running Jekyll build..."
85-
bundle exec jekyll build --config _config.yml,_config_preview.yml --verbose
43+
bundle exec jekyll build --config _config.yml,_config_preview.yml
8644
87-
# Check if build succeeded
88-
if [ $? -eq 0 ]; then
89-
echo "Jekyll build completed successfully"
90-
else
91-
echo "Jekyll build failed!"
45+
# Verify build succeeded
46+
if [ ! -d "_site" ] || [ -z "$(ls -A _site 2>/dev/null)" ]; then
47+
echo "ERROR: Jekyll build failed or created empty _site directory"
9248
exit 1
9349
fi
9450
95-
# Show what was built
96-
echo "Build completed. Checking _site directory:"
97-
if [ -d "_site" ]; then
98-
echo "_site directory exists"
99-
echo "Site structure:"
100-
find _site -name "*.html" | head -10
101-
echo "Total files in _site:"
102-
find _site -type f | wc -l
103-
else
104-
echo "ERROR: _site directory was not created!"
105-
exit 1
106-
fi
51+
echo "Build completed successfully"
52+
echo "Files built: $(find _site -type f | wc -l)"
10753
env:
10854
JEKYLL_ENV: production
10955

11056
- name: Deploy staging site
11157
run: |
11258
echo "=== Deploying staging site ==="
11359
114-
# Verify _site directory exists before proceeding
115-
if [ ! -d "_site" ]; then
116-
echo "ERROR: _site directory not found. Build must have failed."
117-
exit 1
118-
fi
119-
120-
echo "_site directory found, proceeding with deployment..."
121-
12260
# Switch to gh-pages branch
12361
git fetch origin gh-pages:gh-pages || git checkout --orphan gh-pages
12462
git checkout gh-pages
@@ -130,11 +68,11 @@ jobs:
13068
# Copy built site to root of gh-pages
13169
cp -r _site/* ./
13270
133-
# Commit and push the full staging site
71+
# Commit and push the staging site
13472
git add -A
13573
git config user.name "GitHub Actions"
13674
git config user.email "actions@github.com"
137-
git commit -m "Deploy staging preview from ${{ github.ref_name }} (${{ github.sha }})" || exit 0
75+
git commit -m "Deploy staging preview from PR #${{ github.event.number }}" || exit 0
13876
git push origin gh-pages
13977
14078
echo "=== Staging deployment complete ==="
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
layout: post
3+
title: "Test Staging Post"
4+
date: 2025-06-10 12:00:00 -0500
5+
tags: [test, staging]
6+
---
7+
8+
# Test Staging Post
9+
10+
This is a test post that lives directly in the staging directory.
11+
12+
## Purpose
13+
14+
This post is used to test the staging preview system:
15+
16+
- It's a real blog post with proper front matter
17+
- It lives in the `staging/` directory
18+
- It will be built as part of the staging collection
19+
- It appears in the preview site
20+
21+
## Content
22+
23+
This is just sample content to verify that:
24+
25+
1. Jekyll can build staging posts
26+
2. The staging collection works
27+
3. Posts appear in the preview deployment
28+
29+
When this works, we know the staging system is functioning correctly!

0 commit comments

Comments
 (0)