-
Notifications
You must be signed in to change notification settings - Fork 88
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
[eas-cli] Enhance eas env:exec
command by enabling shell execution for commands
#2788
Conversation
Subscribed to pull request
Generated by CodeMention |
/changelog-entry bug-fix [eas-cli] Enhance eas env:exec command by enabling shell execution for commands |
7ebf630
to
7430bba
Compare
const spawnPromise = spawnAsync('bash', ['-c', command], { | ||
const spawnPromise = spawnAsync(command, [], { | ||
shell: true, |
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.
I'm not sure if I fully understand why bash -c
doesn't work on CI but it does on my local machine 🤔 Do you fully get it? Do you use Windows on CI by any chance?
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.
Do you fully get it?
Hey Szymon, unfortunately, no... I am baffled too...
Do you use Windows on CI by any chance?
Nope, I use Github actions with runs-on: ubuntu-latest
.
It's totally weird, but even the quote issue seems to be happening only on CI...
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.
LGTM. Only change is to rebase and apply the same fix to the new runCommandNonInteractiveWithEnvVarsAsync
. Otherwise, this looks like it might be what's required to fix the issues. Definitely hard to understand the "why" these are the case in CI only, but really we need to do whatever is required to get this command (eas env:exec --non-interactive
) to be a pure passthrough.
Relatedly, I almost wonder if it makes more sense to recommend using eas env:pull
and then source .env in CI? cc @szdziedzic
I believe it should also work 🤔 At least for |
…for commands * This change allows for better command handling and execution within the environment context. * Fix command execution in env:exec to handle various command formats properly.
Closing this in lieu of Will's MR here: #2811 |
Why
Initial Problem: Command Not Found in CI
The impetus for these changes originated from feedback on this pull request. The initial problem, highlighted here, was that commands passed to the
env:exec
functionality were failing to execute within the GitHub Actions environment. Specifically, the error message indicated thatnpx expo config --json --type public
could not be found.This error suggested that the command was not being executed within a context where
npx
was accessible.Second Problem: Local Terminal Failures
After resolving the initial "command not found" error in CI, a new problem surfaced. The command, which now worked in the CI environment, began to fail when executed directly from a local terminal. This was unexpected, as local terminals typically have access to
npx
.The error was due to a bash session starting without executing the code.
Third Problem: Unstripped Quotes in CI
The third issue arose when inspecting the output in the CI environment after the previous fixes. It became apparent that the command being executed was still enclosed in quotes (was trying to execute a string).
Local Output (Correct):
Remote Output (Incorrect):
The key difference was the
Running command:
line. In CI, the command was being executed as a quoted string ("npx expo config --json --type public"
), rather than a direct command (npx expo config --json --type public
), indicating that the quotes were not being parsed correctly by oclif. I am still not sure why.How
This section details the solutions implemented to address the identified problems.
Solution to "Command Not Found"
To address the initial "command not found" error in the CI environment, we implemented the suggestion found in this Stack Overflow answer. This solution involves adding
shell: true
to thespawn
command.By setting
shell: true
, the command is executed via the system shell, which has the necessary context to locate and executenpx
.Solution for Local Terminal Failures
The second issue, the local terminal failures, was resolved by opting to execute the command without using
bash -c
. We instead adopted the approach recommended by this Stack Overflow answer, which advocates for a more direct approach. This avoids the need to shell out tobash -c
and reduces the chances of issues with command parsing, especially when dealing with arguments containing spaces or quotes.Solution for Unstripped Quotes
Finally, to address the issue of unstripped quotes in the CI environment, a basic sanitization method was added. This method is designed to remove quotes from the command string prior to execution, ensuring that the command is executed correctly as intended. It's important to note that this sanitization is intended to be a preliminary fix and may require further refinement for broader applicability.
Test Plan
This section outlines the steps taken to verify the correctness of the changes.
Verification Steps
GitHub CI Testing: The primary goal was to ensure the command now executes successfully within the GitHub CI environment, which was accomplished.
Local Command Testing: The following commands were executed locally to ensure the changes did not break existing functionality and worked as expected.
This test confirms the primary command and ensures it now works locally with environment variables
This test confirms that commands with inner single quotes now works
These tests were conducted to ensure the fixes addressed the issues and did not introduce new problems.