Skip to content

Commit

Permalink
Merge pull request #1 from moloco/make-firebase-service-account-input…
Browse files Browse the repository at this point in the history
…-optional

feat(dup): make firebase service account input optional
  • Loading branch information
lucetre authored Dec 9, 2024
2 parents 7a831e3 + bb0822f commit dae9c15
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:

## Options

### `firebaseServiceAccount` _{string}_ (required)
### `firebaseServiceAccount` _{string}_

This is a service account JSON key. The easiest way to set it up is to run `firebase init hosting:github`. However, it can also be [created manually](./docs/service-account.md).

Expand All @@ -95,6 +95,8 @@ to prevent unintended access to your Firebase project. Set it in the "Secrets" a
of your repository settings and add it as `FIREBASE_SERVICE_ACCOUNT`:
`https://github.com/USERNAME/REPOSITORY/settings/secrets`.

If not provided, the action will attempt to use the default application credentials configured in your environment.

### `repoToken` _{string}_

Adding `repoToken: "${{secrets.GITHUB_TOKEN}}"` lets the action comment on PRs
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inputs:
required: false
firebaseServiceAccount:
description: "Firebase service account JSON"
required: true
required: false
expires:
description: "How long should a preview live? See the preview channels docs for options"
default: "7d"
Expand Down
13 changes: 8 additions & 5 deletions bin/action.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -91689,6 +91689,9 @@ module.exports.setGracefulCleanup = setGracefulCleanup;
// Set up Google Application Credentials for use by the Firebase CLI
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
async function createGacFile(googleApplicationCredentials) {
if (!googleApplicationCredentials) {
return "";
}
const tmpFile = tmp.fileSync({
postfix: ".json"
});
Expand Down Expand Up @@ -92958,7 +92961,10 @@ async function execWithCredentials(args, projectId, gacFilename, opts) {
env: {
...process.env,
FIREBASE_DEPLOY_AGENT: "action-hosting-deploy",
GOOGLE_APPLICATION_CREDENTIALS: gacFilename // the CLI will automatically authenticate with this env variable set
...(gacFilename ? {
GOOGLE_APPLICATION_CREDENTIALS: gacFilename
} // the CLI will automatically authenticate with this env variable set
: {})
}
});
} catch (e) {
Expand All @@ -92976,7 +92982,6 @@ async function execWithCredentials(args, projectId, gacFilename, opts) {
}
return deployOutputBuf.length ? deployOutputBuf[deployOutputBuf.length - 1].toString("utf-8") : ""; // output from the CLI
}

async function deployPreview(gacFilename, deployConfig) {
const {
projectId,
Expand Down Expand Up @@ -93171,9 +93176,7 @@ async function postChannelSuccessComment(github, context, result, commit) {
// Inputs defined in action.yml
const expires = core.getInput("expires");
const projectId = core.getInput("projectId");
const googleApplicationCredentials = core.getInput("firebaseServiceAccount", {
required: true
});
const googleApplicationCredentials = core.getInput("firebaseServiceAccount");
const configuredChannelId = core.getInput("channelId");
const isProductionDeploy = configuredChannelId === "live";
const token = process.env.GITHUB_TOKEN || core.getInput("repoToken");
Expand Down
5 changes: 4 additions & 1 deletion src/createGACFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import { writeSync } from "fs";
// Set up Google Application Credentials for use by the Firebase CLI
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
export async function createGacFile(googleApplicationCredentials: string) {
const tmpFile = fileSync({ postfix: ".json" });
if (!googleApplicationCredentials) {
return "";
}

const tmpFile = fileSync({ postfix: ".json" });
writeSync(tmpFile.fd, googleApplicationCredentials);

return tmpFile.name;
Expand Down
4 changes: 3 additions & 1 deletion src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ async function execWithCredentials(
env: {
...process.env,
FIREBASE_DEPLOY_AGENT: "action-hosting-deploy",
GOOGLE_APPLICATION_CREDENTIALS: gacFilename, // the CLI will automatically authenticate with this env variable set
...(gacFilename
? { GOOGLE_APPLICATION_CREDENTIALS: gacFilename } // the CLI will automatically authenticate with this env variable set
: {}),
},
}
);
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ import {
// Inputs defined in action.yml
const expires = getInput("expires");
const projectId = getInput("projectId");
const googleApplicationCredentials = getInput("firebaseServiceAccount", {
required: true,
});
const googleApplicationCredentials = getInput("firebaseServiceAccount");
const configuredChannelId = getInput("channelId");
const isProductionDeploy = configuredChannelId === "live";
const token = process.env.GITHUB_TOKEN || getInput("repoToken");
Expand Down

0 comments on commit dae9c15

Please sign in to comment.