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
[issue-2170] Modified runLocally function to accept closure #2172
Conversation
As noted in the issue deployphp#2170, the logic in the recipe/check_remote.php would try to get the binary path of local and remote git executable. However, due to specific implementation, the get('bin/git') would have been called twice in the context of remote host, instead of invoking it once on remote and once on local machine. The runLocally function has thus been reworked, to accept Closure, which will be invoked in the context of the localhost machine. Once a Closure has been passed, the function will push the Localhost to the Context, invoke the closure, store the stdout (if available), pop the Localhost from the Context and finally return the stdout. For compatibility reasons, the function also accepts the string argument, however it is wrapped in a closure and once again passed to the runLocally function. The recipe/check_remote.php file has been reworked, to utilize the Closure, to make sure that the get('bin/git') is being called in the Localhost context.
aa8640a
to
f0e9162
Compare
Added test cases for runLocally invocations with Closure being passed as a first argument.
This is an interesting idea, but it repeats task functionality. Also if check_remote will be running on a few hosts run part of code will be executed multiple times. task('deploy:check_local', function () {
$remoteLs = run(sprintf("%s ls-remote $opt $repository $ref", get('bin/git')));
})->local(); |
I'm not sure whether it repeats the functionality. It can achieve the same thing, but IMO represents different intentions:
With
Technically, we could add a check that would prevent multiple calls, but I would concentrate on that once we discover that performance really is an issue.
To me it looks like it splits the task('deploy:check_version', [
'deploy:check_local', // this is executed only once on local machine, sets the 'targetRevision` value
'deploy:check_remote', // this has to grab a value set by the `check_local` and compare it against remote version
]); Not sure if such separation is desired. |
I like the idea in general, but for me, it seems a more complex thing to add. We have local tasks and on host functionality. on(localhost(), function () {
$remoteLs = run(sprintf("%s ls-remote $opt $repository $ref", get('bin/git')));
}); |
Looks nice. Do you want me to create a new PR with |
Yes, it will be cool. Also, check if this functionality actually work)) |
As noted in the issue #2170, the logic in the
recipe/check_remote.php
would try to get the binary path of local and remote git executable.However, due to specific implementation, the
get('bin/git')
would have been called twice in the context of remote host, instead of invoking it once on remote and once on local machine.The
runLocally
function has thus been reworked, to accept Closure, which will be invoked in the context of the localhost machine.Once a Closure has been passed, the function will push the Localhost to the Context, invoke the closure, store the stdout (if available), pop the Localhost from the Context and finally return the stdout.
For compatibility reasons, the function also accepts the string argument, however it is wrapped in a closure and once again passed to the
runLocally
function.The
recipe/check_remote.php
file has been reworked, to utilize the Closure, to make sure that theget('bin/git')
is being called in the Localhost context.