Skip to content

Commit 75c3707

Browse files
committed
Make firebaseServiceAccount input optional
1 parent 7a831e3 commit 75c3707

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-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

bin/action.min.js

Lines changed: 9 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,9 @@ 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
9296292967
}
9296392968
});
9296492969
} catch (e) {
@@ -92976,7 +92981,6 @@ async function execWithCredentials(args, projectId, gacFilename, opts) {
9297692981
}
9297792982
return deployOutputBuf.length ? deployOutputBuf[deployOutputBuf.length - 1].toString("utf-8") : ""; // output from the CLI
9297892983
}
92979-
9298092984
async function deployPreview(gacFilename, deployConfig) {
9298192985
const {
9298292986
projectId,
@@ -93171,9 +93175,7 @@ async function postChannelSuccessComment(github, context, result, commit) {
9317193175
// Inputs defined in action.yml
9317293176
const expires = core.getInput("expires");
9317393177
const projectId = core.getInput("projectId");
93174-
const googleApplicationCredentials = core.getInput("firebaseServiceAccount", {
93175-
required: true
93176-
});
93178+
const googleApplicationCredentials = core.getInput("firebaseServiceAccount");
9317793179
const configuredChannelId = core.getInput("channelId");
9317893180
const isProductionDeploy = configuredChannelId === "live";
9317993181
const token = process.env.GITHUB_TOKEN || core.getInput("repoToken");
@@ -93280,3 +93282,5 @@ async function run() {
9328093282
}
9328193283
}
9328293284
run();
93285+
93286+
exports.run = run;

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 }
104+
: {}), // the CLI will automatically authenticate with this env variable set
103105
},
104106
}
105107
);

src/index.ts

Lines changed: 2 additions & 4 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");
@@ -52,7 +50,7 @@ const target = getInput("target");
5250
const firebaseToolsVersion = getInput("firebaseToolsVersion");
5351
const disableComment = getInput("disableComment");
5452

55-
async function run() {
53+
export async function run() {
5654
const isPullRequest = !!context.payload.pull_request;
5755

5856
let finish = (details: Object) => console.log(details);

0 commit comments

Comments
 (0)