Deploy a Quarto site with a preview for every pull request
Episodic review environments on Firebase Hosting channels without exposing private source code
The problem
Reviewing technical documentation or rendered reports in a pull request diff is notoriously unreliable:
- Markdown diffs hide visual defects. A git diff shows line changes, but it cannot show broken CSS layouts, overflowing tables, mangled cross-references, or misaligned typography.
- Local rendering does not scale across a team. Asking reviewers to clone the branch, install matching tool versions, and run
quarto renderlocally creates friction. Small errors slip into production because nobody rendered the full site. - GitHub Pages limitations. On GitHub Free accounts, GitHub Pages functions exclusively on public repositories. If your source code, drafting notes, or research documents are kept in a private repository, GitHub Pages is unavailable. Even on GitHub Pro plans where private repositories can publish to Pages, the rendered site is published to a single static URL with no native concept of pull request preview channels.
Teams need isolated, temporary preview environments for every pull request that spin up automatically, update on subsequent pushes, and expire when review concludes.
The web-repo way: Firebase Hosting channels
Modern web applications solve this using ephemeral hosting channels. Google Firebase Hosting provides preview channels out-of-the-box, allowing static sites to deploy to an unlisted, temporary URL.
1. Minimal hosting configuration
A standard firebase.json file in the repository root defines the static output directory generated by Quarto (_site):
{
"hosting": {
"public": "_site",
"cleanUrls": true,
"ignore": ["firebase.json", "**/.*"]
}
}Setting cleanUrls: true ensures that Firebase Hosting serves page.html at /page (dropping the .html extension) and redirects .html URLs to the clean form.
2. Ephemeral previews in GitHub Actions
In .github/workflows/quarto.yml, the workflow renders the site and deploys PRs directly to a designated channel named pr-<number>:
- name: Deploy PR preview channel
if: env.DEPLOY_ENABLED == 'true' && github.event_name == 'pull_request'
id: preview
run: |
npx --yes "$FIREBASE_TOOLS" hosting:channel:deploy "pr-${{ github.event.number }}" \
--project "${{ vars.FIREBASE_PROJECT_ID }}" --expires 7d --json > deploy.json
url=$(node -e 'const r=require("./deploy.json").result;console.log(Object.values(r)[0].url)')
echo "url=$url" >> "$GITHUB_OUTPUT"
- name: Comment preview URL
if: steps.preview.outputs.url != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment "${{ github.event.number }}" --edit-last --create-if-none \
--body "📘 Preview: ${{ steps.preview.outputs.url }} (expires in 7 days)"3. Posting and updating the review link
The workflow captures the generated preview URL—which follows the structure https://<project>--pr-<number>-<hash>.web.app—and comments it directly onto the pull request. Using gh pr comment --edit-last --create-if-none ensures that repeated commits to the same pull request update the existing comment rather than generating comment spam.
When the branch is merged into main, the workflow executes a standard live deployment:
- name: Deploy live (dev) site
if: env.DEPLOY_ENABLED == 'true' && github.event_name != 'pull_request'
run: |
npx --yes "$FIREBASE_TOOLS" deploy --only hosting \
--project "${{ vars.FIREBASE_PROJECT_ID }}" --non-interactiveAll credentials are exchanged keylessly via Workload Identity Federation (see keyless CI deploys), meaning no service account keys exist in the repository.
What we observed
Our live dev deployment and preview channels were verified on 2026-09-26:
- Automated commenting: On opening a pull request, the workflow authenticated, provisioned the Firebase Hosting channel
pr-2, and left a single formatted comment with the live preview link. - Graceful degradation: The deployment step evaluates a safety gate (
DEPLOY_ENABLED). If the repository variables for Google Cloud have not yet been configured, the deployment steps skip without breaking the build, allowing Quarto rendering and link checking to proceed unhindered. - Fork security: Fork PRs get a read-only token and no secrets; our workflow additionally skips deploys when
head.repo.full_name != github.repository. - Automatic retirement: Channels deploy with
--expires 7d. Channels expire 7 days after the last deploy to that channel (each push redeploys and resets the timer), preventing orphaned staging sites from accumulating.
The R way: pkgdown sites and Quarto reports
This architecture is not restricted to websites; it fits any static HTML generated by R tooling.
pkgdown documentation
An R package documentation site created with pkgdown::build_site() writes its static assets to the docs/ folder. By pointing firebase.json’s public key to docs, the exact same preview pipeline can deploy previews of your package documentation whenever an author opens a pull request. Reviewers can click through reference manual updates and vignettes before the code is merged.
Quarto clinical and scientific reports
Complex Quarto reports often contain tabsets, interactive HTML widgets, and extensive data tables that cannot be adequately evaluated in code review. Building the report in CI and shipping it to an ephemeral preview channel gives statisticians, clinicians, and quality auditors a fully functional artifact to examine.
Deployment alternatives
Other platforms offer preview capabilities for static R outputs:
- Posit Connect: Excellent for enterprise internal deployment, supporting both Shiny apps and static Quarto reports. Previews typically require publishing to distinct content items or managing access controls within the Connect server.
- Quarto Pub: Simple and built directly into Quarto, but all published content is public.
- Netlify: Provides native deploy previews for static sites by monitoring GitHub pull requests, but introduces an additional third-party vendor if your organisation already standardises on Google Cloud, AWS, or Azure.
Pitfalls we hit
- Channel sprawl without expiry: Forgetting the
--expiresflag leaves old preview channels active indefinitely. Setting--expires 7densures automatic garbage collection. - Silent skips during initial setup: If repository variables (
GCP_WORKLOAD_IDENTITY_PROVIDER,GCP_SERVICE_ACCOUNT,FIREBASE_PROJECT_ID) are absent or misspelled,DEPLOY_ENABLEDevaluates tofalseand the deployment step skips quietly. Check the job log variables if a preview comment fails to appear. - PR comment flooding: Running a naive
gh pr commentwithout--edit-lastleaves a new comment on every push, drowning out conversation. Always use--edit-last --create-if-none. - Public URL discovery: Firebase preview URLs are unlisted, but they are accessible on the public internet. Firebase Hosting has no built-in access control for static content, so keep content generic and free of proprietary data, or use a host with access control (such as Posit Connect).
- 2026-09-26: Removed the end-of-post checklist.