feat: Add cleanup option for exported .env file and refactor post-processing logic#28
feat: Add cleanup option for exported .env file and refactor post-processing logic#28mertemr wants to merge 1 commit intoInfisical:mainfrom
Conversation
…cessing logic (cherry picked from commit 789b609)
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new cleanup feature that automatically deletes exported .env files after the GitHub Action workflow completes. The implementation introduces a post-execution script that runs after the main action finishes.
Key changes:
- Adds a new
cleaninput parameter (defaults totrue) to control whether exported .env files should be deleted - Implements a post-processing script (
post.ts) that handles file cleanup - Updates the build configuration to compile both main and post scripts
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/post.ts | New post-processing script that handles cleanup of exported .env files based on the clean input parameter |
| rollup.config.js | Refactored from single build config to array of configs to support building both main and post scripts |
| action.yaml | Added new clean input parameter and configured the post-processing hook to run dist/post.cjs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try { | ||
| const filePath = `${process.env.GITHUB_WORKSPACE}${fileOutputPath}`; | ||
|
|
||
| try { | ||
| await fs.access(filePath); | ||
| await fs.unlink(filePath); | ||
| core.info(`Cleaned up exported file at ${filePath}`); | ||
| } catch (accessErr) { | ||
| core.debug(`File not found at ${filePath}, skipping cleanup`); | ||
| } | ||
| } catch (err) { | ||
| core.warning(`Failed to clean up file: ${(err as Error)?.message}`); |
There was a problem hiding this comment.
These nested try-catch blocks are unnecessary and make the code harder to read. The inner try-catch (lines 13-19) already handles file access errors gracefully, so the outer try-catch (lines 10-22) that wraps it provides no additional value. Consider removing the outer try-catch block and keeping only the inner one.
| try { | |
| const filePath = `${process.env.GITHUB_WORKSPACE}${fileOutputPath}`; | |
| try { | |
| await fs.access(filePath); | |
| await fs.unlink(filePath); | |
| core.info(`Cleaned up exported file at ${filePath}`); | |
| } catch (accessErr) { | |
| core.debug(`File not found at ${filePath}, skipping cleanup`); | |
| } | |
| } catch (err) { | |
| core.warning(`Failed to clean up file: ${(err as Error)?.message}`); | |
| const filePath = `${process.env.GITHUB_WORKSPACE}${fileOutputPath}`; | |
| try { | |
| await fs.access(filePath); | |
| await fs.unlink(filePath); | |
| core.info(`Cleaned up exported file at ${filePath}`); | |
| } catch (accessErr) { | |
| core.debug(`File not found at ${filePath}, skipping cleanup`); |
| if (shouldClean) { | ||
| try { | ||
| const filePath = `${process.env.GITHUB_WORKSPACE}${fileOutputPath}`; | ||
|
|
||
| try { | ||
| await fs.access(filePath); | ||
| await fs.unlink(filePath); | ||
| core.info(`Cleaned up exported file at ${filePath}`); | ||
| } catch (accessErr) { | ||
| core.debug(`File not found at ${filePath}, skipping cleanup`); | ||
| } | ||
| } catch (err) { | ||
| core.warning(`Failed to clean up file: ${(err as Error)?.message}`); | ||
| } | ||
| } else { | ||
| core.info("Cleanup is disabled, keeping exported file"); | ||
| } |
There was a problem hiding this comment.
The cleanup logic should only execute when export-type is set to "file". Currently, the post script attempts to clean up the file regardless of the export type. When export-type is "env", no file is created (secrets are only set as environment variables in index.ts), so attempting cleanup is unnecessary and could log misleading debug messages. Add a check for export-type before attempting cleanup:
const exportType = core.getInput("export-type");
if (shouldClean && exportType === "file") {
// cleanup logic
}
(cherry picked from commit 789b609)