@cloudflare/deploy-helpers 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,8 +44,25 @@ function convertConfigToBindings(config, options) {
44
44
  if (pages) {
45
45
  break;
46
46
  }
47
- for (const { name, ...x } of info) {
48
- output[name] = { type: "send_email", ...x };
47
+ for (const {
48
+ name,
49
+ destination_address,
50
+ allowed_destination_addresses,
51
+ allowed_sender_addresses,
52
+ remote
53
+ } of info) {
54
+ const shared = {
55
+ type: "send_email",
56
+ allowed_sender_addresses,
57
+ remote
58
+ };
59
+ if (destination_address !== void 0) {
60
+ output[name] = { ...shared, destination_address };
61
+ } else if (allowed_destination_addresses !== void 0) {
62
+ output[name] = { ...shared, allowed_destination_addresses };
63
+ } else {
64
+ output[name] = shared;
65
+ }
49
66
  }
50
67
  break;
51
68
  }
@@ -554,16 +571,24 @@ function createWorkerUploadForm(worker, bindings, options) {
554
571
  }
555
572
  });
556
573
  send_email.forEach((emailBinding) => {
557
- const destination_address = "destination_address" in emailBinding ? emailBinding.destination_address : void 0;
558
- const allowed_destination_addresses = "allowed_destination_addresses" in emailBinding ? emailBinding.allowed_destination_addresses : void 0;
559
- const allowed_sender_addresses = "allowed_sender_addresses" in emailBinding ? emailBinding.allowed_sender_addresses : void 0;
560
- metadataBindings.push({
574
+ const shared = {
561
575
  name: emailBinding.name,
562
576
  type: "send_email",
563
- destination_address,
564
- allowed_destination_addresses,
565
- allowed_sender_addresses
566
- });
577
+ allowed_sender_addresses: emailBinding.allowed_sender_addresses
578
+ };
579
+ if (emailBinding.destination_address !== void 0) {
580
+ metadataBindings.push({
581
+ ...shared,
582
+ destination_address: emailBinding.destination_address
583
+ });
584
+ } else if (emailBinding.allowed_destination_addresses !== void 0) {
585
+ metadataBindings.push({
586
+ ...shared,
587
+ allowed_destination_addresses: emailBinding.allowed_destination_addresses
588
+ });
589
+ } else {
590
+ metadataBindings.push(shared);
591
+ }
567
592
  });
568
593
  durable_objects.forEach(({ name, class_name, script_name, environment }) => {
569
594
  metadataBindings.push({
@@ -1,2 +1,2 @@
1
- export { createWorkerUploadForm, fromMimeType, moduleTypeMimeType } from './chunk-LRKPOFWK.mjs';
1
+ export { createWorkerUploadForm, fromMimeType, moduleTypeMimeType } from './chunk-ZV7SJ2MZ.mjs';
2
2
  import './chunk-Q72B4Q5Z.mjs';
package/dist/index.d.mts CHANGED
@@ -934,6 +934,15 @@ interface DeploymentResource {
934
934
  limits?: CfUserLimits;
935
935
  placement?: CfPlacement;
936
936
  cache?: CacheOptions;
937
+ annotations?: {
938
+ "workers/commit_sha"?: string;
939
+ "workers/message"?: string;
940
+ "workers/pull_request_number"?: string;
941
+ "workers/pull_request_title"?: string;
942
+ "workers/pull_request_url"?: string;
943
+ "workers/repository_url"?: string;
944
+ "workers/tag"?: string;
945
+ };
937
946
  env?: EnvBindings;
938
947
  created_on: string;
939
948
  }
@@ -955,7 +964,12 @@ type CreatePreviewDeploymentRequestParams = {
955
964
  compatibility_date?: string;
956
965
  compatibility_flags?: string[];
957
966
  annotations?: {
967
+ "workers/commit_sha"?: string;
958
968
  "workers/message"?: string;
969
+ "workers/pull_request_number"?: string;
970
+ "workers/pull_request_title"?: string;
971
+ "workers/pull_request_url"?: string;
972
+ "workers/repository_url"?: string;
959
973
  "workers/tag"?: string;
960
974
  };
961
975
  migrations?: CfWorkerInit["migrations"];
@@ -1028,6 +1042,43 @@ declare function getBranchName(): string | undefined;
1028
1042
  declare function shouldUseCIMetadataFallback(): boolean;
1029
1043
  declare function getHeadCommitRef(): string | undefined;
1030
1044
  declare function getHeadCommitMessage(): string | undefined;
1045
+ /**
1046
+ * Detects the current commit's full SHA from well-known CI provider
1047
+ * environment variables (GitHub Actions, GitLab CI, CircleCI), falling back
1048
+ * to a generic `COMMIT_SHA` env var for providers without dedicated support.
1049
+ */
1050
+ declare function getCommitSha(): string | undefined;
1051
+ /**
1052
+ * Detects the current repository's URL from well-known CI provider
1053
+ * environment variables (GitLab CI, CircleCI, Buildkite, Bitbucket, GitHub
1054
+ * Actions, and a generic `REPOSITORY_URL` fallback), or from the local git
1055
+ * remote when running in CI and no env var matched.
1056
+ *
1057
+ * The local git remote fallback is intentionally gated behind
1058
+ * {@link shouldUseCIMetadataFallback}: unlike the env var checks, it shells
1059
+ * out to read the developer's `git config`, so it's only attempted in CI to
1060
+ * avoid uploading a local machine's repository details on every
1061
+ * `wrangler preview` run outside CI.
1062
+ */
1063
+ declare function getRepositoryUrl(): string | undefined;
1064
+ /**
1065
+ * The pull/merge request number, URL, and title detected from the current CI
1066
+ * environment. Any field may be missing depending on what the detected CI
1067
+ * provider exposes.
1068
+ */
1069
+ type PullRequestMetadata = {
1070
+ number?: string;
1071
+ url?: string;
1072
+ title?: string;
1073
+ };
1074
+ /**
1075
+ * Detects the pull/merge request associated with the current CI run, trying
1076
+ * each supported source in order: direct/generic env vars, GitHub Actions,
1077
+ * then GitLab CI. This is best effort — if none of the sources match (e.g.
1078
+ * an unsupported CI provider, or running locally), the deployment proceeds
1079
+ * without pull request metadata.
1080
+ */
1081
+ declare function getPullRequestMetadata(): PullRequestMetadata | undefined;
1031
1082
  declare function resolveWorkerName(args: {
1032
1083
  workerName?: string;
1033
1084
  "worker-name"?: string;
@@ -1105,6 +1156,7 @@ type PreviewCallbacks = Pick<DeployCallbacks, "getNormalizedContainerOptions"> &
1105
1156
  }) => Promise<void>) | undefined;
1106
1157
  verifyContainersScope?: (scopedConfig: Config) => Promise<void>;
1107
1158
  };
1159
+ declare const NO_ACTIVE_PREVIEW_URLS_MESSAGE = "Note: This Preview deployment has no active URLs. To get one, enable Preview Deployments on workers.dev or a custom domain. See https://developers.cloudflare.com/workers/previews/custom-domains/ for more information";
1108
1160
  /**
1109
1161
  * Full preview create/update + deployment orchestration.
1110
1162
  * The wrangler handler calls this after auth + build.
@@ -1189,4 +1241,4 @@ type DrawConnectedChildBoxOptions = {
1189
1241
  */
1190
1242
  declare function drawConnectedChildBox(contentLines: string[], options?: DrawConnectedChildBoxOptions): string;
1191
1243
 
1192
- export { ACTOR_BINDING_DEPENDS_ON_EXPORT_CODE, type ApiDeployment, type ApiVersion, type AssetManifest, type AssetUploadStats, type AssetsUploadResult, type Binding, type BulkInputNullableResult, type BulkInputResult, type Consumer, type ConsumerSettings, type CreatePreviewDeploymentRequestParams, type CreatePreviewRequestParams, type CustomDomain, type CustomDomainChangeset, type DeployCallbacks, DeployProps, type DeploymentResource, EXPORTS_RECONCILIATION_ERROR_CODE, type EnvBindings, INCONSISTENT_EXPORTS_ACROSS_VERSIONS_CODE, INVALID_INHERIT_BINDING_CODE, type JsonLike, NoInputError, type NonVersionedScriptSettings, type PackageDependency, type Percentage, type PostQueueBody, type PostQueueResponse, type PostTypedConsumerBody, type PreviewArgs, type PreviewAssetsOptions, type PreviewBaseConfig, type PreviewBaseConfigPatch, type PreviewCallbacks, type PreviewDefaults, type PreviewDefaultsPatch, type PreviewDeleteArgs, type PreviewRequestOptions, type PreviewResource, type PreviewResult, type PreviewSettingsArgs, type PreviewSettingsUpdateArgs, type Producer, type PurgeQueueBody, type PurgeQueueResponse, type QueueResponse, type QueueSettings, type RetrieveSourceMapFunction, type RouteObject, type ScriptReference, type Settings, SharedDeployVersionsProps, TriggerDeployment, TriggerProps, type TypedConsumerResponse, type UpdatePreviewRequestParams, type VersionCache, type VersionId, type VersionsUploadCallbacks, VersionsUploadProps, WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE, WORKER_NOT_FOUND_ERR_CODE, WORKFLOW_CRON_REQUIRES_PAID_PLAN_CODE, WORKFLOW_NOT_FOUND_CODE, WorkerBuildResult, type Workflow, type WorkflowConflict, type Zone, type ZoneIdCache, addRequiredSecretsInheritBindings, addWorkersSitesBindings, applyServiceAndEnvironmentTags, assemblePreviewDefaults, assemblePreviewScriptSettings, buildAssetManifest, checkRemoteSecretsOverride, checkWorkflowConflicts, collectPackageDependencies, confirmLatestDeploymentOverwrite, convertConfigToBindings, createDeployment, createPreview, createPreviewDeployment, createPreviewParentWorker, createTruncatedAlias, decodeJwtPayload, deletePreview, deletePullConsumer, deleteWorkerConsumer, deploy, deployWfpUserWorker, diagnoseScriptSizeError, diagnoseStartupError, diffJsonObjects, downloadWorkerConfig, drawBox, drawConnectedChildBox, editPreview, editWorkerPreviewDefaults, ensureQueuesExistByConfig, extractBindingsOfType, extractConfigBindings, fetchDeployableVersions, fetchDeploymentVersions, fetchLatestDeployment, fetchLatestDeployments, fetchSecrets, fetchVersion, fetchVersions, fetchWorkerConfig, formatAlignedRows, formatBindings, formatPreviewsSettings, generatePreviewAlias, getBindingValue, getBindings, getBranchName, getConfigPatch, getDeployConfirmFunction, getEdgeKvUploadConcurrency, getHeadCommitMessage, getHeadCommitRef, getMigrationsToUpload, getPreview, getPreviewBaseConfig, getPreviewDeployment, getPreviewOwnedContainerClassNames, getQueue, getRemoteConfigDiff, getSettings, getSourceMappedStack, getSourceMappedString, getSubdomainValues, getSubdomainValuesAPIMock, getWorkerPreviewDefaults, getWorkersDevSubdomain, getZoneForRoute, getZoneIdFromHost, handleMissingSecretsError, handleUnsafeCapnp, hasDefinedEnvironments, hashFile, helpIfErrorIsSizeOrScriptStartup, isExportsReconciliationErrorDetails, isJwtExpired, isModifiedDiffValue, isNonDestructive, isUnsafeBindingType, isWorkerNotFoundError, listConsumers, listQueues, maybeRetrieveFileSourceMap, mergeDeep, padToVisibleWidth, parseBulkInputToObject, parseConfigPlacement, patchNonVersionedScriptSettings, patchPreviewBaseConfig, patchPreviewDeployment, postConsumer, preview, previewContainerAppName, previewDelete, previewSettingsGet, previewSettingsUpdate, printBindings, printBundleSize, printVersions, provisionBindings, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderBindingDependsOnExportError, renderExportsReconciliationError, renderExportsReconciliationSuccess, renderInconsistentExportsAcrossVersionsError, renderRoute, resolveAssetOptions, resolveDoLifecyclePayload, resolveExportsUploadPayload, resolveWorkerName, sanitizeBranchName, shouldUseCIMetadataFallback, stripAnsi, syncAssets, tagsAreEqual, triggersDeploy, updateQueueConsumers, validateEventTriggerTargets, validateFileSecrets, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, visibleLength, warnOnErrorUpdatingServiceAndEnvironmentTags, warnOrError, workerNotFoundErrorMessage };
1244
+ export { ACTOR_BINDING_DEPENDS_ON_EXPORT_CODE, type ApiDeployment, type ApiVersion, type AssetManifest, type AssetUploadStats, type AssetsUploadResult, type Binding, type BulkInputNullableResult, type BulkInputResult, type Consumer, type ConsumerSettings, type CreatePreviewDeploymentRequestParams, type CreatePreviewRequestParams, type CustomDomain, type CustomDomainChangeset, type DeployCallbacks, DeployProps, type DeploymentResource, EXPORTS_RECONCILIATION_ERROR_CODE, type EnvBindings, INCONSISTENT_EXPORTS_ACROSS_VERSIONS_CODE, INVALID_INHERIT_BINDING_CODE, type JsonLike, NO_ACTIVE_PREVIEW_URLS_MESSAGE, NoInputError, type NonVersionedScriptSettings, type PackageDependency, type Percentage, type PostQueueBody, type PostQueueResponse, type PostTypedConsumerBody, type PreviewArgs, type PreviewAssetsOptions, type PreviewBaseConfig, type PreviewBaseConfigPatch, type PreviewCallbacks, type PreviewDefaults, type PreviewDefaultsPatch, type PreviewDeleteArgs, type PreviewRequestOptions, type PreviewResource, type PreviewResult, type PreviewSettingsArgs, type PreviewSettingsUpdateArgs, type Producer, type PullRequestMetadata, type PurgeQueueBody, type PurgeQueueResponse, type QueueResponse, type QueueSettings, type RetrieveSourceMapFunction, type RouteObject, type ScriptReference, type Settings, SharedDeployVersionsProps, TriggerDeployment, TriggerProps, type TypedConsumerResponse, type UpdatePreviewRequestParams, type VersionCache, type VersionId, type VersionsUploadCallbacks, VersionsUploadProps, WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE, WORKER_NOT_FOUND_ERR_CODE, WORKFLOW_CRON_REQUIRES_PAID_PLAN_CODE, WORKFLOW_NOT_FOUND_CODE, WorkerBuildResult, type Workflow, type WorkflowConflict, type Zone, type ZoneIdCache, addRequiredSecretsInheritBindings, addWorkersSitesBindings, applyServiceAndEnvironmentTags, assemblePreviewDefaults, assemblePreviewScriptSettings, buildAssetManifest, checkRemoteSecretsOverride, checkWorkflowConflicts, collectPackageDependencies, confirmLatestDeploymentOverwrite, convertConfigToBindings, createDeployment, createPreview, createPreviewDeployment, createPreviewParentWorker, createTruncatedAlias, decodeJwtPayload, deletePreview, deletePullConsumer, deleteWorkerConsumer, deploy, deployWfpUserWorker, diagnoseScriptSizeError, diagnoseStartupError, diffJsonObjects, downloadWorkerConfig, drawBox, drawConnectedChildBox, editPreview, editWorkerPreviewDefaults, ensureQueuesExistByConfig, extractBindingsOfType, extractConfigBindings, fetchDeployableVersions, fetchDeploymentVersions, fetchLatestDeployment, fetchLatestDeployments, fetchSecrets, fetchVersion, fetchVersions, fetchWorkerConfig, formatAlignedRows, formatBindings, formatPreviewsSettings, generatePreviewAlias, getBindingValue, getBindings, getBranchName, getCommitSha, getConfigPatch, getDeployConfirmFunction, getEdgeKvUploadConcurrency, getHeadCommitMessage, getHeadCommitRef, getMigrationsToUpload, getPreview, getPreviewBaseConfig, getPreviewDeployment, getPreviewOwnedContainerClassNames, getPullRequestMetadata, getQueue, getRemoteConfigDiff, getRepositoryUrl, getSettings, getSourceMappedStack, getSourceMappedString, getSubdomainValues, getSubdomainValuesAPIMock, getWorkerPreviewDefaults, getWorkersDevSubdomain, getZoneForRoute, getZoneIdFromHost, handleMissingSecretsError, handleUnsafeCapnp, hasDefinedEnvironments, hashFile, helpIfErrorIsSizeOrScriptStartup, isExportsReconciliationErrorDetails, isJwtExpired, isModifiedDiffValue, isNonDestructive, isUnsafeBindingType, isWorkerNotFoundError, listConsumers, listQueues, maybeRetrieveFileSourceMap, mergeDeep, padToVisibleWidth, parseBulkInputToObject, parseConfigPlacement, patchNonVersionedScriptSettings, patchPreviewBaseConfig, patchPreviewDeployment, postConsumer, preview, previewContainerAppName, previewDelete, previewSettingsGet, previewSettingsUpdate, printBindings, printBundleSize, printVersions, provisionBindings, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderBindingDependsOnExportError, renderExportsReconciliationError, renderExportsReconciliationSuccess, renderInconsistentExportsAcrossVersionsError, renderRoute, resolveAssetOptions, resolveDoLifecyclePayload, resolveExportsUploadPayload, resolveWorkerName, sanitizeBranchName, shouldUseCIMetadataFallback, stripAnsi, syncAssets, tagsAreEqual, triggersDeploy, updateQueueConsumers, validateEventTriggerTargets, validateFileSecrets, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, visibleLength, warnOnErrorUpdatingServiceAndEnvironmentTags, warnOrError, workerNotFoundErrorMessage };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { fetchResult, fetchPagedListResult, logger, confirm, fetchListResult, prompt, select } from './chunk-Z4LB73IF.mjs';
2
2
  export { initDeployHelpersContext } from './chunk-Z4LB73IF.mjs';
3
- import { extractBindingsOfType, isUnsafeBindingType, getBindings, createWorkerUploadForm, moduleTypeMimeType } from './chunk-LRKPOFWK.mjs';
4
- export { convertConfigToBindings, createWorkerUploadForm, extractBindingsOfType, fromMimeType, getBindings, handleUnsafeCapnp, isUnsafeBindingType, moduleTypeMimeType } from './chunk-LRKPOFWK.mjs';
3
+ import { extractBindingsOfType, isUnsafeBindingType, getBindings, createWorkerUploadForm, moduleTypeMimeType } from './chunk-ZV7SJ2MZ.mjs';
4
+ export { convertConfigToBindings, createWorkerUploadForm, extractBindingsOfType, fromMimeType, getBindings, handleUnsafeCapnp, isUnsafeBindingType, moduleTypeMimeType } from './chunk-ZV7SJ2MZ.mjs';
5
5
  import { __commonJS, __name, __require, __toESM, __export } from './chunk-Q72B4Q5Z.mjs';
6
6
  import assert4 from 'node:assert';
7
7
  import { readFileSync, mkdirSync, writeFileSync, createReadStream } from 'node:fs';
@@ -4414,6 +4414,14 @@ ${dashLink}`, {
4414
4414
  }
4415
4415
  );
4416
4416
  }
4417
+ if (workflow.default_retention) {
4418
+ throw new UserError(
4419
+ `Workflow "${workflow.name}" has "default_retention" configured but references external script "${workflow.script_name}". Configure default_retention on the worker that defines the workflow.`,
4420
+ {
4421
+ telemetryMessage: "triggers deploy workflow default_retention external script"
4422
+ }
4423
+ );
4424
+ }
4417
4425
  continue;
4418
4426
  }
4419
4427
  workflowDeployments.push({
@@ -4429,6 +4437,9 @@ ${dashLink}`, {
4429
4437
  ...workflow.limits && { limits: workflow.limits },
4430
4438
  ...workflow.schedules && {
4431
4439
  schedules: (Array.isArray(workflow.schedules) ? workflow.schedules : [workflow.schedules]).map((cron) => ({ cron }))
4440
+ },
4441
+ ...workflow.default_retention && {
4442
+ default_retention: workflow.default_retention
4432
4443
  }
4433
4444
  }),
4434
4445
  headers: {
@@ -26748,6 +26759,141 @@ function getHeadCommitMessage() {
26748
26759
  }
26749
26760
  }
26750
26761
  __name(getHeadCommitMessage, "getHeadCommitMessage");
26762
+ function getCommitSha() {
26763
+ return process.env.GITHUB_SHA || process.env.CI_COMMIT_SHA || process.env.CIRCLE_SHA1 || process.env.COMMIT_SHA || void 0;
26764
+ }
26765
+ __name(getCommitSha, "getCommitSha");
26766
+ function normalizeRepositoryUrl(repositoryUrl) {
26767
+ const trimmed = repositoryUrl.trim();
26768
+ if (!trimmed) {
26769
+ return void 0;
26770
+ }
26771
+ const scpLikeSshMatch = trimmed.match(/^git@([^:]+):(.+)$/);
26772
+ if (scpLikeSshMatch) {
26773
+ const [, host, pathname] = scpLikeSshMatch;
26774
+ return `https://${host}/${pathname.replace(/\.git$/, "")}`;
26775
+ }
26776
+ try {
26777
+ const url3 = new URL(trimmed);
26778
+ if (url3.protocol === "ssh:" && url3.username === "git") {
26779
+ return `https://${url3.host}${url3.pathname.replace(/\.git$/, "")}`;
26780
+ }
26781
+ if (url3.protocol !== "https:" && url3.protocol !== "http:") {
26782
+ return void 0;
26783
+ }
26784
+ url3.username = "";
26785
+ url3.password = "";
26786
+ url3.search = "";
26787
+ url3.hash = "";
26788
+ url3.pathname = url3.pathname.replace(/\.git$/, "");
26789
+ return url3.toString().replace(/\/$/, "");
26790
+ } catch {
26791
+ return void 0;
26792
+ }
26793
+ }
26794
+ __name(normalizeRepositoryUrl, "normalizeRepositoryUrl");
26795
+ function getRepositoryUrl() {
26796
+ const repositoryUrl = process.env.CI_PROJECT_URL || process.env.CI_REPOSITORY_URL || process.env.CIRCLE_REPOSITORY_URL || process.env.BUILDKITE_REPO || process.env.BITBUCKET_GIT_HTTP_ORIGIN || process.env.BITBUCKET_GIT_SSH_ORIGIN || process.env.REPOSITORY_URL;
26797
+ if (repositoryUrl) {
26798
+ return normalizeRepositoryUrl(repositoryUrl);
26799
+ }
26800
+ if (process.env.GITHUB_REPOSITORY) {
26801
+ const githubServerUrl = process.env.GITHUB_SERVER_URL || "https://github.com";
26802
+ return normalizeRepositoryUrl(
26803
+ `${githubServerUrl.replace(/\/$/, "")}/${process.env.GITHUB_REPOSITORY}`
26804
+ );
26805
+ }
26806
+ if (!shouldUseCIMetadataFallback()) {
26807
+ return void 0;
26808
+ }
26809
+ try {
26810
+ execSync(`git rev-parse --is-inside-work-tree`, { stdio: "ignore" });
26811
+ return normalizeRepositoryUrl(
26812
+ execSync(`git config --get remote.origin.url`).toString()
26813
+ );
26814
+ } catch {
26815
+ return void 0;
26816
+ }
26817
+ }
26818
+ __name(getRepositoryUrl, "getRepositoryUrl");
26819
+ function normalizePullRequestNumber(number4) {
26820
+ if (number4 === void 0) {
26821
+ return void 0;
26822
+ }
26823
+ const normalizedNumber = String(number4).trim();
26824
+ return normalizedNumber ? normalizedNumber : void 0;
26825
+ }
26826
+ __name(normalizePullRequestNumber, "normalizePullRequestNumber");
26827
+ function normalizePullRequestTitle(title) {
26828
+ if (title === void 0) {
26829
+ return void 0;
26830
+ }
26831
+ const trimmedTitle = title.trim();
26832
+ return trimmedTitle || void 0;
26833
+ }
26834
+ __name(normalizePullRequestTitle, "normalizePullRequestTitle");
26835
+ function getGitHubPullRequestMetadata() {
26836
+ if (process.env.GITHUB_EVENT_PATH) {
26837
+ try {
26838
+ const event = JSON.parse(
26839
+ readFileSync(process.env.GITHUB_EVENT_PATH, "utf8")
26840
+ );
26841
+ const number5 = normalizePullRequestNumber(event.pull_request?.number);
26842
+ const url3 = event.pull_request?.html_url ? normalizeRepositoryUrl(event.pull_request.html_url) : void 0;
26843
+ const title = normalizePullRequestTitle(event.pull_request?.title);
26844
+ if (number5 || url3 || title) {
26845
+ return { number: number5, url: url3, title };
26846
+ }
26847
+ } catch {
26848
+ }
26849
+ }
26850
+ const refPullRequestNumber = process.env.GITHUB_REF?.match(/^refs\/pull\/(\d+)\//)?.[1];
26851
+ const number4 = normalizePullRequestNumber(refPullRequestNumber);
26852
+ if (!number4 || !process.env.GITHUB_REPOSITORY) {
26853
+ return void 0;
26854
+ }
26855
+ const githubServerUrl = process.env.GITHUB_SERVER_URL || "https://github.com";
26856
+ return {
26857
+ number: number4,
26858
+ url: normalizeRepositoryUrl(
26859
+ `${githubServerUrl.replace(/\/$/, "")}/${process.env.GITHUB_REPOSITORY}/pull/${number4}`
26860
+ )
26861
+ };
26862
+ }
26863
+ __name(getGitHubPullRequestMetadata, "getGitHubPullRequestMetadata");
26864
+ function getGitLabPullRequestMetadata() {
26865
+ const number4 = normalizePullRequestNumber(process.env.CI_MERGE_REQUEST_IID);
26866
+ const projectUrl = process.env.CI_MERGE_REQUEST_PROJECT_URL || process.env.CI_PROJECT_URL;
26867
+ if (!number4 || !projectUrl) {
26868
+ return void 0;
26869
+ }
26870
+ const normalizedProjectUrl = projectUrl.replace(/\.git$/, "").replace(/\/$/, "");
26871
+ return {
26872
+ number: number4,
26873
+ url: normalizeRepositoryUrl(
26874
+ `${normalizedProjectUrl}/-/merge_requests/${number4}`
26875
+ ),
26876
+ title: normalizePullRequestTitle(process.env.CI_MERGE_REQUEST_TITLE)
26877
+ };
26878
+ }
26879
+ __name(getGitLabPullRequestMetadata, "getGitLabPullRequestMetadata");
26880
+ function getDirectPullRequestMetadata() {
26881
+ const directUrl = process.env.PULL_REQUEST_URL || process.env.PR_URL || process.env.CHANGE_URL || process.env.CIRCLE_PULL_REQUEST;
26882
+ const number4 = normalizePullRequestNumber(
26883
+ process.env.PULL_REQUEST_NUMBER || process.env.PR_NUMBER || process.env.CHANGE_ID
26884
+ );
26885
+ const url3 = directUrl ? normalizeRepositoryUrl(directUrl) : void 0;
26886
+ const title = normalizePullRequestTitle(process.env.PULL_REQUEST_TITLE);
26887
+ if (number4 || url3 || title) {
26888
+ return { number: number4, url: url3, title };
26889
+ }
26890
+ return void 0;
26891
+ }
26892
+ __name(getDirectPullRequestMetadata, "getDirectPullRequestMetadata");
26893
+ function getPullRequestMetadata() {
26894
+ return getDirectPullRequestMetadata() ?? getGitHubPullRequestMetadata() ?? getGitLabPullRequestMetadata();
26895
+ }
26896
+ __name(getPullRequestMetadata, "getPullRequestMetadata");
26751
26897
  function resolveWorkerName(args, config2) {
26752
26898
  const workerName = args.workerName ?? args["worker-name"] ?? config2.name;
26753
26899
  if (!workerName) {
@@ -27151,6 +27297,7 @@ async function prepareContainersForPreview(config2, workerName, previewSlug, cal
27151
27297
  return { scopedContainerConfig, normalisedContainerConfig };
27152
27298
  }
27153
27299
  __name(prepareContainersForPreview, "prepareContainersForPreview");
27300
+ var NO_ACTIVE_PREVIEW_URLS_MESSAGE = "Note: This Preview deployment has no active URLs. To get one, enable Preview Deployments on workers.dev or a custom domain. See https://developers.cloudflare.com/workers/previews/custom-domains/ for more information";
27154
27301
  function toBase64(content) {
27155
27302
  return Buffer.from(content).toString("base64");
27156
27303
  }
@@ -27265,9 +27412,21 @@ async function assemblePreviewDeploymentSettings(config2, buildResult, accountId
27265
27412
  if (config2.compatibility_flags && config2.compatibility_flags.length > 0) {
27266
27413
  request2.compatibility_flags = config2.compatibility_flags;
27267
27414
  }
27268
- if (options.message || options.tag) {
27415
+ const repositoryUrl = options.repositoryUrl;
27416
+ const pullRequest = options.pullRequest;
27417
+ const commitSha = options.commitSha;
27418
+ if (options.message || options.tag || repositoryUrl || pullRequest || commitSha) {
27269
27419
  request2.annotations = {
27420
+ ...commitSha && { "workers/commit_sha": commitSha },
27270
27421
  ...options.message && { "workers/message": options.message },
27422
+ ...pullRequest?.number && {
27423
+ "workers/pull_request_number": pullRequest.number
27424
+ },
27425
+ ...pullRequest?.title && {
27426
+ "workers/pull_request_title": pullRequest.title
27427
+ },
27428
+ ...pullRequest?.url && { "workers/pull_request_url": pullRequest.url },
27429
+ ...repositoryUrl && { "workers/repository_url": repositoryUrl },
27271
27430
  ...options.tag && { "workers/tag": options.tag }
27272
27431
  };
27273
27432
  }
@@ -27340,14 +27499,21 @@ function formatUrlLines(label, urls) {
27340
27499
  ];
27341
27500
  }
27342
27501
  __name(formatUrlLines, "formatUrlLines");
27343
- function formatPreviewDeploymentSummary(previewResource, deployment, isNew) {
27502
+ function formatPreviewDeploymentSummary(previewResource, deployment, isNew, pullRequest) {
27344
27503
  const statusLabel = isNew ? chalk6.green("(new)") : chalk6.dim("(updated)");
27504
+ const pullRequestUrl = deployment.annotations?.["workers/pull_request_url"] ?? pullRequest?.url;
27505
+ const pullRequestNumber = deployment.annotations?.["workers/pull_request_number"] ?? pullRequest?.number;
27506
+ const hasActiveUrls = (previewResource.urls?.length ?? 0) > 0 || (deployment.urls?.length ?? 0) > 0;
27345
27507
  return [
27346
27508
  `${chalk6.bold("Preview:")} ${previewResource.name} ${statusLabel}`,
27347
27509
  ...formatUrlLines("Preview", previewResource.urls),
27348
27510
  "",
27349
27511
  `${chalk6.bold("Deployment ID:")} ${deployment.id}`,
27350
- ...formatUrlLines("Deployment", deployment.urls)
27512
+ ...formatUrlLines("Deployment", deployment.urls),
27513
+ ...pullRequestUrl || pullRequestNumber ? [
27514
+ `${chalk6.bold("Pull Request:")} ${pullRequestUrl ?? `#${pullRequestNumber}`}`
27515
+ ] : [],
27516
+ ...hasActiveUrls ? [] : [NO_ACTIVE_PREVIEW_URLS_MESSAGE]
27351
27517
  ].join("\n");
27352
27518
  }
27353
27519
  __name(formatPreviewDeploymentSummary, "formatPreviewDeploymentSummary");
@@ -27420,6 +27586,9 @@ async function preview(accountId, args, config2, buildResult, assetsOptions, cal
27420
27586
  const ignoreBaseConfig = args.ignoreBaseConfig;
27421
27587
  const fallbackTag = !args.tag && shouldUseCIMetadataFallback() ? getHeadCommitRef() : void 0;
27422
27588
  const fallbackMessage = !args.message && shouldUseCIMetadataFallback() ? getHeadCommitMessage() : void 0;
27589
+ const repositoryUrl = getRepositoryUrl();
27590
+ const pullRequest = getPullRequestMetadata();
27591
+ const commitSha = getCommitSha();
27423
27592
  let existingPreview = null;
27424
27593
  try {
27425
27594
  existingPreview = await getPreview(
@@ -27479,6 +27648,9 @@ async function preview(accountId, args, config2, buildResult, assetsOptions, cal
27479
27648
  {
27480
27649
  message: args.message ?? fallbackMessage,
27481
27650
  tag: args.tag ?? fallbackTag,
27651
+ repositoryUrl,
27652
+ pullRequest,
27653
+ commitSha,
27482
27654
  assetsOptions
27483
27655
  }
27484
27656
  );
@@ -27511,7 +27683,12 @@ async function preview(accountId, args, config2, buildResult, assetsOptions, cal
27511
27683
  );
27512
27684
  } else {
27513
27685
  logger.log(
27514
- formatPreviewDeploymentSummary(previewResource, deployment, isNewPreview)
27686
+ formatPreviewDeploymentSummary(
27687
+ previewResource,
27688
+ deployment,
27689
+ isNewPreview,
27690
+ pullRequest
27691
+ )
27515
27692
  );
27516
27693
  const topLevelBindings = getBindings(config2);
27517
27694
  if (Object.keys(topLevelBindings).length > 0) {
@@ -27862,4 +28039,4 @@ __name(previewSettingsUpdate, "previewSettingsUpdate");
27862
28039
  * THE SOFTWARE.
27863
28040
  */
27864
28041
 
27865
- export { ACTOR_BINDING_DEPENDS_ON_EXPORT_CODE, EXPORTS_RECONCILIATION_ERROR_CODE, INCONSISTENT_EXPORTS_ACROSS_VERSIONS_CODE, INVALID_INHERIT_BINDING_CODE, NoInputError, WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE, WORKER_NOT_FOUND_ERR_CODE, WORKFLOW_CRON_REQUIRES_PAID_PLAN_CODE, WORKFLOW_NOT_FOUND_CODE, addRequiredSecretsInheritBindings, addWorkersSitesBindings, applyServiceAndEnvironmentTags, assemblePreviewDefaults, assemblePreviewScriptSettings, buildAssetManifest, checkRemoteSecretsOverride, checkWorkflowConflicts, collectPackageDependencies, confirmLatestDeploymentOverwrite, createDeployment, createPreview, createPreviewDeployment, createPreviewParentWorker, createTruncatedAlias, decodeJwtPayload, deletePreview, deletePullConsumer, deleteWorkerConsumer, deploy, deployWfpUserWorker, diagnoseScriptSizeError, diagnoseStartupError, diffJsonObjects, downloadWorkerConfig, drawBox, drawConnectedChildBox, editPreview, editWorkerPreviewDefaults, ensureQueuesExistByConfig, extractConfigBindings, fetchDeployableVersions, fetchDeploymentVersions, fetchLatestDeployment, fetchLatestDeployments, fetchSecrets, fetchVersion, fetchVersions, fetchWorkerConfig, formatAlignedRows, formatBindings, formatPreviewsSettings, generatePreviewAlias, getBindingValue, getBranchName2 as getBranchName, getConfigPatch, getDeployConfirmFunction, getEdgeKvUploadConcurrency, getHeadCommitMessage, getHeadCommitRef, getMigrationsToUpload, getPreview, getPreviewBaseConfig, getPreviewDeployment, getPreviewOwnedContainerClassNames, getQueue, getRemoteConfigDiff, getSettings, getSourceMappedStack, getSourceMappedString, getSubdomainValues, getSubdomainValuesAPIMock, getWorkerPreviewDefaults, getWorkersDevSubdomain, getZoneForRoute, getZoneIdFromHost, handleMissingSecretsError, hasDefinedEnvironments, hashFile, helpIfErrorIsSizeOrScriptStartup, isExportsReconciliationErrorDetails, isJwtExpired, isModifiedDiffValue, isNonDestructive, isWorkerNotFoundError, listConsumers, listQueues, maybeRetrieveFileSourceMap, mergeDeep, padToVisibleWidth, parseBulkInputToObject, parseConfigPlacement, patchNonVersionedScriptSettings, patchPreviewBaseConfig, patchPreviewDeployment, postConsumer, preview, previewContainerAppName, previewDelete, previewSettingsGet, previewSettingsUpdate, printBindings, printBundleSize, printVersions, provisionBindings, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderBindingDependsOnExportError, renderExportsReconciliationError, renderExportsReconciliationSuccess, renderInconsistentExportsAcrossVersionsError, renderRoute, resolveAssetOptions, resolveDoLifecyclePayload, resolveExportsUploadPayload, resolveWorkerName, sanitizeBranchName, shouldUseCIMetadataFallback, stripAnsi, syncAssets, tagsAreEqual, triggersDeploy, updateQueueConsumers, validateEventTriggerTargets, validateFileSecrets, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, visibleLength, warnOnErrorUpdatingServiceAndEnvironmentTags, warnOrError, workerNotFoundErrorMessage };
28042
+ export { ACTOR_BINDING_DEPENDS_ON_EXPORT_CODE, EXPORTS_RECONCILIATION_ERROR_CODE, INCONSISTENT_EXPORTS_ACROSS_VERSIONS_CODE, INVALID_INHERIT_BINDING_CODE, NO_ACTIVE_PREVIEW_URLS_MESSAGE, NoInputError, WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE, WORKER_NOT_FOUND_ERR_CODE, WORKFLOW_CRON_REQUIRES_PAID_PLAN_CODE, WORKFLOW_NOT_FOUND_CODE, addRequiredSecretsInheritBindings, addWorkersSitesBindings, applyServiceAndEnvironmentTags, assemblePreviewDefaults, assemblePreviewScriptSettings, buildAssetManifest, checkRemoteSecretsOverride, checkWorkflowConflicts, collectPackageDependencies, confirmLatestDeploymentOverwrite, createDeployment, createPreview, createPreviewDeployment, createPreviewParentWorker, createTruncatedAlias, decodeJwtPayload, deletePreview, deletePullConsumer, deleteWorkerConsumer, deploy, deployWfpUserWorker, diagnoseScriptSizeError, diagnoseStartupError, diffJsonObjects, downloadWorkerConfig, drawBox, drawConnectedChildBox, editPreview, editWorkerPreviewDefaults, ensureQueuesExistByConfig, extractConfigBindings, fetchDeployableVersions, fetchDeploymentVersions, fetchLatestDeployment, fetchLatestDeployments, fetchSecrets, fetchVersion, fetchVersions, fetchWorkerConfig, formatAlignedRows, formatBindings, formatPreviewsSettings, generatePreviewAlias, getBindingValue, getBranchName2 as getBranchName, getCommitSha, getConfigPatch, getDeployConfirmFunction, getEdgeKvUploadConcurrency, getHeadCommitMessage, getHeadCommitRef, getMigrationsToUpload, getPreview, getPreviewBaseConfig, getPreviewDeployment, getPreviewOwnedContainerClassNames, getPullRequestMetadata, getQueue, getRemoteConfigDiff, getRepositoryUrl, getSettings, getSourceMappedStack, getSourceMappedString, getSubdomainValues, getSubdomainValuesAPIMock, getWorkerPreviewDefaults, getWorkersDevSubdomain, getZoneForRoute, getZoneIdFromHost, handleMissingSecretsError, hasDefinedEnvironments, hashFile, helpIfErrorIsSizeOrScriptStartup, isExportsReconciliationErrorDetails, isJwtExpired, isModifiedDiffValue, isNonDestructive, isWorkerNotFoundError, listConsumers, listQueues, maybeRetrieveFileSourceMap, mergeDeep, padToVisibleWidth, parseBulkInputToObject, parseConfigPlacement, patchNonVersionedScriptSettings, patchPreviewBaseConfig, patchPreviewDeployment, postConsumer, preview, previewContainerAppName, previewDelete, previewSettingsGet, previewSettingsUpdate, printBindings, printBundleSize, printVersions, provisionBindings, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderBindingDependsOnExportError, renderExportsReconciliationError, renderExportsReconciliationSuccess, renderInconsistentExportsAcrossVersionsError, renderRoute, resolveAssetOptions, resolveDoLifecyclePayload, resolveExportsUploadPayload, resolveWorkerName, sanitizeBranchName, shouldUseCIMetadataFallback, stripAnsi, syncAssets, tagsAreEqual, triggersDeploy, updateQueueConsumers, validateEventTriggerTargets, validateFileSecrets, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, visibleLength, warnOnErrorUpdatingServiceAndEnvironmentTags, warnOrError, workerNotFoundErrorMessage };