Skip to content

Commit 1df4b3e

Browse files
committed
Unlink after the main process is finished or failed
1 parent 1f64cb0 commit 1df4b3e

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

dist/index.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -754904,7 +754904,7 @@ core.info(`Spreadsheet ID: ${spreadsheetId}`);
754904754904
core.info(`Localization Root: ${localizationRoot}`);
754905754905

754906754906
// Write the Google API key to a file
754907-
const googleApiKeyFilePath = path.join(__dirname, 'google-api-key.json');
754907+
const googleApiKeyFilePath = path.join(process.cwd(), 'google-api-key.json');
754908754908
fs.writeFileSync(googleApiKeyFilePath, JSON.stringify(googleApiKeyJson));
754909754909

754910754910
process.env.GOOGLE_APPLICATION_CREDENTIALS = googleApiKeyFilePath;
@@ -754913,21 +754913,38 @@ process.env.LOCALIZATION_ROOT = localizationRoot;
754913754913

754914754914
try {
754915754915
if (action === 'push') {
754916-
pushMain();
754916+
pushMain().then(() => {
754917+
// Clean up the Google API key file
754918+
fs.unlinkSync(googleApiKeyFilePath);
754919+
}).catch((error) => {
754920+
core.setFailed(`Action failed with error: ${error.message}`);
754921+
// Clean up the Google API key file
754922+
fs.unlinkSync(googleApiKeyFilePath);
754923+
process.exit(1);
754924+
});
754917754925
} else if (action === 'pull') {
754918-
pullMain();
754926+
pullMain().then(() => {
754927+
// Clean up the Google API key file
754928+
fs.unlinkSync(googleApiKeyFilePath);
754929+
}).catch((error) => {
754930+
core.setFailed(`Action failed with error: ${error.message}`);
754931+
// Clean up the Google API key file
754932+
fs.unlinkSync(googleApiKeyFilePath);
754933+
process.exit(1);
754934+
});
754919754935
} else {
754920754936
core.setFailed(`Unknown action: ${action}`);
754937+
// Clean up the Google API key file
754938+
fs.unlinkSync(googleApiKeyFilePath);
754921754939
process.exit(1);
754922754940
}
754923754941
} catch (error) {
754924754942
core.setFailed(`Action failed with error: ${error.message}`);
754943+
// Clean up the Google API key file
754944+
fs.unlinkSync(googleApiKeyFilePath);
754925754945
process.exit(1);
754926754946
}
754927754947

754928-
// Clean up the Google API key file
754929-
fs.unlinkSync(googleApiKeyFilePath);
754930-
754931754948
module.exports = __webpack_exports__;
754932754949
/******/ })()
754933754950
;

entrypoint.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ core.info(`Spreadsheet ID: ${spreadsheetId}`);
4141
core.info(`Localization Root: ${localizationRoot}`);
4242

4343
// Write the Google API key to a file
44-
const googleApiKeyFilePath = path.join(__dirname, 'google-api-key.json');
44+
const googleApiKeyFilePath = path.join(process.cwd(), 'google-api-key.json');
4545
fs.writeFileSync(googleApiKeyFilePath, JSON.stringify(googleApiKeyJson));
4646

4747
process.env.GOOGLE_APPLICATION_CREDENTIALS = googleApiKeyFilePath;
@@ -50,17 +50,34 @@ process.env.LOCALIZATION_ROOT = localizationRoot;
5050

5151
try {
5252
if (action === 'push') {
53-
pushMain();
53+
pushMain().then(() => {
54+
// Clean up the Google API key file
55+
fs.unlinkSync(googleApiKeyFilePath);
56+
}).catch((error) => {
57+
core.setFailed(`Action failed with error: ${error.message}`);
58+
// Clean up the Google API key file
59+
fs.unlinkSync(googleApiKeyFilePath);
60+
process.exit(1);
61+
});
5462
} else if (action === 'pull') {
55-
pullMain();
63+
pullMain().then(() => {
64+
// Clean up the Google API key file
65+
fs.unlinkSync(googleApiKeyFilePath);
66+
}).catch((error) => {
67+
core.setFailed(`Action failed with error: ${error.message}`);
68+
// Clean up the Google API key file
69+
fs.unlinkSync(googleApiKeyFilePath);
70+
process.exit(1);
71+
});
5672
} else {
5773
core.setFailed(`Unknown action: ${action}`);
74+
// Clean up the Google API key file
75+
fs.unlinkSync(googleApiKeyFilePath);
5876
process.exit(1);
5977
}
6078
} catch (error) {
6179
core.setFailed(`Action failed with error: ${error.message}`);
80+
// Clean up the Google API key file
81+
fs.unlinkSync(googleApiKeyFilePath);
6282
process.exit(1);
6383
}
64-
65-
// Clean up the Google API key file
66-
fs.unlinkSync(googleApiKeyFilePath);

0 commit comments

Comments
 (0)