-
Notifications
You must be signed in to change notification settings - Fork 3
restore process.env after exec action with side-effects #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request addresses the side effects caused by running an action by ensuring that process.env and the current working directory are restored after the action executes.
- Captures process.env before any changes by cloning it.
- Stores the original working directory to restore it later.
- Restores both process.env and cwd after the action function is executed.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #153 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 642 647 +5
Branches 132 132
=========================================
+ Hits 642 647 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
shazron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea from Copilot about the try-finally block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that any modifications to the process environment and working directory during action invocation are reverted afterward to prevent side-effects.
- Snapshot
process.envandcwdbefore running the action - Wrap action execution in
try/finallyto restore environment and directory - Added comments to clarify restore logic
Comments suppressed due to low confidence (1)
src/lib/run-dev.js:355
- [nitpick] The variable name
preCallEnvis ambiguous; consider renaming it tooriginalEnvSnapshotorenvBackupfor clarity.
const preCallEnv = cloneDeep(process.env)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that the environment variables and working directory are reset after executing an action that may have side-effects.
- Capture a snapshot of
process.envand current working directory before action execution - Inject an OpenWhisk‐style activation ID into
process.env - Restore
process.envand CWD in afinallyblock after the action runs
Comments suppressed due to low confidence (1)
src/lib/run-dev.js:353
- There are no tests covering the restoration of
process.envand CWD after an action; consider adding unit tests that change env vars and directory during an action and assert they are reset.
// if we run an action, we will restore the process.env after the call
| } | ||
| } finally { | ||
| logger.debug('restoring process.env and cwd') | ||
| process.env = preCallEnv // restore the environment variables |
Copilot
AI
Jun 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reassigning process.env can break references elsewhere; instead clear the existing process.env and reassign properties, e.g. delete all keys then Object.assign(process.env, preCallEnv), to preserve the env object identity.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: