Skip to content

Commit 8660c48

Browse files
expatiatingjhuleattrachelsaunders
authored
Add target option (#41)
* Add target option * Fix format * Update src/deploy.ts DRY `--only hosting` once Co-authored-by: Jeff <[email protected]> * Update src/deploy.ts Co-authored-by: Jeff <[email protected]> * Update action.yml Not really pertinent to my change, but reads clearer, so thank you 🤓 Co-authored-by: rachelsaunders <[email protected]> * Better description Co-authored-by: rachelsaunders <[email protected]> * Make target optional in productionDeployConfig * Commit prettier suggestions * Add bin contents per #47 workflow Co-authored-by: Jeff <[email protected]> Co-authored-by: rachelsaunders <[email protected]>
1 parent 58c4f50 commit 8660c48

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

action.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ inputs:
3838
a .firebaserc file"
3939
required: false
4040
channelId:
41+
description: "The ID of the channel to deploy to. If you leave this blank,
42+
a preview channel and its ID will be auto-generated per branch or PR."
43+
required: false
44+
target:
4145
description:
42-
"The preview channel id to deploy to. If you leave this blank, an channel
43-
id will be auto-generated per branch or PR"
46+
"The target name of the Hosting site to deploy to. If you leave this blank,
47+
the default target or all targets defined in the .firebaserc will be deployed to.
48+
Refer to the Hosting docs about [multiple sites](https://firebase.google.com/docs/hosting/multisites)
49+
for more information about deploy targets."
4450
required: false
4551
entryPoint:
4652
description:

bin/action.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/deploy.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export type DeployConfig = {
4444
projectId: string;
4545
expires: string;
4646
channelId: string;
47+
target: string;
48+
};
49+
50+
export type productionDeployConfig = {
51+
projectId: string;
52+
target?: string;
4753
};
4854

4955
async function execWithCredentials(
@@ -97,13 +103,14 @@ async function execWithCredentials(
97103
}
98104

99105
export async function deploy(gacFilename: string, deployConfig: DeployConfig) {
100-
const { projectId, expires, channelId } = deployConfig;
106+
const { projectId, expires, channelId, target } = deployConfig;
101107

102108
const deploymentText = await execWithCredentials(
103109
"npx firebase-tools",
104110
[
105111
"hosting:channel:deploy",
106112
channelId,
113+
...(target ? ["--only", target] : []),
107114
...(expires ? ["--expires", expires] : []),
108115
],
109116
projectId,
@@ -117,10 +124,15 @@ export async function deploy(gacFilename: string, deployConfig: DeployConfig) {
117124
return deploymentResult;
118125
}
119126

120-
export async function deployProductionSite(gacFilename, projectId) {
127+
export async function deployProductionSite(
128+
gacFilename,
129+
productionDeployConfig: productionDeployConfig
130+
) {
131+
const { projectId, target } = productionDeployConfig;
132+
121133
const deploymentText = await execWithCredentials(
122134
"npx firebase-tools",
123-
["deploy", "--only", "hosting"],
135+
["deploy", "--only", `hosting${target ? ":" + target : ""}`],
124136
projectId,
125137
gacFilename
126138
);

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const isProductionDeploy = configuredChannelId === "live";
4040
const token = process.env.GITHUB_TOKEN || getInput("repoToken");
4141
const github = token ? new GitHub(token) : undefined;
4242
const entryPoint = getInput("entryPoint");
43+
const target = getInput("target");
4344

4445
async function run() {
4546
const isPullRequest = !!context.payload.pull_request;
@@ -79,7 +80,10 @@ async function run() {
7980

8081
if (isProductionDeploy) {
8182
startGroup("Deploying to production site");
82-
const deployment = await deployProductionSite(gacFilename, projectId);
83+
const deployment = await deployProductionSite(gacFilename, {
84+
projectId,
85+
target,
86+
});
8387
if (deployment.status === "error") {
8488
throw Error((deployment as ErrorResult).error);
8589
}
@@ -104,6 +108,7 @@ async function run() {
104108
projectId,
105109
expires,
106110
channelId,
111+
target,
107112
});
108113
endGroup();
109114

0 commit comments

Comments
 (0)