Skip to content

Commit 5121ca6

Browse files
committed
chore: cleanup temp file at the end of the action
1 parent bb7817d commit 5121ca6

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,
@@ -51,7 +51,7 @@ const firebaseToolsVersion = getInput("firebaseToolsVersion");
5151

5252
async function run() {
5353
try {
54-
startGroup("Verifying firebase.json exists");
54+
startGroup("Verifying setup parameters");
5555

5656
if (entryPoint !== ".") {
5757
console.log(`Changing to directory: ${entryPoint}`);
@@ -61,21 +61,15 @@ async function run() {
6161
throw Error(`Error changing to directory ${entryPoint}: ${err}`);
6262
}
6363
}
64-
6564
if (existsSync("./firebase.json")) {
6665
console.log("firebase.json file found. Continuing deploy.");
6766
} else {
6867
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.");
6968
}
70-
endGroup();
71-
72-
startGroup("Setting up CLI credentials");
73-
console.log("validating passed credentials: %s", googleApplicationCredentials);
7469
const gacFilename = await createGacFile(googleApplicationCredentials);
75-
console.log("generated credentials: %s", gacFilename)
7670
if (gacFilename !== googleApplicationCredentials) {
7771
console.log(
78-
"Created a temporary file with Application Default Credentials."
72+
"Created a temporary file with Google Application Credentials."
7973
);
8074
}
8175
endGroup();
@@ -90,6 +84,11 @@ async function run() {
9084
await deployToPreviewChannel(gacFilename, channelId);
9185
endGroup();
9286
}
87+
88+
// cleanup
89+
if (gacFilename !== googleApplicationCredentials) {
90+
unlinkSync(gacFilename);
91+
}
9392
} catch (e) {
9493
setFailed(e.message);
9594
}

0 commit comments

Comments
 (0)