Skip to content

Add preview deployment workflow for pull requests#3

Merged
elft3r merged 8 commits intomainfrom
claude/add-cloudflare-preview-oDPVo
Mar 20, 2026
Merged

Add preview deployment workflow for pull requests#3
elft3r merged 8 commits intomainfrom
claude/add-cloudflare-preview-oDPVo

Conversation

@elft3r
Copy link
Owner

@elft3r elft3r commented Mar 20, 2026

Summary

This PR adds a GitHub Actions workflow that automatically deploys pull requests to Cloudflare Pages for preview testing, and cleans up deployments when PRs are closed.

Key Changes

  • New workflow file: .github/workflows/preview.yml that handles preview deployments
  • Deploy on PR events: Automatically builds and deploys to Cloudflare Pages when a PR is opened, synchronized, or reopened
  • PR comments: Posts deployment URLs as comments on PRs, updating existing comments on subsequent pushes
  • Cleanup on close: Automatically deletes preview deployments from Cloudflare Pages when a PR is closed
  • Concurrency control: Ensures only one deployment runs per PR at a time, canceling previous in-progress deployments

Implementation Details

  • Uses Node.js 20 with npm caching for faster builds
  • Deploys to Cloudflare Pages with branch alias pr-{PR_NUMBER} for easy identification
  • Gracefully handles project creation if it doesn't exist yet
  • Implements pagination when listing Cloudflare deployments to handle large numbers of deployments
  • Uses GitHub Script action to manage PR comments, finding and updating existing bot comments instead of creating duplicates
  • Requires CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID secrets to be configured

https://claude.ai/code/session_01P7QZZ9gtBDbS6BeoLdrPMt

Adds a GitHub Actions workflow that deploys PR previews to Cloudflare Pages,
matching the same mechanism used in the presentations repo. On PR open/update
it builds the Docusaurus site and deploys it, commenting a preview URL on
the PR. On PR close it cleans up the preview deployments.

Requires CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID repository secrets.

https://claude.ai/code/session_01P7QZZ9gtBDbS6BeoLdrPMt
@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Preview Deployment

This PR has been deployed for preview:

Site URL Commit
DevOps Training https://b18eb40a.devops-training-01p.pages.dev 031d6cc

Last updated: Fri, 20 Mar 2026 20:26:16 GMT

claude added 6 commits March 20, 2026 09:45
Wrap long lines to stay within 80 character limit and add YAML
document start marker to pass super-linter checks.

https://claude.ai/code/session_01P7QZZ9gtBDbS6BeoLdrPMt
Checkov (run by super-linter) requires workflows to declare explicit
top-level permissions rather than relying on defaults. Add minimal
permissions blocks to linter, test deploy, and deploy workflows.

https://claude.ai/code/session_01P7QZZ9gtBDbS6BeoLdrPMt
Add yamllint disable-line directives for the truthy rule on `on:` keys
in all GitHub Actions workflow files. The `on` key triggers a yamllint
truthy warning which super-linter treats as an error.

https://claude.ai/code/session_01P7QZZ9gtBDbS6BeoLdrPMt
- Apply Prettier formatting to all workflow YAML files
- Add USER instruction to Dockerfile (CKV_DOCKER_3)
- Add HEALTHCHECK instruction to Dockerfile (CKV_DOCKER_2)

https://claude.ai/code/session_01P7QZZ9gtBDbS6BeoLdrPMt
- Remove gh-pages-test-deploy.yml since preview.yml already validates
  the build on every PR
- Add commit SHA to preview deployment comment for traceability
- Add page-limit safety valve (max 50) in cleanup pagination
- Move permissions to job-level for least privilege
- Drop unnecessary issues: write permission

https://claude.ai/code/session_01P7QZZ9gtBDbS6BeoLdrPMt
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a GitHub Actions-based preview deployment pipeline for pull requests using Cloudflare Pages, and updates existing CI/CD workflows to align with the new approach.

Changes:

  • Added a new PR-triggered workflow to build, deploy, comment the preview URL, and clean up Cloudflare Pages preview deployments.
  • Updated existing GitHub Actions workflows (lint + GitHub Pages deploy) and removed the older GitHub Pages test-deploy workflow.
  • Updated the Docker image configuration to run as a non-root user and added a container healthcheck.

Reviewed changes

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

Show a summary per file
File Description
Dockerfile Runs container as node user and adds a healthcheck (but introduces a likely runtime permission issue).
.github/workflows/preview.yml New Cloudflare Pages preview deploy + PR comment + cleanup workflow (has permission + pagination/commit-SHA issues).
.github/workflows/linter.yml Tweaks workflow YAML and adds explicit permissions.
.github/workflows/gh-pages-test-deploy.yml Removes the prior PR build-only workflow.
.github/workflows/gh-pages-deploy.yml Adds explicit permissions (currently breaks deployment by making contents read-only).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Dockerfile: add --chown=node:node to COPY so /app is writable as node
- preview.yml: add issues: write permission for PR comment API calls
- preview.yml: use github.paginate() for listComments to handle >30 comments
- preview.yml: use PR head SHA instead of merge commit SHA
- gh-pages-deploy.yml: grant contents: write for gh-pages branch push

https://claude.ai/code/session_01P7QZZ9gtBDbS6BeoLdrPMt
@elft3r elft3r merged commit feb3375 into main Mar 20, 2026
2 of 4 checks passed
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.

3 participants