[eas-cli] Enhance eas env:exec
command by enabling shell execution for commands
#2788
+10
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.