Skip to content

Migrate to Unity Build Automation API v2 with service accounts - #3

Merged
Matuyuhi merged 2 commits into
mainfrom
claude/unity-api-v2-migration-1919xt
Aug 6, 2026
Merged

Matuyuhi merged 2 commits into
mainfrom
claude/unity-api-v2-migration-1919xt

Conversation

@Matuyuhi

@Matuyuhi Matuyuhi commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

This PR updates the action to use Unity Build Automation API v2, replacing the deprecated v1 API. The most significant change is the authentication mechanism: instead of accepting a pre-formed authorization header, the action now takes a service account key ID and secret, constructs the HTTP Basic credential internally, and validates that v1 URLs are not used.

Key Changes

  • Authentication overhaul: Replaced single authorization_header input with two new inputs (unity_service_account_key_id and unity_service_account_secret_key). The action now constructs the base64-encoded HTTP Basic credential internally and masks both the secret key and derived credential in logs.

  • API endpoint migration: Changed default API URL from https://build-api.cloud.unity3d.com/api/v1 to https://build-automation.services.api.unity.com/v2. Added validation to reject v1 URLs with a clear error message.

  • Error handling improvements: Updated error parsing to handle v2's RFC 7807 error format (detail, title, requestId fields instead of v1's error/message). Added special handling for 401/403 errors to guide users toward service account setup. Extracts and includes requestId in error messages for support investigations.

  • Response parsing updates: Added extraction of buildStatus field from API responses and exposed it as a new output. Enhanced handling of 2xx responses that contain per-target errors (e.g., when a build is already running).

  • Documentation: Added comprehensive migration guide explaining the v1→v2 transition, authentication setup, and what changed in the API contract. Updated all examples and input/output tables.

Implementation Details

  • The action base64-encodes keyId:secretKey and strips newlines (to handle GNU coreutils' line wrapping) before constructing the Authorization: Basic header.
  • All credential-related values (secret key, base64 credential, and final header) are masked in logs via ::add-mask::.
  • Validation of required inputs happens before any API request, preventing confusing failures.
  • The response parser is tolerant of both single-element arrays (v1 shape) and bare objects (v2 shape) to handle potential future API changes gracefully.
  • Retry logic only applies to connection failures, not to successful API responses, to avoid double-charging build minutes.

https://claude.ai/code/session_016Mxrx7ufpE3maxhLfSYwPA

claude added 2 commits August 6, 2026 13:02
Unity deprecated Build Automation API v1 and removes it on 2026-12-21, so
default to v2 at https://build-automation.services.api.unity.com/v2.

v2 authenticates with HTTP Basic using a service account key ID and secret
and rejects the legacy Build Automation API key, so add
`unity_service_account_key_id` / `unity_service_account_secret_key` inputs
that are base64-encoded into the Authorization header. `authorization_header`
stays supported for callers that can only supply a pre-built header, but the
two are mutually exclusive: supplying both, or half of the key pair, now
fails before any request is sent rather than silently using stale
credentials.

Adapt response handling to v2:

- 202 Accepted is the success status (the existing `^2` check covers it).
- Errors are RFC 7807, so read `detail`/`title` alongside v1's
  `error`/`message`, and surface the `requestId` Unity support asks for.
- 401/403 responses explain that v2 needs service account credentials with a
  Build Automation role, the most likely migration failure.
- A 2xx carrying a per-target `error` and no build ID (e.g. a build is
  already running) now reports that message instead of the raw body.
- Expose the `buildStatus` field v2 returns as a new `build_status` output.

Pointing `api_url` back at v1 still works and logs a deprecation warning.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Mxrx7ufpE3maxhLfSYwPA
Since this releases under a new version tag, the v1 fallbacks are dead
weight. Remove them so there is exactly one supported configuration:

- Delete the `authorization_header` input. API v2 only accepts service
  account credentials, so the pre-built-header escape hatch could only carry
  a value the caller had to hand-encode anyway. The key ID and secret inputs
  are now plain required inputs, validated alongside the org/project/target
  IDs, which drops the mutually-exclusive/paired-input checks entirely.
- Reject a v1 base URL instead of warning. v1 does not accept service account
  credentials, so pointing `api_url` at it can only produce a confusing 401;
  the error names the older release to pin instead.
- Parse errors as RFC 7807 only (`detail`/`title`), dropping v1's
  `error`/`message`. The 2xx-without-a-build-ID path still reads `error`,
  which v2's GetBuildResponse defines for an already-running target.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Mxrx7ufpE3maxhLfSYwPA
@Matuyuhi
Matuyuhi merged commit 756918e into main Aug 6, 2026
1 check passed
@Matuyuhi
Matuyuhi deleted the claude/unity-api-v2-migration-1919xt branch August 6, 2026 13:16
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.

2 participants