Properly clean up tmp files

This commit is contained in:
Jessica Rudder
2025-08-12 14:31:05 -07:00
parent 3ba8e1b39d
commit a2fd223fcf
4 changed files with 85 additions and 5 deletions
Generated Vendored
+16 -2
View File
@@ -52596,6 +52596,9 @@ function isPromptYamlFile(filePath) {
* @returns Resolves when the action is complete.
*/
async function run() {
let responseFile = null;
// Set up graceful cleanup for temporary files on process exit
tmpExports.setGracefulCleanup();
try {
const promptFilePath = coreExports.getInput('prompt-file');
const inputVariables = coreExports.getInput('input');
@@ -52648,10 +52651,9 @@ async function run() {
}
coreExports.setOutput('response', modelResponse || '');
// Create a secure temporary file instead of using the temp directory directly
const responseFile = tmpExports.fileSync({
responseFile = tmpExports.fileSync({
prefix: 'modelResponse-',
postfix: '.txt',
keep: true, // Keep the file so the action can read it
});
coreExports.setOutput('response-file', responseFile.name);
if (modelResponse && modelResponse !== '') {
@@ -52668,6 +52670,18 @@ async function run() {
// Force exit to prevent hanging on open connections
process.exit(1);
}
finally {
// Explicit cleanup of temporary file if it was created
if (responseFile) {
try {
responseFile.removeCallback();
}
catch (cleanupError) {
// Log cleanup errors but don't fail the action
coreExports.warning(`Failed to cleanup temporary file: ${cleanupError}`);
}
}
}
// Force exit to prevent hanging on open connections
process.exit(0);
}
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long