Skip to content

Commit

Permalink
Add entryPoint option (FirebaseExtended#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuleatt authored Sep 9, 2020
1 parent 0221164 commit d703bec
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 58 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ jobs:
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}"
expires: 30d
projectId: action-hosting-deploy-demo
entryPoint: "./demo"
env:
FIREBASE_CLI_PREVIEWS: hostingchannels
1 change: 1 addition & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ jobs:
expires: 30d
channelId: live
projectId: action-hosting-deploy-demo
entryPoint: "./demo"
env:
FIREBASE_CLI_PREVIEWS: hostingchannels
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ unless you know you want to deploy a certain branch to a long-lived channel (for
example, you may want to deploy every commit from your `next` branch to a
`preprod` channel)

### `entryPoint` _{string}_

The location of your [`firebase.json`](https://firebase.google.com/docs/cli#the_firebasejson_file) file. Defaults to `.` (the root of your repo).

---

This GitHub Action is not an officially supported Google product
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ inputs:
"The preview channel id to deploy to. If you leave this blank, an channel
id will be auto-generated per branch or PR"
required: false
entryPoint:
description:
"The location of your firebase.json file, relative to the root of your
directory"
default: "."
required: false
2 changes: 1 addition & 1 deletion bin/action.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion firebase.json → demo/firebase.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hosting": {
"public": "demo",
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
}
}
File renamed without changes.
14 changes: 5 additions & 9 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function execWithCredentials(
},
env: {
...process.env,
FIREBASE_DEPLOY_AGENT: 'action-hosting-deploy',
FIREBASE_DEPLOY_AGENT: "action-hosting-deploy",
GOOGLE_APPLICATION_CREDENTIALS: gacFilename, // the CLI will automatically authenticate with this env variable set
},
}
Expand All @@ -94,15 +94,11 @@ async function execWithCredentials(
return Buffer.concat(deployOutputBuf).toString("utf-8"); // output from the CLI
}

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

const deploymentText = await execWithCredentials(
firebase,
"npx firebase-tools",
["hosting:channel:deploy", channelId],
projectId,
gacFilename
Expand All @@ -115,9 +111,9 @@ export async function deploy(
return deploymentResult;
}

export async function deployProductionSite(firebase, gacFilename, projectId) {
export async function deployProductionSite(gacFilename, projectId) {
const deploymentText = await execWithCredentials(
firebase,
"npx firebase-tools",
["deploy", "--only", "hosting"],
projectId,
gacFilename
Expand Down
38 changes: 27 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import {
startGroup,
} from "@actions/core";
import { context, GitHub } from "@actions/github";
import { existsSync } from "fs";
import { createCheck } from "./createCheck";
import { createGacFile } from "./createGACFile";
import { deploy, ErrorResult, deployProductionSite } from "./deploy";
import { deploy, deployProductionSite, ErrorResult } from "./deploy";
import { getChannelId } from "./getChannelId";
import { installFirebaseCLI } from "./installFirebaseCLI";
import { createCheck } from "./createCheck";
import { postOrUpdateComment } from "./postOrUpdateComment";

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

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

try {
startGroup("Setting up Firebase");
const firebase = await installFirebaseCLI();
startGroup("Verifying firebase.json exists");

if (entryPoint !== ".") {
console.log(`Changing to directory: ${entryPoint}`);
try {
process.chdir(entryPoint);
} catch (err) {
throw Error(`Error changing to directory ${entryPoint}: ${err}`);
}
}

if (existsSync("./firebase.json")) {
console.log("firebase.json file found. Continuing deploy.");
} else {
throw Error(
"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."
);
}
endGroup();

startGroup("Setting up CLI credentials");
const gacFilename = await createGacFile(googleApplicationCredentials);
console.log(
"Created a temporary file with Application Default Credentials."
);
endGroup();

if (isProductionDeploy) {
startGroup("Deploying to production site");
const deployment = await deployProductionSite(
firebase,
gacFilename,
projectId
);
const deployment = await deployProductionSite(gacFilename, projectId);
if (deployment.status === "error") {
throw Error((deployment as ErrorResult).error);
}
Expand All @@ -84,7 +100,7 @@ async function run() {
const channelId = getChannelId(configuredChannelId, context);

startGroup(`Deploying to Firebase preview channel ${channelId}`);
const deployment = await deploy(firebase, gacFilename, {
const deployment = await deploy(gacFilename, {
projectId,
expires,
channelId,
Expand Down
36 changes: 0 additions & 36 deletions src/installFirebaseCLI.ts

This file was deleted.

0 comments on commit d703bec

Please sign in to comment.