Skip to content

Build PR previews without maintainer approval - #1806

Merged
st0012 merged 5 commits into
ruby:masterfrom
st0012:codex/automatic-pr-previews
Sep 1, 2026
Merged

Build PR previews without maintainer approval#1806
st0012 merged 5 commits into
ruby:masterfrom
st0012:codex/automatic-pr-previews

Conversation

@st0012

@st0012 st0012 commented Aug 31, 2026

Copy link
Copy Markdown
Member

Fork previews currently pause each fork update in fork-preview-protection until a maintainer approves the environment deployment. This creates repeated approval requests, delays contributor feedback, and fills the Actions UI with waiting jobs.

This change removes the preview-specific maintainer approval step. Every PR builds RDoc in a read-only workflow that has no secrets. A trusted workflow_run matches the _site artifact to the current PR head and rejects non-static Pages controls.

sequenceDiagram
  actor Author as PR author
  participant PR as Pull request
  participant Build as Build PR Preview<br/>Untrusted, no secrets
  participant Artifact as GitHub artifact store
  participant Deploy as Deploy PR Preview<br/>Trusted
  participant Cloudflare as Cloudflare Pages

  Author->>PR: Open, update, or reopen the PR
  PR->>Build: Start pull_request workflow
  Build->>Build: Checkout PR code at the exact head SHA
  Build->>Build: Setup Ruby
  Build->>Build: Build site into _site
  alt The build produces an artifact
    Build->>Artifact: Upload preview site for one day
  else The build fails before upload
    Note over Build,Artifact: No preview artifact is available
  end

  Build-->>Deploy: workflow_run completed, success or failure
  Deploy->>Deploy: Resolve current pull request and artifact
  Deploy->>PR: Match one open PR to the exact head SHA
  Deploy->>Artifact: Match one artifact from this exact run
  alt The PR, SHA, or artifact is not current and valid
    Deploy--xDeploy: Stop before Cloudflare secrets
  else The candidate is current
    Artifact-->>Deploy: Download preview site
    Deploy->>Deploy: Validate preview site as safe static files
    Deploy->>PR: Confirm pull request head again
    alt The site is invalid or the PR head changed
      Deploy--xDeploy: Stop before deployment
    else The site is safe and the PR is current
      Deploy->>Deploy: Prepare trusted Wrangler directory
      Note over Deploy,Cloudflare: Cloudflare secrets are supplied only for this call
      Deploy->>Cloudflare: Deploy to the PR-number-preview branch
      Cloudflare-->>Deploy: Return an HTTPS pages.dev URL
      Deploy->>PR: Update preview comment after one final head and URL check
      Note over PR: Reuse one marked comment with the preview URL and commit SHA
    end
  end
Loading

Contributors now receive an updated preview after each commit that produces a preview artifact. Per-PR concurrency cancels older work, and one bot comment points to the latest successful preview. Maintainers no longer open individual environment deployments or receive repeated preview approval requests.

The trusted workflow exposes the Cloudflare token only to the deployment step. It does not download the PR repository or run PR code. GitHub's separate public-fork policy can still hold workflows from contributors who are new to GitHub. Existing PRs can retain the old MATZBOT comment once. Later deployments update only the new GitHub Actions comment.

@skatkov

skatkov commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Thanks!

Nice way to preview changes

@st0012
st0012 marked this pull request as ready for review September 1, 2026 10:31
Copilot AI balanced review requested due to automatic review settings September 1, 2026 10:31
@st0012
st0012 merged commit f4e3c3b into ruby:master Sep 1, 2026
28 checks passed
@st0012
st0012 deleted the codex/automatic-pr-previews branch September 1, 2026 10:34

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

Reworks PR previews to build untrusted contributions without maintainer approval, then validate and deploy artifacts through a trusted workflow.

Changes:

  • Builds and uploads preview artifacts for every PR.
  • Validates artifacts before Cloudflare deployment.
  • Removes the former fork-approval workflow and reuses one preview comment.

Reviewed changes

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

File Description
.github/workflows/pr-preview-check.yml Builds the preview artifact without secrets.
.github/workflows/fork-preview-deploy.yml Removes the approval-gated fork workflow.
.github/workflows/cloudflare-preview.yml Resolves, validates, deploys, and comments on previews.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +326 to +328
const previewUrl = (
process.env.PREVIEW_ALIAS_URL || process.env.PREVIEW_DEPLOYMENT_URL || ''
).trim();
Comment on lines +163 to +169
- name: Download preview site
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pr-preview-site
path: ${{ runner.temp }}/pr-preview-site
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
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