Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make firebaseServiceAccount input optional #398

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 9 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,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
lucetre marked this conversation as resolved.
Show resolved Hide resolved
}
});
} catch (e) {
Expand All @@ -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,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -93280,3 +93282,5 @@ async function run() {
}
}
run();

exports.run = run;
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
lucetre marked this conversation as resolved.
Show resolved Hide resolved
},
}
);
Expand Down
6 changes: 2 additions & 4 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 All @@ -52,7 +50,7 @@ const target = getInput("target");
const firebaseToolsVersion = getInput("firebaseToolsVersion");
const disableComment = getInput("disableComment");

async function run() {
export async function run() {
lucetre marked this conversation as resolved.
Show resolved Hide resolved
const isPullRequest = !!context.payload.pull_request;

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