Skip to content

Add PR preview deployments with GitHub Pages - #1

Merged
mithro merged 2 commits into
mainfrom
development
Jul 5, 2025
Merged

Add PR preview deployments with GitHub Pages#1
mithro merged 2 commits into
mainfrom
development

Conversation

@mithro

@mithro mithro commented Jul 4, 2025

Copy link
Copy Markdown
Contributor

Summary

• Adds automatic preview deployments for pull requests using GitHub Pages
• Each PR gets a custom preview URL at https://preview.wafer.space/pr-123/
• Automatic cleanup when PRs are closed
• Clean commit history with logical progression

Features Added

GitHub Actions workflow for PR preview deployments with custom domain support
External templates and scripts for maintainability and clean separation of concerns
Deployment tracking using GitHub Deployments API with environment status
Preview index page listing all active previews at https://preview.wafer.space/
Automatic PR comments with preview URLs and deployment status
Proper error handling that fails fast on real problems instead of silent suppression

Technical Details

• Uses Jekyll with PR-specific base URLs for proper routing
• SSH deploy key integration for private theme submodule access
• Custom domain configuration with CNAME file generation
• Comprehensive documentation for users and maintainers

Test Plan

  • Verify workflow triggers on PR open/sync/close events
  • Test Jekyll build with PR-specific base URL
  • Confirm preview deployment to correct custom domain path
  • Validate preview index page generation and styling
  • Test automatic cleanup when PR is closed
  • Verify deployment status tracking and PR comments

🤖 Generated with Claude Code

@github-actions
github-actions Bot had a problem deploying to pr-preview-1 July 4, 2025 20:57 Failure
@github-actions
github-actions Bot had a problem deploying to pr-preview-1 July 4, 2025 21:16 Failure
@github-actions
github-actions Bot had a problem deploying to pr-preview-1 July 4, 2025 21:40 Failure
@github-actions
github-actions Bot had a problem deploying to pr-preview-1 July 4, 2025 21:47 Failure
@github-actions
github-actions Bot had a problem deploying to pr-preview-1 July 4, 2025 21:56 Failure
@github-actions
github-actions Bot had a problem deploying to pr-preview-1 July 4, 2025 21:58 Failure
@github-actions
github-actions Bot had a problem deploying to pr-preview-1 July 4, 2025 22:01 Failure
@github-actions
github-actions Bot had a problem deploying to pr-preview-1 July 4, 2025 22:03 Failure
github-actions Bot added a commit that referenced this pull request Jul 4, 2025
github-actions Bot added a commit that referenced this pull request Jul 4, 2025
@github-actions

github-actions Bot commented Jul 4, 2025

Copy link
Copy Markdown

🚀 Preview Deployment Ready!

Status Preview URL Commit
✅ Success View Preview aacf4a7

This preview will be automatically updated when you push new commits to this PR.

Browse all previews: https://preview.wafer.space


⚡ Deployed to custom domain • Preview will be removed when PR is closed

github-actions Bot added a commit that referenced this pull request Jul 4, 2025
@github-actions
github-actions Bot had a problem deploying to pr-preview-1 July 4, 2025 22:20 Failure
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 4, 2025 22:49 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 4, 2025 22:52 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 4, 2025 23:02 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 4, 2025 23:06 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 4, 2025 23:08 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 4, 2025 23:20 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 00:04 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 00:15 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:12 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:14 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:16 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:18 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:24 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:26 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:27 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:30 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:34 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:44 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:47 Destroyed
mithro and others added 2 commits July 4, 2025 23:53
Add critical guidance about verifying working directory before running
commands due to complex submodule architecture and multiple working directories.

Key guidance:
• Always verify current working directory with pwd before commands
• Main repository root: ./ (top-level directory with _config.yml)
• Theme submodule: ./_theme/ (contains Jekyll theme files)
• Preview cleanup: /tmp/preview-cleanup/ (temporary cleanup workspace)
• Temporary directories: _tmp/preview-repo/ (relative to repository root)

Common mistakes addressed:
• Running Jekyll commands from wrong directory
• Editing theme files when not in _theme/ directory
• Git operations in wrong repository context

This prevents common development errors and ensures commands are run
in the correct context for this complex repository architecture.
Implements a comprehensive GitHub Actions workflow for automatically deploying
pull request previews to a custom domain at preview.wafer.space.

Core features:
• Automatic PR preview deployments at https://preview.wafer.space/pr-{number}/
• GitHub Deployments API integration with status tracking
• Secure SSH authentication for private theme submodule access
• Custom domain deployment using dedicated preview repository
• Automatic cleanup when PRs are closed
• Professional PR comments with deployment status
• Central preview index page listing all active previews

Architecture:
• Modular JavaScript modules for GitHub API interactions
• Reusable Markdown templates for consistent messaging
• Jekyll builds with PR-specific baseurl configuration
• Dedicated preview.wafer.space repository avoids CNAME conflicts
• Memory-only SSH key handling for enhanced security

This provides a solid foundation for PR preview functionality with
enterprise-grade security practices and maintainable code organization.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
github-actions Bot temporarily deployed to pr-preview-1 July 5, 2025 06:53 Destroyed
@mithro
mithro requested a review from Copilot July 5, 2025 08:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a GitHub Actions workflow and supporting scripts/templates to build, deploy, and track Jekyll-based preview environments for each pull request on a custom GitHub Pages domain, with automatic cleanup on PR close.

  • Introduces .github/workflows/pr-preview.yml to build and deploy previews per PR
  • Adds scripts in .github/scripts/ for creating deployments, updating status, generating directories, and commenting PRs
  • Provides template files in .github/templates/ and documentation updates for users and local workflows

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
CLAUDE.md Adds a critical reminder to verify working directory
.github/workflows/pr-preview.yml New Actions workflow for PR preview deployments
.github/workflows/pr-preview.md Markdown docs for the PR preview workflow
.github/templates/redirect-template.html HTML template for slugified redirect pages
.github/templates/preview-index.html Template for the central index of active PR previews
.github/templates/pr-comment-template.md Template for the success comment posted on PRs
.github/templates/pr-cleanup-template.md Template for cleanup notification on closed PRs
.github/scripts/create-deployment.js Script to create GitHub Deployment entries
.github/scripts/update-deployment-status.js Script to mark deployments as success/failure/inactive
.github/scripts/generate-pr-directory-name.js Module to slugify PR titles into directory names
.github/scripts/generate-preview-index.sh Bash script to build the preview index page
.github/scripts/comment-pr-preview.js Script to post or update preview status comments on PR
.github/scripts/comment-pr-cleanup.js Script to comment on PR when its preview is removed
.github/scripts/cleanup-deployments.js Marks all deployments inactive when a PR is closed
.claude/settings.local.json Local Claude tooling settings updated with new commands
Comments suppressed due to low confidence (2)

.github/workflows/pr-preview.yml:19

  • Consider using a per-PR concurrency group (e.g., pr-preview-${{ github.event.pull_request.number }}) so builds for different PRs don’t block each other.
  group: pr-preview-deployment

.github/workflows/pr-preview.yml:161

  • Exiting with exit 1 when there are no changes marks the step as a failure—use exit 0 or skip pushing to avoid failing the job when no changes occur.
          if git diff --staged --quiet; then

Comment on lines +81 to +82
# Replace placeholder with actual items
if ! sed -i "s|<!-- PREVIEW_ITEMS_PLACEHOLDER -->|$PREVIEW_ITEMS|g" "$OUTPUT_FILE"; then

Copilot AI Jul 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Embedding raw HTML in a single sed replacement can break if $PREVIEW_ITEMS contains the delimiter or unescaped characters; consider using a here-document or safer template engine for placeholder insertion.

Suggested change
# Replace placeholder with actual items
if ! sed -i "s|<!-- PREVIEW_ITEMS_PLACEHOLDER -->|$PREVIEW_ITEMS|g" "$OUTPUT_FILE"; then
# Replace placeholder with actual items using a here-document
if ! {
awk -v preview_items="$PREVIEW_ITEMS" '
/<!-- PREVIEW_ITEMS_PLACEHOLDER -->/ { print preview_items; next }
{ print }
' "$TEMPLATE_FILE" > "$OUTPUT_FILE";
}; then

Copilot uses AI. Check for mistakes.

// Validate template path to prevent directory traversal
const resolvedPath = path.resolve(templatePath);
if (!resolvedPath.includes('.github/templates/pr-comment-template.md')) {

Copilot AI Jul 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The includes check may be too permissive—use a strict equality or path comparison (e.g., resolvedPath === path.resolve(templatePath)) to prevent directory traversal risks.

Suggested change
if (!resolvedPath.includes('.github/templates/pr-comment-template.md')) {
const expectedPath = path.resolve('.github/templates/pr-comment-template.md');
if (resolvedPath !== expectedPath) {

Copilot uses AI. Check for mistakes.
@mithro
mithro merged commit 6db320a into main Jul 5, 2025
@mithro
mithro deleted the development branch July 5, 2025 08:51
@github-actions

github-actions Bot commented Jul 5, 2025

Copy link
Copy Markdown

🧹 Preview Deployment Removed

The preview deployment for this PR has been removed from https://preview.wafer.space

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants