Skip to content

Commit 577db06

Browse files
authored
Add entryPoint option (#16)
1 parent 7b568e9 commit 577db06

File tree

10 files changed

+46
-58
lines changed

10 files changed

+46
-58
lines changed

.github/workflows/deploy-preview.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ jobs:
2828
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}"
2929
expires: 30d
3030
projectId: action-hosting-deploy-demo
31+
entryPoint: "./demo"
3132
env:
3233
FIREBASE_CLI_PREVIEWS: hostingchannels

.github/workflows/deploy-production.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ jobs:
1818
expires: 30d
1919
channelId: live
2020
projectId: action-hosting-deploy-demo
21+
entryPoint: "./demo"
2122
env:
2223
FIREBASE_CLI_PREVIEWS: hostingchannels

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ unless you know you want to deploy a certain branch to a long-lived channel (for
105105
example, you may want to deploy every commit from your `next` branch to a
106106
`preprod` channel)
107107

108+
### `entryPoint` _{string}_
109+
110+
The location of your [`firebase.json`](https://firebase.google.com/docs/cli#the_firebasejson_file) file. Defaults to `.` (the root of your repo).
111+
108112
---
109113

110114
This GitHub Action is not an officially supported Google product

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ inputs:
4242
"The preview channel id to deploy to. If you leave this blank, an channel
4343
id will be auto-generated per branch or PR"
4444
required: false
45+
entryPoint:
46+
description:
47+
"The location of your firebase.json file, relative to the root of your
48+
directory"
49+
default: "."
50+
required: false

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.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"hosting": {
3-
"public": "demo",
3+
"public": "public",
44
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
55
}
66
}
File renamed without changes.

src/deploy.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async function execWithCredentials(
7272
},
7373
env: {
7474
...process.env,
75-
FIREBASE_DEPLOY_AGENT: 'action-hosting-deploy',
75+
FIREBASE_DEPLOY_AGENT: "action-hosting-deploy",
7676
GOOGLE_APPLICATION_CREDENTIALS: gacFilename, // the CLI will automatically authenticate with this env variable set
7777
},
7878
}
@@ -94,15 +94,11 @@ async function execWithCredentials(
9494
return Buffer.concat(deployOutputBuf).toString("utf-8"); // output from the CLI
9595
}
9696

97-
export async function deploy(
98-
firebase: string,
99-
gacFilename: string,
100-
deployConfig: DeployConfig
101-
) {
97+
export async function deploy(gacFilename: string, deployConfig: DeployConfig) {
10298
const { projectId, expires, channelId } = deployConfig;
10399

104100
const deploymentText = await execWithCredentials(
105-
firebase,
101+
"npx firebase-tools",
106102
["hosting:channel:deploy", channelId],
107103
projectId,
108104
gacFilename
@@ -115,9 +111,9 @@ export async function deploy(
115111
return deploymentResult;
116112
}
117113

118-
export async function deployProductionSite(firebase, gacFilename, projectId) {
114+
export async function deployProductionSite(gacFilename, projectId) {
119115
const deploymentText = await execWithCredentials(
120-
firebase,
116+
"npx firebase-tools",
121117
["deploy", "--only", "hosting"],
122118
projectId,
123119
gacFilename

src/index.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import {
2222
startGroup,
2323
} from "@actions/core";
2424
import { context, GitHub } from "@actions/github";
25+
import { existsSync } from "fs";
26+
import { createCheck } from "./createCheck";
2527
import { createGacFile } from "./createGACFile";
26-
import { deploy, ErrorResult, deployProductionSite } from "./deploy";
28+
import { deploy, deployProductionSite, ErrorResult } from "./deploy";
2729
import { getChannelId } from "./getChannelId";
28-
import { installFirebaseCLI } from "./installFirebaseCLI";
29-
import { createCheck } from "./createCheck";
3030
import { postOrUpdateComment } from "./postOrUpdateComment";
3131

3232
// Inputs defined in action.yml
@@ -39,6 +39,7 @@ const configuredChannelId = getInput("channelId");
3939
const isProductionDeploy = configuredChannelId === "live";
4040
const token = process.env.GITHUB_TOKEN || getInput("repoToken");
4141
const github = token ? new GitHub(token) : undefined;
42+
const entryPoint = getInput("entryPoint");
4243

4344
async function run() {
4445
const isPullRequest = !!context.payload.pull_request;
@@ -49,21 +50,36 @@ async function run() {
4950
}
5051

5152
try {
52-
startGroup("Setting up Firebase");
53-
const firebase = await installFirebaseCLI();
53+
startGroup("Verifying firebase.json exists");
54+
55+
if (entryPoint !== ".") {
56+
console.log(`Changing to directory: ${entryPoint}`);
57+
try {
58+
process.chdir(entryPoint);
59+
} catch (err) {
60+
throw Error(`Error changing to directory ${entryPoint}: ${err}`);
61+
}
62+
}
63+
64+
if (existsSync("./firebase.json")) {
65+
console.log("firebase.json file found. Continuing deploy.");
66+
} else {
67+
throw Error(
68+
"firebase.json file not found. If your firebase.json file is not in the root of your repo, edit the entryPoint option of this GitHub action."
69+
);
70+
}
5471
endGroup();
5572

5673
startGroup("Setting up CLI credentials");
5774
const gacFilename = await createGacFile(googleApplicationCredentials);
75+
console.log(
76+
"Created a temporary file with Application Default Credentials."
77+
);
5878
endGroup();
5979

6080
if (isProductionDeploy) {
6181
startGroup("Deploying to production site");
62-
const deployment = await deployProductionSite(
63-
firebase,
64-
gacFilename,
65-
projectId
66-
);
82+
const deployment = await deployProductionSite(gacFilename, projectId);
6783
if (deployment.status === "error") {
6884
throw Error((deployment as ErrorResult).error);
6985
}
@@ -84,7 +100,7 @@ async function run() {
84100
const channelId = getChannelId(configuredChannelId, context);
85101

86102
startGroup(`Deploying to Firebase preview channel ${channelId}`);
87-
const deployment = await deploy(firebase, gacFilename, {
103+
const deployment = await deploy(gacFilename, {
88104
projectId,
89105
expires,
90106
channelId,

src/installFirebaseCLI.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)