Add PR preview deployments for website changes#172
Conversation
- Add Cloudflare Pages deployment workflow (preview-deploy.yml) - Add artifact-based preview workflow (pr-preview-artifact.yml) - Add documentation for setup (PREVIEW_DEPLOYMENT.md) - Update CONTRIBUTING.md with preview deployment info Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
🚀 Preview DeploymentA preview build has been generated for this PR! Download the artifact: To view the preview locally:
Live Preview URL: https://b95d7f26.razorconsole.pages.dev The live preview will be automatically updated when you push new |
LittleLittleCloud
left a comment
There was a problem hiding this comment.
@copilot resolve comments
- Merge pr-preview-artifact.yml and preview-deploy.yml - Single workflow now uploads artifacts AND deploys to Cloudflare - Add workflow_dispatch for manual invocation - Update documentation to reflect combined workflow - Cloudflare deployment continues on error if secrets not configured Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
- Use descriptive artifact names for manual runs (branch-runNumber) - Add 'main' as final fallback for branch detection - Better support for workflow_dispatch scenarios Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
website | 3255333 | Nov 23 2025, 04:46 PM |
Signed-off-by: Xiaoyun Zhang <bigmiao.zhang@gmail.com>
Signed-off-by: Xiaoyun Zhang <bigmiao.zhang@gmail.com>
Simplified the pages deploy command in the workflow. Signed-off-by: Xiaoyun Zhang <bigmiao.zhang@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds automated preview deployments for website changes, enabling contributors and reviewers to see changes before merging. The implementation provides a unified workflow that always uploads build artifacts and optionally deploys to Cloudflare Pages when secrets are configured.
Key Changes:
- Combined GitHub Actions workflow supporting both artifact uploads and optional Cloudflare deployment
- Automatic PR comments with download links and optional live preview URLs
- Documentation for setup and usage in CONTRIBUTING.md and .github/PREVIEW_DEPLOYMENT.md
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
.github/workflows/pr-preview-artifact.yml |
New workflow that builds website on PR changes, uploads artifacts, optionally deploys to Cloudflare Pages, and comments on PRs with preview information |
.github/PREVIEW_DEPLOYMENT.md |
Comprehensive setup guide for optional Cloudflare Pages integration, including credentials configuration and workflow testing |
CONTRIBUTING.md |
Added section documenting the automated preview deployment feature for contributors |
| 3. Serve the files with a local web server | ||
| (e.g., \`npx serve dist\`) |
There was a problem hiding this comment.
The instruction references serving dist directory, but after extracting the artifact ZIP file, the directory structure may differ. The artifact is created from website/dist, so after extraction, the files might be at the root of the extracted folder or in a subdirectory.
Consider clarifying the instruction to be more explicit:
3. Serve the extracted files with a local web server
(e.g., `cd website-preview-123` && `npx serve .`)
Or provide clearer guidance about the expected directory structure after extraction.
| 3. Serve the files with a local web server | |
| (e.g., \`npx serve dist\`) | |
| 3. Serve the extracted files with a local web server | |
| (e.g., \`cd website-preview-pr-${prNumber}\` && \`npx serve .\`) |
| - name: Deploy to Cloudflare Pages | ||
| id: deploy | ||
| continue-on-error: true | ||
| uses: cloudflare/wrangler-action@v3 | ||
| with: | ||
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
| command: | | ||
| pages project list | ||
| pages deploy website/dist --project-name=razorconsole --branch=${{ github.head_ref || github.ref_name || 'main' }} | ||
|
|
||
| - name: Comment PR with preview info | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const prNumber = context.issue.number; | ||
| const runId = context.runId; | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const artifactUrl = | ||
| `https://github.com/${owner}/${repo}/actions/runs/${runId}`; | ||
| const deploymentUrl = '${{ steps.deploy.outputs.deployment-url }}'; |
There was a problem hiding this comment.
The deployment-url output from the wrangler-action step may not be populated when using a custom command parameter. The action's outputs are typically only available when using its built-in deployment parameters rather than raw CLI commands.
This means the live preview URL might not appear in PR comments even when Cloudflare deployment succeeds. The workflow would need to either:
- Parse the deployment URL from the wrangler CLI output and set it as a step output
- Use wrangler-action's native parameters if they support Pages deployment
- Accept that users must check workflow logs for the deployment URL
Consider testing whether steps.deploy.outputs.deployment-url is actually populated with the current configuration.
| const botComment = comments.find(comment => | ||
| comment.user.type === 'Bot' && | ||
| (comment.body.includes('Preview Deployment') || | ||
| comment.body.includes('Preview Build Artifact')) |
There was a problem hiding this comment.
[nitpick] Variable shadowing: the inner comment variable in the find callback (line 108) shadows the outer comment variable declared on line 72. While this works correctly in JavaScript, it can reduce code clarity.
Consider renaming the callback parameter to avoid confusion:
const botComment = comments.find(c =>
c.user.type === 'Bot' &&
(c.body.includes('Preview Deployment') ||
c.body.includes('Preview Build Artifact'))
);This makes it clearer that you're iterating over individual comment objects to find a specific one.
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| (comment.body.includes('Preview Deployment') || | |
| comment.body.includes('Preview Build Artifact')) | |
| const botComment = comments.find(c => | |
| c.user.type === 'Bot' && | |
| (c.body.includes('Preview Deployment') || | |
| c.body.includes('Preview Build Artifact')) |
| A preview build has been generated for this PR! | ||
|
|
||
| **Download the artifact:** | ||
| [website-preview-pr-${prNumber}](${artifactUrl}) |
There was a problem hiding this comment.
The artifact name in the PR comment (website-preview-pr-${prNumber}) doesn't match the actual artifact name format defined in line 43 (website-preview-${{ github.event.pull_request.number || format('{0}-{1}', github.ref_name, github.run_number) }}).
For a pull request, the actual artifact name would be website-preview-123 (not website-preview-pr-123). This inconsistency could confuse users trying to locate the artifact.
Suggested fix: Change line 77 to use website-preview-${prNumber} to match the actual artifact naming pattern.
| [website-preview-pr-${prNumber}](${artifactUrl}) | |
| [website-preview-${prNumber}](${artifactUrl}) |
| command: | | ||
| pages project list | ||
| pages deploy website/dist --project-name=razorconsole --branch=${{ github.head_ref || github.ref_name || 'main' }} |
There was a problem hiding this comment.
The pages project list command on line 55 appears to be unnecessary before the actual deployment. This command lists all pages projects but doesn't contribute to the deployment process.
Consider removing this command and simplifying the deployment to just:
command: pages deploy website/dist --project-name=razorconsole --branch=${{ github.head_ref || github.ref_name || 'main' }}This will reduce execution time and potential noise in logs.
| command: | | |
| pages project list | |
| pages deploy website/dist --project-name=razorconsole --branch=${{ github.head_ref || github.ref_name || 'main' }} | |
| command: pages deploy website/dist --project-name=razorconsole --branch=${{ github.head_ref || github.ref_name || 'main' }} |
Enables automated preview deployments when PRs modify the website, allowing contributors and reviewers to see changes before merging.
Implementation
A unified workflow provides both artifact uploads and optional Cloudflare deployment:
Combined preview workflow (
.github/workflows/pr-preview-artifact.yml)website/**changes or manual workflow dispatchCLOUDFLARE_API_TOKENandCLOUDFLARE_ACCOUNT_IDsecretsThe workflow updates existing comments rather than creating duplicates and gracefully handles missing Cloudflare secrets.
Example PR Comment
Without Cloudflare configured:
With Cloudflare configured:
Files Changed
.github/workflows/pr-preview-artifact.yml- Combined workflow (artifact + optional Cloudflare).github/PREVIEW_DEPLOYMENT.md- Setup guide for optional Cloudflare deploymentCONTRIBUTING.md- Preview deployment documentationFixes #171
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.