-
Notifications
You must be signed in to change notification settings - Fork 222
Thad castl3 main #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thad castl3 main #428
Changes from 6 commits
bb25dd7
93bfe47
0c94d23
6f6d7eb
0aeca82
43f1c76
4c9959f
ab40107
561f0e1
8ec7c1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -40,19 +40,36 @@ export type ProductionSuccessResult = { | |||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export type ForceProductionSuccessResult = { | ||||||||||||||||||||||||||||||||||||||
| status: "success"; | ||||||||||||||||||||||||||||||||||||||
| result: { | ||||||||||||||||||||||||||||||||||||||
| hosting: string | string[]; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export type ForceChannelSuccessResult = { | ||||||||||||||||||||||||||||||||||||||
| status: "success"; | ||||||||||||||||||||||||||||||||||||||
| result: { [key: string]: SiteDeploy }; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| type DeployConfig = { | ||||||||||||||||||||||||||||||||||||||
| projectId: string; | ||||||||||||||||||||||||||||||||||||||
| target?: string; | ||||||||||||||||||||||||||||||||||||||
| // Optional version specification for firebase-tools. Defaults to `latest`. | ||||||||||||||||||||||||||||||||||||||
| firebaseToolsVersion?: string; | ||||||||||||||||||||||||||||||||||||||
| force?: boolean; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export type ChannelDeployConfig = DeployConfig & { | ||||||||||||||||||||||||||||||||||||||
| expires: string; | ||||||||||||||||||||||||||||||||||||||
| channelId: string; | ||||||||||||||||||||||||||||||||||||||
| force?: boolean; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export type ProductionDeployConfig = DeployConfig & {}; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export type ProductionDeployConfig = DeployConfig & { | ||||||||||||||||||||||||||||||||||||||
| force?: boolean; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export function interpretChannelDeployResult( | ||||||||||||||||||||||||||||||||||||||
| deployResult: ChannelSuccessResult | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -74,18 +91,20 @@ async function execWithCredentials( | |||||||||||||||||||||||||||||||||||||
| args: string[], | ||||||||||||||||||||||||||||||||||||||
| projectId, | ||||||||||||||||||||||||||||||||||||||
| gacFilename, | ||||||||||||||||||||||||||||||||||||||
| opts: { debug?: boolean; firebaseToolsVersion?: string } | ||||||||||||||||||||||||||||||||||||||
| opts: { debug?: boolean; firebaseToolsVersion?: string; force?: boolean } | ||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||
| let deployOutputBuf: Buffer[] = []; | ||||||||||||||||||||||||||||||||||||||
| const debug = opts.debug || false; | ||||||||||||||||||||||||||||||||||||||
| const firebaseToolsVersion = opts.firebaseToolsVersion || "latest"; | ||||||||||||||||||||||||||||||||||||||
| const force = opts.force; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| await exec( | ||||||||||||||||||||||||||||||||||||||
| `npx firebase-tools@${firebaseToolsVersion}`, | ||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||
| ...args, | ||||||||||||||||||||||||||||||||||||||
| ...(projectId ? ["--project", projectId] : []), | ||||||||||||||||||||||||||||||||||||||
| ...(force ? ["--force"] : []), | ||||||||||||||||||||||||||||||||||||||
| debug | ||||||||||||||||||||||||||||||||||||||
| ? "--debug" // gives a more thorough error message | ||||||||||||||||||||||||||||||||||||||
| : "--json", // allows us to easily parse the output | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -114,6 +133,7 @@ async function execWithCredentials( | |||||||||||||||||||||||||||||||||||||
| await execWithCredentials(args, projectId, gacFilename, { | ||||||||||||||||||||||||||||||||||||||
| debug: true, | ||||||||||||||||||||||||||||||||||||||
| firebaseToolsVersion, | ||||||||||||||||||||||||||||||||||||||
| force, | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| throw e; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -129,7 +149,7 @@ export async function deployPreview( | |||||||||||||||||||||||||||||||||||||
| gacFilename: string, | ||||||||||||||||||||||||||||||||||||||
| deployConfig: ChannelDeployConfig | ||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||
| const { projectId, channelId, target, expires, firebaseToolsVersion } = | ||||||||||||||||||||||||||||||||||||||
| const { projectId, channelId, target, expires, firebaseToolsVersion, force } = | ||||||||||||||||||||||||||||||||||||||
| deployConfig; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const deploymentText = await execWithCredentials( | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -141,7 +161,7 @@ export async function deployPreview( | |||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||
| projectId, | ||||||||||||||||||||||||||||||||||||||
| gacFilename, | ||||||||||||||||||||||||||||||||||||||
| { firebaseToolsVersion } | ||||||||||||||||||||||||||||||||||||||
| { firebaseToolsVersion, force } | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const deploymentResult = JSON.parse(deploymentText.trim()) as | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -155,13 +175,14 @@ export async function deployProductionSite( | |||||||||||||||||||||||||||||||||||||
| gacFilename, | ||||||||||||||||||||||||||||||||||||||
| productionDeployConfig: ProductionDeployConfig | ||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||
| const { projectId, target, firebaseToolsVersion } = productionDeployConfig; | ||||||||||||||||||||||||||||||||||||||
| const { projectId, target, firebaseToolsVersion, force } = | ||||||||||||||||||||||||||||||||||||||
| productionDeployConfig; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const deploymentText = await execWithCredentials( | ||||||||||||||||||||||||||||||||||||||
| ["deploy", "--only", `hosting${target ? ":" + target : ""}`], | ||||||||||||||||||||||||||||||||||||||
| projectId, | ||||||||||||||||||||||||||||||||||||||
| gacFilename, | ||||||||||||||||||||||||||||||||||||||
| { firebaseToolsVersion } | ||||||||||||||||||||||||||||||||||||||
| { firebaseToolsVersion, force } | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const deploymentResult = JSON.parse(deploymentText) as | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,18 @@ const baseLiveDeployConfig: ProductionDeployConfig = { | |||||||||||||||||||
| projectId: "my-project", | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const forceProductionDeployConfig: ProductionDeployConfig = { | ||||||||||||||||||||
| projectId: "my-project", | ||||||||||||||||||||
| force: true, | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const forcePreviewDeployConfig: ChannelDeployConfig = { | ||||||||||||||||||||
| projectId: "my-project", | ||||||||||||||||||||
| channelId: "my-channel", | ||||||||||||||||||||
| expires: undefined, | ||||||||||||||||||||
| force: true, | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| async function fakeExecFail( | ||||||||||||||||||||
| mainCommand: string, | ||||||||||||||||||||
| args: string[], | ||||||||||||||||||||
|
|
@@ -128,6 +140,48 @@ describe("deploy", () => { | |||||||||||||||||||
| }); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| describe("deploy to preview channel with force flag", () => { | ||||||||||||||||||||
| it("calls exec and interprets the output, including the --force flag when force is true", async () => { | ||||||||||||||||||||
| // @ts-ignore read-only property | ||||||||||||||||||||
| exec.exec = jest.fn(fakeExec); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const deployOutput: ChannelSuccessResult = (await deployPreview( | ||||||||||||||||||||
| "my-file", | ||||||||||||||||||||
| forcePreviewDeployConfig | ||||||||||||||||||||
| )) as ChannelSuccessResult; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| expect(exec.exec).toBeCalled(); | ||||||||||||||||||||
| expect(deployOutput).toEqual(channelSingleSiteSuccess); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Check the arguments that exec was called with | ||||||||||||||||||||
| // @ts-ignore Jest adds a magic "mock" property | ||||||||||||||||||||
| const args = exec.exec.mock.calls; | ||||||||||||||||||||
| const deployFlags = args[0][1]; | ||||||||||||||||||||
| expect(deployFlags).toContain("hosting:channel:deploy"); | ||||||||||||||||||||
| expect(deployFlags).toContain("--force"); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it("specifies a target when one is provided", async () => { | ||||||||||||||||||||
| // @ts-ignore read-only property | ||||||||||||||||||||
| exec.exec = jest.fn(fakeExec); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const config: ChannelDeployConfig = { | ||||||||||||||||||||
| ...baseChannelDeployConfig, | ||||||||||||||||||||
| target: "my-second-site", | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case is intended to check that
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| await deployPreview("my-file", config); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Check the arguments that exec was called with | ||||||||||||||||||||
| // @ts-ignore Jest adds a magic "mock" property | ||||||||||||||||||||
| const args = exec.exec.mock.calls; | ||||||||||||||||||||
| const deployFlags = args[0][1]; | ||||||||||||||||||||
| expect(deployFlags).toContain("--only"); | ||||||||||||||||||||
| expect(deployFlags).toContain("my-second-site"); | ||||||||||||||||||||
| expect(deployFlags).toContain("--force"); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| describe("deploy to live channel", () => { | ||||||||||||||||||||
| it("calls exec and interprets the output", async () => { | ||||||||||||||||||||
| // @ts-ignore read-only property | ||||||||||||||||||||
|
|
@@ -150,4 +204,28 @@ describe("deploy", () => { | |||||||||||||||||||
| expect(deployFlags).toContain("hosting"); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| describe("deploy to live channel with force flag", () => { | ||||||||||||||||||||
| it("includes --force flag when force is true for deploy", async () => { | ||||||||||||||||||||
| // @ts-ignore read-only property | ||||||||||||||||||||
| exec.exec = jest.fn(fakeExec); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const forceDeployOutput: ProductionSuccessResult = (await deployProductionSite( | ||||||||||||||||||||
| "my-file", | ||||||||||||||||||||
| forceProductionDeployConfig | ||||||||||||||||||||
| )) as ProductionSuccessResult; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| expect(exec.exec).toBeCalled(); | ||||||||||||||||||||
| expect(forceDeployOutput).toEqual(liveDeploySingleSiteSuccess); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Check the arguments that exec was called with | ||||||||||||||||||||
| // @ts-ignore Jest adds a magic "mock" property | ||||||||||||||||||||
| const args = exec.exec.mock.calls; | ||||||||||||||||||||
| const deployFlags = args[0][1]; | ||||||||||||||||||||
| expect(deployFlags).toContain("deploy"); | ||||||||||||||||||||
| expect(deployFlags).toContain("--only"); | ||||||||||||||||||||
| expect(deployFlags).toContain("hosting"); | ||||||||||||||||||||
| expect(deployFlags).toContain("--force"); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This compiled file appears to be out of sync with the TypeScript source files (
src/index.tsandsrc/deploy.ts). It contains adeployWithForcefunction and a specialif (force)block in the mainrunfunction, which are not present in the source and represent an incorrect implementation approach. The logic insrc/index.tscorrectly passes theforceflag to the existing deploy functions, which is the right way to do it.Please run the build process to update this file from the TypeScript source. The current state of this file will cause incorrect behavior.