Skip to content

Add update_apps_cdn_build_metadata action#701

Open
iangmaia wants to merge 11 commits intotrunkfrom
iangmaia/add-update-apps-cdn-build-metadata-action
Open

Add update_apps_cdn_build_metadata action#701
iangmaia wants to merge 11 commits intotrunkfrom
iangmaia/add-update-apps-cdn-build-metadata-action

Conversation

@iangmaia
Copy link
Contributor

@iangmaia iangmaia commented Mar 2, 2026

Fixes AINFRA-2102

Summary

  • Adds a new update_apps_cdn_build_metadata Fastlane action that updates metadata of existing builds on the Apps CDN without re-uploading files
  • Uses the WP REST API v2 (POST /wp/v2/sites/{site_id}/a8c_cdn_build/{post_id}) with JSON body
  • Accepts an array of post_ids to update multiple builds in one call — the visibility term ID lookup is performed only once and reused across all posts
  • Supports updating visibility (:internal / :external) via taxonomy term ID lookup, and post_status (publish / draft)
  • This enables a two-phase release flow: upload builds as Internal during finalize, then flip to External at publish time

Context

The companion Studio PR uses this action in its publish_release lane to flip CDN build visibility from Internal to External.

The existing upload_build_to_apps_cdn action cannot be used to change visibility because visibility is part of the dedup matching criteria in the CDN plugin — re-uploading with a different visibility creates a new build rather than updating the existing one.

Note: The v1.1 API (/rest/v1.1/sites/{site_id}/posts/{post_id}) returns 500 for a8c_cdn_build custom post types, which is why this action uses the WP v2 endpoint instead.

Test plan

  • Unit tests added and passing (bundle exec rspec spec/update_apps_cdn_build_metadata_spec.rb — 16 examples, 0 failures)
  • bundle exec rubocop — no offenses on changed files
  • Manual test: verified against the real CDN API that both visibility updates and post_status changes work correctly via the v2 endpoint

🤖 Generated with Claude Code

…sting CDN builds

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@iangmaia iangmaia self-assigned this Mar 2, 2026
@iangmaia iangmaia added the enhancement New feature or request label Mar 2, 2026
@iangmaia iangmaia requested a review from Copilot March 2, 2026 20:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Fastlane action to update metadata on an existing Apps CDN build post via the WordPress.com REST API, enabling a two-phase release flow (upload internal → later flip to external without re-upload).

Changes:

  • Introduces update_apps_cdn_build_metadata Fastlane action that POSTs updates to an Apps CDN build post (visibility/status).
  • Adds RSpec coverage for successful updates, validation, and error handling.
  • Documents the new action in the Trunk changelog.

Reviewed changes

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

File Description
spec/update_apps_cdn_build_metadata_spec.rb Adds unit tests for the new action’s request shaping, validation, and error cases.
lib/fastlane/plugin/wpmreleasetoolkit/actions/common/update_apps_cdn_build_metadata.rb Implements the new Fastlane action that updates build metadata via WPCOM REST API.
CHANGELOG.md Adds a Trunk “New Features” entry for the new action.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@iangmaia iangmaia requested review from AliSoftware and mokagio March 3, 2026 18:44
The v1.1 API returns 500 for a8c_cdn_build custom post types.
The WP REST API v2 endpoint works correctly for both reads and writes.

- POST to /wp/v2/sites/{site_id}/a8c_cdn_build/{post_id} with JSON body
- Visibility changes now look up taxonomy term IDs first
- Response uses lowercase 'id' instead of 'ID'

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change post_id (Integer) to post_ids (Array) so callers can update
multiple builds in one call. The visibility term lookup is performed
only once and reused across all posts, avoiding redundant API calls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger


if params[:visibility]
term_id = lookup_visibility_term_id(site_id: params[:site_id], api_token: params[:api_token], visibility: params[:visibility])
body['visibility'] = [term_id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably more of a question for Hannah but it feels surprising to me that the API would technically allow an array if values for this metadata instead of a single one 🤔

Like, what would happen at the API level if we called the API with {"visibility":[1345, 1367]} body (where, say, 1345 is internal and 1367 is external, for example) 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checked using the API. It indeed accepts multiple term IDs and assigns both:

POST /wp/v2/sites/{site_id}/a8c_cdn_build/737
{"visibility": [1316, 21293]}

→ 200 OK
{"id": 737, "visibility": [21293, 1316], ...}

So a post would end up being both "internal" and "external" at the same time 😅 it just treats visibility as a taxonomy that supports multiple terms.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! I wonder why we didn't have to pass an array but just a string in the API call that creates the build in upload_build_to_apps_cdn then 🤔 🤷

Also, this doesn't match the table in the FieldGuide documentation (interal ref: PCYsg-15tP-p2#How-to-upload-a-build-to-a-CDN-blog), so I guess one of the 2 should probably be updated.
I'd vote for only updating the AppsCDN plugin for accepting only one visibility (both in the API call and on the visibility metadata stored for a post taxonomy), but I'm not sure if that's technically feasible/easy (vs if this is an inherent technical limitation of how taxonomies work in WordPress? cc @hannahtinkler).

Anyway, I think ultimately it's not really critical (given the way we use the API and this visibility taxonomy we always set only one value in practice in all our call sites); as long as we're sure that calling update_build_to_apps_cdn with a one-item array [term_id] on a post that already had a different value set for visibility indeed replaces the visibility of that post with a single visibility value of term_id—as opposed to adding it to the existing ones.

Copy link
Contributor

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 small suggestions for also DRY-ing the ConfigItems or at least their verify_block: procs into the Helper, as well as integrating the URI.parse(url) calls into the {rest_v1_1,wp_v2}_url helpers directly.
But LGTM apart from that, so approving to unblock.

Copy link
Contributor

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants