ci(pages): support main deploy with isolated PR previews#6
Conversation
|
🚀 PR Preview deployed!
Run |
There was a problem hiding this comment.
Pull request overview
Updates the GitHub Pages deployment strategy for the UI-theme showcase so that main continues to publish to the Pages root while pull requests publish isolated previews under a PR-numbered subdirectory, with a companion workflow to clean up previews when PRs close.
Changes:
- Deploy
mainbuilds to thegh-pagesroot while preservingpreviews/content; deploy PR builds topreviews/pr-<number>/. - Add path filters so the deploy workflow only runs when relevant files change.
- Add a cleanup workflow to remove
previews/pr-<number>/when a PR is closed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
.github/workflows/deploy-showcase-pages.yml |
Splits prod vs PR preview publish locations on gh-pages, adds path filters, updates preview URL/comment text. |
.github/workflows/cleanup-showcase-preview.yml |
Adds a PR-close workflow intended to delete the corresponding preview directory from gh-pages. |
| - name: Remove preview directory from gh-pages | ||
| run: | | ||
| if ! git ls-remote --exit-code --heads origin gh-pages > /dev/null 2>&1; then | ||
| echo "gh-pages does not exist; nothing to clean." | ||
| exit 0 | ||
| fi | ||
|
|
||
| git fetch origin gh-pages | ||
| git worktree add --detach ./gh-pages-out FETCH_HEAD |
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "showcase/**" | ||
| - "styles/**" | ||
| - "index.css" | ||
| - ".github/workflows/deploy-showcase-pages.yml" |
| on: | ||
| pull_request: | ||
| types: | ||
| - closed | ||
|
|
| if ! git diff --staged --quiet; then | ||
| git commit -m "Deploy: ${{ github.sha }}" | ||
| git commit -m "Deploy (${{ github.event_name }}): ${{ github.sha }}" | ||
| git push --force origin HEAD:refs/heads/gh-pages |
| git add -A | ||
| if ! git diff --staged --quiet; then | ||
| git commit -m "Cleanup preview for PR #${{ github.event.pull_request.number }}" | ||
| git push --force origin HEAD:refs/heads/gh-pages | ||
| fi |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b5bba78d7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ! git ls-remote --exit-code --heads origin gh-pages > /dev/null 2>&1; then | ||
| echo "gh-pages does not exist; nothing to clean." | ||
| exit 0 |
There was a problem hiding this comment.
Checkout repo before running cleanup git commands
This cleanup job runs git ls-remote --heads origin gh-pages without first checking out the repository, so no origin remote is configured in the runner workspace. In that state the command fails and the script takes the "gh-pages does not exist" early-exit path, which means closed PR previews are never removed. Add an actions/checkout step (or use an explicit repository URL and initialize a repo) before invoking these git operations.
Useful? React with 👍 / 👎.
|
🚀 PR Preview deployed!
Run |
|
🚀 PR Preview deployed!
Run |
|
🚀 PR Preview deployed!
Run |
|
🚀 PR Preview deployed!
Run |
Summary
Why
This prevents PR preview deploys from overwriting the production site and allows both to coexist.
Notes
Set repository Pages source to Deploy from a branch -> gh-pages -> /(root).
Verification