mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-25 04:37:06 +00:00
feat: add post-job step for cleaning temp dir
This commit is contained in:
parent
69c00852f1
commit
f6ec85149b
3 changed files with 54 additions and 0 deletions
37
dist/cleanup.js
vendored
Normal file
37
dist/cleanup.js
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Retrieve environment variables and parameters
|
||||
const terraformCliPath = process.env.TERRAFORM_CLI_PATH;
|
||||
|
||||
// Function to recursively delete a directory
|
||||
const deleteDirectoryRecursive = function(directoryPath) {
|
||||
if (fs.existsSync(directoryPath)) {
|
||||
fs.readdirSync(directoryPath).forEach((file) => {
|
||||
const curPath = path.join(directoryPath, file);
|
||||
if (fs.lstatSync(curPath).isDirectory()) {
|
||||
// Recurse
|
||||
deleteDirectoryRecursive(curPath);
|
||||
} else {
|
||||
// Delete file
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(directoryPath);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Check if cleanup is required
|
||||
if (terraformCliPath) {
|
||||
console.log(`Cleaning up directory: ${terraformCliPath}`);
|
||||
deleteDirectoryRecursive(terraformCliPath);
|
||||
console.log('Cleanup completed.');
|
||||
} else {
|
||||
console.log('No cleanup required.');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue