From 75c3707e988d951e159d6d8f5ee7e7bc5c0359ae Mon Sep 17 00:00:00 2001 From: Sangjun Son Date: Fri, 6 Dec 2024 18:57:29 +0900 Subject: [PATCH] Make firebaseServiceAccount input optional --- README.md | 4 +++- bin/action.min.js | 14 +++++++++----- src/createGACFile.ts | 5 ++++- src/deploy.ts | 4 +++- src/index.ts | 6 ++---- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c755c437..c98bcd37 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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 diff --git a/bin/action.min.js b/bin/action.min.js index 8324beb8..741d4e27 100644 --- a/bin/action.min.js +++ b/bin/action.min.js @@ -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" }); @@ -92958,7 +92961,9 @@ 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) { @@ -92976,7 +92981,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, @@ -93171,9 +93175,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"); @@ -93280,3 +93282,5 @@ async function run() { } } run(); + +exports.run = run; diff --git a/src/createGACFile.ts b/src/createGACFile.ts index b559fb30..92924255 100644 --- a/src/createGACFile.ts +++ b/src/createGACFile.ts @@ -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; diff --git a/src/deploy.ts b/src/deploy.ts index 76c61858..464f5b49 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -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 }, } ); diff --git a/src/index.ts b/src/index.ts index fe34502b..6a1aaa93 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"); @@ -52,7 +50,7 @@ const target = getInput("target"); const firebaseToolsVersion = getInput("firebaseToolsVersion"); const disableComment = getInput("disableComment"); -async function run() { +export async function run() { const isPullRequest = !!context.payload.pull_request; let finish = (details: Object) => console.log(details);