Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/dependabot-update-15294.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"miniflare": patch
"wrangler": patch
---

Update dependencies of "miniflare", "wrangler"

The following dependency versions have been updated:

| Dependency | From | To |
| ------------------------- | ------------- | ------------- |
| @cloudflare/workers-types | ^5.20260820.1 | ^5.20260821.1 |
| workerd | 1.20260820.1 | 1.20260821.1 |
10 changes: 10 additions & 0 deletions .changeset/preview-pull-request-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@cloudflare/deploy-helpers": minor
"wrangler": minor
---

Add pull request metadata to `wrangler preview` deployments

`wrangler preview` now detects the pull request associated with the current CI run (GitHub Actions, GitLab CI, CircleCI, and a generic `PULL_REQUEST_URL`/`PR_URL`/`CHANGE_URL` fallback) and attaches it, along with the repository URL, to the preview deployment as annotations (`workers/pull_request_number`, `workers/pull_request_url`, `workers/repository_url`).

This is best effort: if no pull request can be detected, nothing changes. When a pull request is detected, its URL is now also shown in the `wrangler preview` command output.
12 changes: 12 additions & 0 deletions packages/deploy-helpers/src/preview/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ export interface DeploymentResource {
limits?: CfUserLimits;
placement?: CfPlacement;
cache?: CacheOptions;
annotations?: {
"workers/commit_sha"?: string;
"workers/message"?: string;
"workers/pull_request_number"?: string;
"workers/pull_request_url"?: string;
"workers/repository_url"?: string;
"workers/tag"?: string;
};
env?: EnvBindings;
created_on: string;
}
Expand All @@ -101,7 +109,11 @@ export type CreatePreviewDeploymentRequestParams = {
compatibility_date?: string;
compatibility_flags?: string[];
annotations?: {
"workers/commit_sha"?: string;
"workers/message"?: string;
"workers/pull_request_number"?: string;
"workers/pull_request_url"?: string;
"workers/repository_url"?: string;
"workers/tag"?: string;
};
migrations?: CfWorkerInit["migrations"];
Expand Down
52 changes: 49 additions & 3 deletions packages/deploy-helpers/src/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ import {
assemblePreviewScriptSettings,
extractConfigBindings,
getBranchName,
getCommitSha,
getHeadCommitMessage,
getHeadCommitRef,
getPreviewOwnedContainerClassNames,
getPullRequestMetadata,
getRepositoryUrl,
previewContainerAppName,
resolveWorkerName,
shouldUseCIMetadataFallback,
Expand All @@ -43,6 +46,7 @@ import type {
DeploymentResource,
PreviewResource,
} from "./api";
import type { PullRequestMetadata } from "./shared";
import type { ContainerNormalizedConfig } from "@cloudflare/containers-shared";
import type {
Config,
Expand Down Expand Up @@ -404,6 +408,9 @@ async function assemblePreviewDeploymentSettings(
options: {
message?: string;
tag?: string;
repositoryUrl?: string;
pullRequest?: PullRequestMetadata;
commitSha?: string;
assetsOptions?: PreviewAssetsOptions;
}
): Promise<CreatePreviewDeploymentRequestParams> {
Expand Down Expand Up @@ -440,9 +447,24 @@ async function assemblePreviewDeploymentSettings(
if (config.compatibility_flags && config.compatibility_flags.length > 0) {
request.compatibility_flags = config.compatibility_flags;
}
if (options.message || options.tag) {
const repositoryUrl = options.repositoryUrl;
const pullRequest = options.pullRequest;
const commitSha = options.commitSha;
if (
options.message ||
options.tag ||
repositoryUrl ||
pullRequest ||
commitSha
) {
request.annotations = {
...(commitSha && { "workers/commit_sha": commitSha }),
...(options.message && { "workers/message": options.message }),
...(pullRequest?.number && {
"workers/pull_request_number": pullRequest.number,
}),
...(pullRequest?.url && { "workers/pull_request_url": pullRequest.url }),
...(repositoryUrl && { "workers/repository_url": repositoryUrl }),
...(options.tag && { "workers/tag": options.tag }),
};
}
Expand Down Expand Up @@ -550,16 +572,29 @@ function formatUrlLines(label: string, urls: string[] | undefined): string[] {
function formatPreviewDeploymentSummary(
previewResource: PreviewResource,
deployment: DeploymentResource,
isNew: boolean
isNew: boolean,
pullRequest?: PullRequestMetadata
): string {
const statusLabel = isNew ? chalk.green("(new)") : chalk.dim("(updated)");
const pullRequestUrl =
deployment.annotations?.["workers/pull_request_url"] ?? pullRequest?.url;
const pullRequestNumber =
deployment.annotations?.["workers/pull_request_number"] ??
pullRequest?.number;

return [
`${chalk.bold("Preview:")} ${previewResource.name} ${statusLabel}`,
...formatUrlLines("Preview", previewResource.urls),
"",
`${chalk.bold("Deployment ID:")} ${deployment.id}`,
...formatUrlLines("Deployment", deployment.urls),
...(pullRequestUrl || pullRequestNumber
? [
`${chalk.bold("Pull Request:")} ${
pullRequestUrl ?? `#${pullRequestNumber}`
}`,
]
: []),
].join("\n");
}

Expand Down Expand Up @@ -676,6 +711,9 @@ export async function preview(
!args.message && shouldUseCIMetadataFallback()
? getHeadCommitMessage()
: undefined;
const repositoryUrl = getRepositoryUrl();
const pullRequest = getPullRequestMetadata();
const commitSha = getCommitSha();

let existingPreview: PreviewResource | null = null;
try {
Expand Down Expand Up @@ -740,6 +778,9 @@ export async function preview(
{
message: args.message ?? fallbackMessage,
tag: args.tag ?? fallbackTag,
repositoryUrl,
pullRequest,
commitSha,
assetsOptions,
}
);
Expand Down Expand Up @@ -781,7 +822,12 @@ export async function preview(
);
} else {
logger.log(
formatPreviewDeploymentSummary(previewResource, deployment, isNewPreview)
formatPreviewDeploymentSummary(
previewResource,
deployment,
isNewPreview,
pullRequest
)
);

const topLevelBindings = getBindings(config);
Expand Down
Loading
Loading