Skip to content

Commit 43f1c76

Browse files
committed
accepted update to action.yml for 'force' flag description, added support for channel site deployment with force flag. Updated tests to and types to account for force flags. Force flag is now optional on ProductionDeployConfig and ChannelDeployConfig. Simplified deploy calls using force flag to automatically append force based on the boolean value nad removed the force-specific branch in index.ts
1 parent 0aeca82 commit 43f1c76

4 files changed

Lines changed: 67 additions & 70 deletions

File tree

src/deploy.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ export type ProductionSuccessResult = {
4040
};
4141
};
4242

43-
export type ForceSuccessResult = {
43+
export type ForceProductionSuccessResult = {
4444
status: "success";
4545
result: {
4646
hosting: string | string[];
4747
};
4848
};
4949

50+
export type ForceChannelSuccessResult = {
51+
status: "success";
52+
result: { [key: string]: SiteDeploy };
53+
};
54+
5055
type DeployConfig = {
5156
projectId: string;
5257
target?: string;
@@ -58,13 +63,13 @@ type DeployConfig = {
5863
export type ChannelDeployConfig = DeployConfig & {
5964
expires: string;
6065
channelId: string;
66+
force?: boolean;
6167
};
6268

63-
export type ForceDeployConfig = DeployConfig & {
64-
force: boolean;
65-
};
6669

67-
export type ProductionDeployConfig = DeployConfig & {};
70+
export type ProductionDeployConfig = DeployConfig & {
71+
force?: boolean;
72+
};
6873

6974
export function interpretChannelDeployResult(
7075
deployResult: ChannelSuccessResult
@@ -186,23 +191,3 @@ export async function deployProductionSite(
186191

187192
return deploymentResult;
188193
}
189-
190-
export async function deployWithForce(
191-
gacFilename,
192-
deployConfig: ForceDeployConfig
193-
) {
194-
const { projectId, target, firebaseToolsVersion, force } = deployConfig;
195-
196-
const deploymentText = await execWithCredentials(
197-
["deploy", "--only", `hosting${target ? ":" + target : ""}`, "--force"],
198-
projectId,
199-
gacFilename,
200-
{ firebaseToolsVersion, force }
201-
);
202-
203-
const deploymentResult = JSON.parse(deploymentText) as
204-
| ForceSuccessResult
205-
| ErrorResult;
206-
207-
return deploymentResult;
208-
}

src/index.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { createGacFile } from "./createGACFile";
2828
import {
2929
deployPreview,
3030
deployProductionSite,
31-
deployWithForce,
3231
ErrorResult,
3332
interpretChannelDeployResult,
3433
} from "./deploy";
@@ -90,32 +89,6 @@ async function run() {
9089
);
9190
endGroup();
9291

93-
if (force) {
94-
startGroup("Deploying with force flag");
95-
const deployment = await deployWithForce(gacFilename, {
96-
projectId,
97-
target,
98-
firebaseToolsVersion,
99-
force,
100-
});
101-
if (deployment.status === "error") {
102-
throw Error((deployment as ErrorResult).error);
103-
}
104-
endGroup();
105-
106-
const hostname = target ? `${target}.web.app` : `${projectId}.web.app`;
107-
const url = `https://${hostname}/`;
108-
await finish({
109-
details_url: url,
110-
conclusion: "success",
111-
output: {
112-
title: `Production deploy succeeded`,
113-
summary: `[${hostname}](${url})`,
114-
},
115-
});
116-
return;
117-
}
118-
11992
if (isProductionDeploy) {
12093
startGroup("Deploying to production site");
12194
const deployment = await deployProductionSite(gacFilename, {

test/deploy.test.ts

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import {
55
deployProductionSite,
66
ProductionDeployConfig,
77
ProductionSuccessResult,
8-
ForceDeployConfig,
9-
deployWithForce,
10-
ForceSuccessResult,
118
} from "../src/deploy";
129
import * as exec from "@actions/exec";
1310
import {
1411
channelError,
1512
channelMultiSiteSuccess,
1613
channelSingleSiteSuccess,
17-
forceDeploySingleSiteSuccess,
1814
liveDeployMultiSiteSuccess,
1915
liveDeploySingleSiteSuccess,
2016
} from "./samples/cliOutputs";
@@ -29,11 +25,18 @@ const baseLiveDeployConfig: ProductionDeployConfig = {
2925
projectId: "my-project",
3026
};
3127

32-
const forceDeployConfig: ForceDeployConfig = {
28+
const forceProductionDeployConfig: ProductionDeployConfig = {
3329
projectId: "my-project",
3430
force: true,
3531
};
3632

33+
const forcePreviewDeployConfig: ChannelDeployConfig = {
34+
projectId: "my-project",
35+
channelId: "my-channel",
36+
expires: undefined,
37+
force: true,
38+
};
39+
3740
async function fakeExecFail(
3841
mainCommand: string,
3942
args: string[],
@@ -137,6 +140,48 @@ describe("deploy", () => {
137140
});
138141
});
139142

143+
describe("deploy to preview channel with force flag", () => {
144+
it("calls exec and interprets the output, including the --force flag when force is true", async () => {
145+
// @ts-ignore read-only property
146+
exec.exec = jest.fn(fakeExec);
147+
148+
const deployOutput: ChannelSuccessResult = (await deployPreview(
149+
"my-file",
150+
forcePreviewDeployConfig
151+
)) as ChannelSuccessResult;
152+
153+
expect(exec.exec).toBeCalled();
154+
expect(deployOutput).toEqual(channelSingleSiteSuccess);
155+
156+
// Check the arguments that exec was called with
157+
// @ts-ignore Jest adds a magic "mock" property
158+
const args = exec.exec.mock.calls;
159+
const deployFlags = args[0][1];
160+
expect(deployFlags).toContain("hosting:channel:deploy");
161+
expect(deployFlags).toContain("--force");
162+
});
163+
164+
it("specifies a target when one is provided", async () => {
165+
// @ts-ignore read-only property
166+
exec.exec = jest.fn(fakeExec);
167+
168+
const config: ChannelDeployConfig = {
169+
...baseChannelDeployConfig,
170+
target: "my-second-site",
171+
};
172+
173+
await deployPreview("my-file", config);
174+
175+
// Check the arguments that exec was called with
176+
// @ts-ignore Jest adds a magic "mock" property
177+
const args = exec.exec.mock.calls;
178+
const deployFlags = args[0][1];
179+
expect(deployFlags).toContain("--only");
180+
expect(deployFlags).toContain("my-second-site");
181+
expect(deployFlags).toContain("--force");
182+
});
183+
});
184+
140185
describe("deploy to live channel", () => {
141186
it("calls exec and interprets the output", async () => {
142187
// @ts-ignore read-only property
@@ -160,18 +205,18 @@ describe("deploy", () => {
160205
});
161206
});
162207

163-
describe("deploy with force flag", () => {
208+
describe("deploy to live channel with force flag", () => {
164209
it("includes --force flag when force is true for deploy", async () => {
165210
// @ts-ignore read-only property
166211
exec.exec = jest.fn(fakeExec);
167212

168-
const forceDeployOutput: ForceSuccessResult = (await deployWithForce(
213+
const forceDeployOutput: ProductionSuccessResult = (await deployProductionSite(
169214
"my-file",
170-
forceDeployConfig
171-
)) as ForceSuccessResult;
215+
forceProductionDeployConfig
216+
)) as ProductionSuccessResult;
172217

173218
expect(exec.exec).toBeCalled();
174-
expect(forceDeployOutput).toEqual(forceDeploySingleSiteSuccess);
219+
expect(forceDeployOutput).toEqual(liveDeploySingleSiteSuccess);
175220

176221
// Check the arguments that exec was called with
177222
// @ts-ignore Jest adds a magic "mock" property

test/samples/cliOutputs.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
ChannelSuccessResult,
33
ErrorResult,
4-
ForceSuccessResult,
4+
ForceProductionSuccessResult,
5+
ForceChannelSuccessResult,
56
ProductionSuccessResult,
67
} from "../../src/deploy";
78

@@ -58,10 +59,3 @@ export const liveDeployMultiSiteSuccess: ProductionSuccessResult = {
5859
],
5960
},
6061
};
61-
62-
export const forceDeploySingleSiteSuccess: ForceSuccessResult = {
63-
status: "success",
64-
result: {
65-
hosting: "sites/jeff-test-699d3/versions/7aebddc461b66922",
66-
},
67-
};

0 commit comments

Comments
 (0)