Skip to content

Commit 53719cd

Browse files
committed
chore: cleanup temp file at the end of the action
1 parent cb84c39 commit 53719cd

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/createGACFile.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717
import { fileSync } from "tmp";
1818
import { writeSync, existsSync } from "fs";
1919

20-
// Set up Google Application Credentials for use by the Firebase CLI
21-
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
22-
export async function createGacFile(googleApplicationCredentials: string) {
20+
// creates file with GAC info if parameter is not already a path to a file
21+
// NOTE: no validation of the credential information is performed
22+
export async function createGacFile(gacInfo: string) {
2323
try {
24-
if (existsSync(googleApplicationCredentials)) {
25-
return googleApplicationCredentials;
24+
if (existsSync(gacInfo)) {
25+
return gacInfo;
2626
}
2727
}
2828
catch (e) {
29-
console.log("debug: failed checking file existence with error %O", e);
30-
// googleApplicationCredentials is not a path to a file
29+
console.warn("unexpected error while validing GAC info. Interpreting provided info as credentials data.");
3130
}
3231
const tmpFile = fileSync({ postfix: ".json" });
33-
writeSync(tmpFile.fd, googleApplicationCredentials);
32+
writeSync(tmpFile.fd, gacInfo);
3433
return tmpFile.name;
3534
}

src/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
startGroup,
2323
} from "@actions/core";
2424
import { context, getOctokit } from "@actions/github";
25-
import { existsSync } from "fs";
25+
import { existsSync, unlinkSync } from "fs";
2626
import { createGacFile } from "./createGACFile";
2727
import {
2828
deployPreview,
@@ -52,7 +52,7 @@ const disableComment = getInput("disableComment");
5252

5353
async function run() {
5454
try {
55-
startGroup("Verifying firebase.json exists");
55+
startGroup("Verifying setup parameters");
5656

5757
if (entryPoint !== ".") {
5858
console.log(`Changing to directory: ${entryPoint}`);
@@ -62,21 +62,15 @@ async function run() {
6262
throw Error(`Error changing to directory ${entryPoint}: ${err}`);
6363
}
6464
}
65-
6665
if (existsSync("./firebase.json")) {
6766
console.log("firebase.json file found. Continuing deploy.");
6867
} else {
6968
console.warn("firebase.json file not found. If your firebase.json file is not in the root of your repo, edit the entryPoint option of this GitHub action.");
7069
}
71-
endGroup();
72-
73-
startGroup("Setting up CLI credentials");
74-
console.log("validating passed credentials: %s", googleApplicationCredentials);
7570
const gacFilename = await createGacFile(googleApplicationCredentials);
76-
console.log("generated credentials: %s", gacFilename)
7771
if (gacFilename !== googleApplicationCredentials) {
7872
console.log(
79-
"Created a temporary file with Application Default Credentials."
73+
"Created a temporary file with Google Application Credentials."
8074
);
8175
}
8276
endGroup();
@@ -91,6 +85,11 @@ async function run() {
9185
await deployToPreviewChannel(gacFilename, channelId);
9286
endGroup();
9387
}
88+
89+
// cleanup
90+
if (gacFilename !== googleApplicationCredentials) {
91+
unlinkSync(gacFilename);
92+
}
9493
} catch (e) {
9594
setFailed(e.message);
9695
}

0 commit comments

Comments
 (0)