-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Shell command works for complex command #1067
Conversation
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
A positive side effect of this pullrquest is that it allow us to move custom scripts directly in the manifest. This is a short term workaround for the chicken and egg problem where we write an Updatecli manifest with a script to update a target repository but the manifest can't work because the target repository do not have yet the script... |
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.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.
The unit test does not work on macOS (darwin):
--- FAIL: TestShell_New (0.00s)
--- FAIL: TestShell_New/Inherit_PATH_environment_variable (0.00s)
/Users/dadou/workspace/updatecli/updatecli/pkg/plugins/resources/shell/main_test.go:154:
Error Trace: /Users/dadou/workspace/updatecli/updatecli/pkg/plugins/resources/shell/main_test.go:154
Error: Not equal:
expected: &shell.Shell{executor:(*shell.nativeCommandExecutor)(0x1005bd660), spec:shell.Spec{Command:"echo Hello", Environments:shell.Environments{shell.Environment{Name:"PATH", Value:""}}, Shell:""}, result:shell.commandResult{ExitCode:0, Stdout:"", Stderr:"", Cmd:""}, interpreter:"/bin/sh"}
actual : &shell.Shell{executor:(*shell.nativeCommandExecutor)(0x1005bd660), spec:shell.Spec{Command:"echo Hello", Environments:shell.Environments{shell.Environment{Name:"PATH", Value:""}}, Shell:""}, result:shell.commandResult{ExitCode:0, Stdout:"", Stderr:"", Cmd:""}, interpreter:"/bin/bash"}
Diff:
--- Expected
+++ Actual
@@ -19,3 +19,3 @@
},
- interpreter: (string) (len=7) "/bin/sh"
+ interpreter: (string) (len=9) "/bin/bash"
})
Test: TestShell_New/Inherit_PATH_environment_variable
=> This PR is legit but the code (and tests) in its current state is too fragile.
First superficial review:
- I would introduce an
ExecuteScript()
method on thence
receiver instead of adding more code in the currentExecuteCommand()
. Remember the UNIX adage: 1 method should do 1 thing but do it well. - I would use
/bin/sh
for any "non Windows" OS: simpler to implement (2 conditional branches instead of 4 with theswitch/case
you have today)
Good suggestion, I'll try to find some time to improve this
I have fine with this suggestion, the shell can be overridden anyway so 🤷🏾
If I manage to install gcc on a Windows I would also like to test to see how it behave there |
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
While running some tests, I noticed that result are not what I would expect:
But I am planning to fix this behavior in #1071 |
@dduportal I think I addressed your concerned. If the PR is in a acceptable state for you, then I'll merge it so I can continue working on #1071 |
I identify a few regression |
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Worth mentioning.
This allows us to debug the generated file |
I did some testing on a windows machine and it seems to work as expected. |
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.
Still failing with macOS. i'm pasting the output here of the condition_test.go
file without further diagnostic (I'm digging but I want to share the feedback as soon as posible):
Running tool: /Users/dadou/.asdf/shims/go test -timeout 30s -run ^(TestShell_Condition|TestShell_ConditionFromSCM)$ github.com/updatecli/updatecli/pkg/plugins/resources/shell
time="2023-01-16T14:57:32+01:00" level=info msg="The shell 🐚 command \"\" ran successfully with the following output:\n----\nHello\n----"
time="2023-01-16T14:57:32+01:00" level=info msg="The shell 🐚 command \"\" exited on error (exit code 1) with the following output:\n----\n----\n\ncommand stderr output was:\n----\nls: 1.2.3: No such file or directory\n----"
time="2023-01-16T14:57:32+01:00" level=info msg="The shell 🐚 command \"\" ran successfully with the following output:\n----\nHello\n----"
--- FAIL: TestShell_ConditionFromSCM (0.00s)
--- FAIL: TestShell_ConditionFromSCM/Successful_Condition_in_existing_SCM (0.00s)
/Users/dadou/workspace/updatecli/updatecli/pkg/plugins/resources/shell/condition_test.go:134:
Error Trace: /Users/dadou/workspace/updatecli/updatecli/pkg/plugins/resources/shell/condition_test.go:134
Error: Not equal:
expected: "/bin/bash /tmp/updatecli/bin/9adca274a8e9298dd9060a3bd68649e74950b670b9bc4efe47443e1843091683.sh"
actual : "/bin/bash /var/folders/2s/09szbrgn22l2tcvxz1_k34g40000gn/T/updatecli/bin/9adca274a8e9298dd9060a3bd68649e74950b670b9bc4efe47443e1843091683.sh"
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-/bin/bash /tmp/updatecli/bin/9adca274a8e9298dd9060a3bd68649e74950b670b9bc4efe47443e1843091683.sh
+/bin/bash /var/folders/2s/09szbrgn22l2tcvxz1_k34g40000gn/T/updatecli/bin/9adca274a8e9298dd9060a3bd68649e74950b670b9bc4efe47443e1843091683.sh
Test: TestShell_ConditionFromSCM/Successful_Condition_in_existing_SCM
FAIL
FAIL github.com/updatecli/updatecli/pkg/plugins/resources/shell 0.357s
FAIL
Co-authored-by: Damien Duportal <damien.duportal@gmail.com>
Signed-off-by: Olblak <me@olblak.com>
@dduportal would you have some time to give it another try? Tests should pass now |
I am going to merge this one as it's a requirement for a few open PR |
Fix #942
As suggested in issue #942, I am copying the command to a file and then run /bin/sh on that file.
This pullrequest introduces a new temporary directory named /tmp/updatecli/bin used to store shell scripts created by Updatecli.
when the shell resource is triggered, we generated a file where the name is the hash of the command
Manifest used during testing
which generate the file /tmp/updatecli/bin/223f8bfb9f09e60649fe1dd60e59fad7
Test
To test this pull request, you can run the following commands:
Additional Information
By default the script is not deleted unless the updatecli uses the flag
--clean=true
such asupdatecli diff --config manifest.yaml --clean=true
Tradeoff
Potential improvement
A potential improvement would be to specify the shell command to use. By default
/bin/sh
sounds the best minimal one.