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
7 changes: 7 additions & 0 deletions .changeset/preview-build-output-secrets-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/deploy-helpers": minor
---

Accept a secrets file when uploading a Preview from Build Output

`previewBuildOutput()` now takes the same `secretsFile` option as `preview()`. The file's secrets are uploaded with the Preview deployment, so a CLI that deploys Previews from Build Output can set Preview secrets without a separate command or the Cloudflare dashboard.
4 changes: 2 additions & 2 deletions packages/deploy-helpers/src/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1338,12 +1338,12 @@ export async function preview(
* Upload a Preview from resolved Build Output configuration.
*
* @param accountId Account that owns the parent Worker.
* @param args Preview name and deployment annotations.
* @param args Preview name, deployment annotations, and secrets file.
* @param buildOutput Exact configuration and artifacts emitted by the build.
*/
export async function previewBuildOutput(
accountId: string,
args: Pick<PreviewArgs, "name" | "tag" | "message" | "json">,
args: Pick<PreviewArgs, "name" | "tag" | "message" | "json" | "secretsFile">,
buildOutput: PreviewBuildOutput,
options?: PreviewOptions
): Promise<PreviewResult> {
Expand Down
29 changes: 29 additions & 0 deletions packages/deploy-helpers/tests/preview-build-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,35 @@ describe("previewBuildOutput", () => {
expect(request.env).toEqual({ API_KEY: { type: "inherit" } });
});

it("uploads secrets from a secrets file", async ({ expect }) => {
writeFileSync(".env.preview", "API_KEY=new-key\nTOKEN=token\n");
mocks.getPreviewDeployment.mockResolvedValue({
...deploymentResource,
env: { API_KEY: { type: "secret_text" } },
});
mocks.createPreviewDeployment.mockResolvedValue({
...deploymentResource,
env: { TOKEN: { type: "secret_text", text: "token" } },
});

const result = await previewBuildOutput(
"account-id",
{ name: "feature", json: true, secretsFile: ".env.preview" },
{
workerConfig: buildOutputConfig(),
rootConfig: validRootConfig,
buildResult,
}
);

const request = mocks.createPreviewDeployment.mock.calls[0]?.[4];
expect(request.env).toEqual({
API_KEY: { type: "secret_text", text: "new-key" },
TOKEN: { type: "secret_text", text: "token" },
});
expect(result.deployment.env).toEqual({ TOKEN: { type: "secret_text" } });
});

it("does not look up the latest deployment of a new Preview", async ({
expect,
}) => {
Expand Down
Loading