Skip to content

Commit dae9c15

Browse files
authored
Merge pull request #1 from moloco/make-firebase-service-account-input-optional
feat(dup): make firebase service account input optional
2 parents 7a831e3 + bb0822f commit dae9c15

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585

8686
## Options
8787

88-
### `firebaseServiceAccount` _{string}_ (required)
88+
### `firebaseServiceAccount` _{string}_
8989

9090
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).
9191

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

98+
If not provided, the action will attempt to use the default application credentials configured in your environment.
99+
98100
### `repoToken` _{string}_
99101

100102
Adding `repoToken: "${{secrets.GITHUB_TOKEN}}"` lets the action comment on PRs

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ inputs:
2727
required: false
2828
firebaseServiceAccount:
2929
description: "Firebase service account JSON"
30-
required: true
30+
required: false
3131
expires:
3232
description: "How long should a preview live? See the preview channels docs for options"
3333
default: "7d"

bin/action.min.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91689,6 +91689,9 @@ module.exports.setGracefulCleanup = setGracefulCleanup;
9168991689
// Set up Google Application Credentials for use by the Firebase CLI
9169091690
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
9169191691
async function createGacFile(googleApplicationCredentials) {
91692+
if (!googleApplicationCredentials) {
91693+
return "";
91694+
}
9169291695
const tmpFile = tmp.fileSync({
9169391696
postfix: ".json"
9169491697
});
@@ -92958,7 +92961,10 @@ async function execWithCredentials(args, projectId, gacFilename, opts) {
9295892961
env: {
9295992962
...process.env,
9296092963
FIREBASE_DEPLOY_AGENT: "action-hosting-deploy",
92961-
GOOGLE_APPLICATION_CREDENTIALS: gacFilename // the CLI will automatically authenticate with this env variable set
92964+
...(gacFilename ? {
92965+
GOOGLE_APPLICATION_CREDENTIALS: gacFilename
92966+
} // the CLI will automatically authenticate with this env variable set
92967+
: {})
9296292968
}
9296392969
});
9296492970
} catch (e) {
@@ -92976,7 +92982,6 @@ async function execWithCredentials(args, projectId, gacFilename, opts) {
9297692982
}
9297792983
return deployOutputBuf.length ? deployOutputBuf[deployOutputBuf.length - 1].toString("utf-8") : ""; // output from the CLI
9297892984
}
92979-
9298092985
async function deployPreview(gacFilename, deployConfig) {
9298192986
const {
9298292987
projectId,
@@ -93171,9 +93176,7 @@ async function postChannelSuccessComment(github, context, result, commit) {
9317193176
// Inputs defined in action.yml
9317293177
const expires = core.getInput("expires");
9317393178
const projectId = core.getInput("projectId");
93174-
const googleApplicationCredentials = core.getInput("firebaseServiceAccount", {
93175-
required: true
93176-
});
93179+
const googleApplicationCredentials = core.getInput("firebaseServiceAccount");
9317793180
const configuredChannelId = core.getInput("channelId");
9317893181
const isProductionDeploy = configuredChannelId === "live";
9317993182
const token = process.env.GITHUB_TOKEN || core.getInput("repoToken");

src/createGACFile.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ import { writeSync } from "fs";
2020
// Set up Google Application Credentials for use by the Firebase CLI
2121
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
2222
export async function createGacFile(googleApplicationCredentials: string) {
23-
const tmpFile = fileSync({ postfix: ".json" });
23+
if (!googleApplicationCredentials) {
24+
return "";
25+
}
2426

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

2730
return tmpFile.name;

src/deploy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ async function execWithCredentials(
9999
env: {
100100
...process.env,
101101
FIREBASE_DEPLOY_AGENT: "action-hosting-deploy",
102-
GOOGLE_APPLICATION_CREDENTIALS: gacFilename, // the CLI will automatically authenticate with this env variable set
102+
...(gacFilename
103+
? { GOOGLE_APPLICATION_CREDENTIALS: gacFilename } // the CLI will automatically authenticate with this env variable set
104+
: {}),
103105
},
104106
}
105107
);

src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ import {
4040
// Inputs defined in action.yml
4141
const expires = getInput("expires");
4242
const projectId = getInput("projectId");
43-
const googleApplicationCredentials = getInput("firebaseServiceAccount", {
44-
required: true,
45-
});
43+
const googleApplicationCredentials = getInput("firebaseServiceAccount");
4644
const configuredChannelId = getInput("channelId");
4745
const isProductionDeploy = configuredChannelId === "live";
4846
const token = process.env.GITHUB_TOKEN || getInput("repoToken");

0 commit comments

Comments
 (0)