Skip to content

Commit

Permalink
Add target option (#41)
Browse files Browse the repository at this point in the history
* Add target option

* Fix format

* Update src/deploy.ts

DRY `--only hosting` once

Co-authored-by: Jeff <jhuleatt@google.com>

* Update src/deploy.ts

Co-authored-by: Jeff <jhuleatt@google.com>

* Update action.yml

Not really pertinent to my change, but reads clearer, so thank you 🤓

Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com>

* Better description

Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com>

* Make target optional in productionDeployConfig

* Commit prettier suggestions

* Add bin contents per #47 workflow

Co-authored-by: Jeff <jhuleatt@google.com>
Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 23, 2020
1 parent 58c4f50 commit 8660c48
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
10 changes: 8 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ inputs:
a .firebaserc file"
required: false
channelId:
description: "The ID of the channel to deploy to. If you leave this blank,
a preview channel and its ID will be auto-generated per branch or PR."
required: false
target:
description:
"The preview channel id to deploy to. If you leave this blank, an channel
id will be auto-generated per branch or PR"
"The target name of the Hosting site to deploy to. If you leave this blank,
the default target or all targets defined in the .firebaserc will be deployed to.
Refer to the Hosting docs about [multiple sites](https://firebase.google.com/docs/hosting/multisites)
for more information about deploy targets."
required: false
entryPoint:
description:
Expand Down
2 changes: 1 addition & 1 deletion bin/action.min.js

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export type DeployConfig = {
projectId: string;
expires: string;
channelId: string;
target: string;
};

export type productionDeployConfig = {
projectId: string;
target?: string;
};

async function execWithCredentials(
Expand Down Expand Up @@ -97,13 +103,14 @@ async function execWithCredentials(
}

export async function deploy(gacFilename: string, deployConfig: DeployConfig) {
const { projectId, expires, channelId } = deployConfig;
const { projectId, expires, channelId, target } = deployConfig;

const deploymentText = await execWithCredentials(
"npx firebase-tools",
[
"hosting:channel:deploy",
channelId,
...(target ? ["--only", target] : []),
...(expires ? ["--expires", expires] : []),
],
projectId,
Expand All @@ -117,10 +124,15 @@ export async function deploy(gacFilename: string, deployConfig: DeployConfig) {
return deploymentResult;
}

export async function deployProductionSite(gacFilename, projectId) {
export async function deployProductionSite(
gacFilename,
productionDeployConfig: productionDeployConfig
) {
const { projectId, target } = productionDeployConfig;

const deploymentText = await execWithCredentials(
"npx firebase-tools",
["deploy", "--only", "hosting"],
["deploy", "--only", `hosting${target ? ":" + target : ""}`],
projectId,
gacFilename
);
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const isProductionDeploy = configuredChannelId === "live";
const token = process.env.GITHUB_TOKEN || getInput("repoToken");
const github = token ? new GitHub(token) : undefined;
const entryPoint = getInput("entryPoint");
const target = getInput("target");

async function run() {
const isPullRequest = !!context.payload.pull_request;
Expand Down Expand Up @@ -79,7 +80,10 @@ async function run() {

if (isProductionDeploy) {
startGroup("Deploying to production site");
const deployment = await deployProductionSite(gacFilename, projectId);
const deployment = await deployProductionSite(gacFilename, {
projectId,
target,
});
if (deployment.status === "error") {
throw Error((deployment as ErrorResult).error);
}
Expand All @@ -104,6 +108,7 @@ async function run() {
projectId,
expires,
channelId,
target,
});
endGroup();

Expand Down

0 comments on commit 8660c48

Please sign in to comment.