Skip to content

Build/Test Tools: Pin Playground PR preview links to build artifact IDs - #16436

Draft
akirk wants to merge 4 commits into
WordPress:trunkfrom
akirk:fix/playground-artifact-ids
Draft

akirk wants to merge 4 commits into
WordPress:trunkfrom
akirk:fix/playground-artifact-ids

Conversation

@akirk

@akirk akirk commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/66918

I’d like to update the Playground preview links posted on Core pull requests to use exact artifact IDs and PR verification, added in WordPress/wordpress-playground#4826 and WordPress/wordpress-playground#4842.

The existing links resolve the PR through Playground’s plugin proxy, which tries to find the right artifact using the PR’s branch name. This can be ambiguous when contributions from different forks share a branch name. This was also reported at WordPress/wordpress-playground#4614 (comment).

Pinning each link to the specific artifact produced by its build makes the preview’s source explicit and avoids relying on branch-based artifact lookup.

This change:

  • Generates a Blueprint pointing to the exact WordPress build artifact.
  • Updates the existing preview comment after each successful build of the latest commit in the PR, including reruns.
  • Prevents builds of older commits from replacing the current preview link.
  • Identifies the PR through GitHub API metadata instead of downloading a separate PR-number artifact.
  • Includes the build commit and workflow run in the comment and explains the artifact’s 14-day expiry.

Existing core-pr and wordpress.html?pr= links continue to work but will no longer be linked in the GitHub comment. Instead, an artifact-pinned link is used. The link in the comment will be updated after each successful build of the latest commit in the PR, including reruns. A copied URL stays pinned to its original artifact but stops working when the PR gets another commit or the artifact expires. A successful build refreshes the link in the comment.

The legacy pr-number upload is retained because the existing default-branch commenter still consumes it while this PR is under review. The new commenter does not download it.

The commenting workflow reads artifact metadata from the exact completed run and checks the PR’s head repository, branch, and SHA before writing. It does not download or execute PR build output. Comment writers for the same source branch are serialized, and comment lookup is paginated so existing preview comments are updated rather than duplicated.

This follows up on https://core.trac.wordpress.org/ticket/59416. A similar change is proposed for Gutenberg in WordPress/gutenberg#87828.

Each exact-artifact URL includes the required pr parameter so the proxy independently verifies the source repository, branch, and latest commit.

Sample plugin-proxy URL

Using this PR's latest successful build:

https://playground.wordpress.net/plugin-proxy.php?org=WordPress&repo=wordpress-develop&artifact-id=15706869473&pr=16436

The sample is pinned to this build and becomes stale after another commit is pushed or the artifact expires.

Testing

PR discovery lists open pull requests for the build’s source owner and branch, then validates the head repository ID and SHA. Commit-to-PR association can be empty for fork commits and is not used.

Regression verification: replayed actual GitHub API responses for Core PR #16416 (run 47035587669). The original lookup skipped the PR; the fixed lookup finds it and generates the exact-artifact preview. Comment writes were captured locally, not posted.

Passed locally after rebasing onto current trunk:

  • Actionlint on both changed workflows.
  • Fixture checks executing the actual comment-writing script with mocked GitHub responses: exact-run artifact selection; initial comment creation; updating existing comments, including ones beyond the first page; reruns with new artifact IDs; stale, foreign-fork, and closed PR rejection; missing/expired artifacts; and preserving human comments.
  • Validation of the generated Blueprint against Playground’s schema.
  • git diff --check.

Offline Zizmor 1.31.1 reports only findings also present on the unchanged base workflows: the existing privileged triggers and a self-repository reference. There are no new findings.

Manual testing, once the workflow is applied to the default branch and the proxy endpoint is deployed:

  1. Open a Core PR and wait for “Test Build Processes” to succeed. Confirm the Playground comment’s link opens the built WordPress instance, logs in, and lands in wp-admin.
  2. Decode the Blueprint in the link’s URL fragment. Confirm preferredVersions.wp uses artifact-id and that the ID belongs to that completed run’s wordpress-build-<PR number> artifact.
  3. Push another commit and wait for a successful build. Confirm the existing comment is updated with a new link rather than duplicated.
  4. Rerun the latest commit’s build and confirm the comment uses the new upload’s ID. A previously copied link should retain its original ID.
  5. Rerun an older commit’s build and confirm it cannot replace the latest commit’s preview link.
  6. Repeat with a fork PR. Failed builds or unavailable artifacts should leave the existing comment untouched.

Live end-to-end testing is pending. This change only affects GitHub Actions tooling, so the WordPress runtime test suites were not run.

Use of AI Tools

OpenAI Codex assisted with the implementation, fixture checks, local validation, and PR drafting.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@akirk akirk changed the title Pin Playground PR preview links to build artifact IDs Build/Test Tools: Pin Playground PR preview links to build artifact IDs Dec 3, 2026
akirk added a commit to WordPress/wordpress-playground that referenced this pull request Dec 3, 2026
## Motivation for the change, related issues

Follow-up to #4826: require both `artifact-id` and `pr` so every
exact-artifact request is verified against the PR's latest commit.

```text
/plugin-proxy.php?org=WordPress&repo=wordpress-develop&artifact-id=15685328433&pr=16416
```

Related consumers: WordPress/wordpress-develop#16436,
WordPress/gutenberg#87828, and Automattic/woocommerce-payments#12539.

## Implementation details

Fetch the exact artifact, its workflow run, and the specified PR
directly from GitHub. Require a `pull_request` run whose source
repository ID, branch, and SHA match the PR's head. Missing or malformed
`pr`, missing source metadata, mismatches, and failed API requests fail
closed. `verify_only` enforces the same checks. There is no artifact
discovery or fallback.

This works for fork runs with an empty `pull_requests` array and avoids
unreliable commit-to-PR association. Push and `pull_request_target` runs
are rejected.

**Compatibility:** exact-ID URLs without `pr` now return HTTP 400.
Existing PR/branch discovery routes are unchanged. An artifact-pinned
link becomes stale as soon as the PR receives another commit, even
before a replacement build completes. Consumer workflows should refresh
the comment link after a successful build. Matching a PR's head does not
establish that its code is trusted.

The README documents the required parameter and stale-link behavior. No
quick-start handbook changes are included.

## Testing Instructions (or ideally a Blueprint)

- All 25 proxy tests pass, covering matching fork metadata, mismatches,
missing metadata, disallowed run events, failed API requests, and
missing/malformed PR numbers. Confirmed the missing-PR regression fails
against the optional implementation.
- PHP syntax checks, focused ESLint, repository formatting, and `git
diff --check` pass. Actual GitHub metadata from Core PR #16416 was
accepted; changing its PR head was rejected without downloading an
archive.
- With a local proxy and a valid artifact/PR pair, verify the URL works
both normally and with `verify_only`. Remove `pr` or substitute a PR
with a mismatched repository, branch, or SHA; expect HTTP 400.

AI assistance: OpenAI Codex assisted with implementation, regression
coverage, validation, and this description.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Exact GitHub Actions artifact downloads now require a pull request
number and are accepted only when the workflow run and its source
repository, branch, and commit match the pull request’s current head.
* The same validation applies in verification-only mode. Downloads and
verification fail when the PR number or required metadata is missing or
does not match. Update artifact links after successful builds, as they
stop matching when the pull request head changes.
* **Documentation**
* Added guidance on pull request artifact validation and its
limitations.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

1 participant