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
feat: allow global host commands to be run from anywhere, for #4416 #5702
feat: allow global host commands to be run from anywhere, for #4416 #5702
Conversation
Download the artifacts for this pull request:
See Testing a PR |
48fe5a7
to
7304e4a
Compare
if runtime.GOOS == "windows" { | ||
windowsBashPath := util.FindBashPath() | ||
if windowsBashPath == "" { | ||
fmt.Println("Unable to find bash.exe in PATH, not loading custom commands") | ||
return nil | ||
} | ||
} |
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.
This was further down, inside a loop for some reason - but it just needs to be run once and should be run early to avoid unnecessary processing
// addCustomCommandsFromDir adds the custom commands from inside a given directory | ||
func addCustomCommandsFromDir(rootCmd *cobra.Command, app *ddevapp.DdevApp, serviceDirOnHost string, commandFiles []string, isGlobalSet bool, commandsAdded map[string]int) error { |
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.
Most of the code in this function used to live directly in addCustomCommands()
- but we need to be able to run it with different input depending on whether we're in a project directory or not and the easiest way to handle that seems to be refactoring this into its own function.
} else { | ||
_ = os.Setenv("DDEV_PROJECT_STATUS", "") | ||
} |
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.
Not sure if we need this or not? I figured it's safer to have it and not need it, rather than not have it and find out later we do need it.
Docs CI failure seems to be for an unrelated broken link |
Wow!
You can use
Restarted failed jobs. |
7304e4a
to
feaedb5
Compare
I've added some tests and updated the "Automated Testing Overview" section of the PR description. |
I tried to test this on gitpod using https://gitpod.io/#https://github.com/ddev/ddev/pulls/5702 but when I ran Anyway, that was more trying that out for fun - I did run this locally and it worked as expected. |
Ah, the problem is your URL had |
Per #5702 (comment) we had a typo in the URL link for a PR, this fixes it
feaedb5
to
7ed5340
Compare
I've renamed the This is a more immediately clear and better descriptive name for what this annotation does, and leaves its usage open to the behaviour described in #4416 (comment) in the future. Also ran this with the correct devpod URL this time (thanks Randy) and it works as expected. |
Buildkite ci failure looks unrelated |
I invited you to buildkite so you can restart tests (and more easily examine them), also to ddev team on GitHub. I think that lets you restart GitHub tests. |
Awesome, thank you! 💙 |
This should be good to go |
I will review this later this week. |
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.
This is a great addition to DDEV!
Works as expected, thank you @GuySartorelli.
The Issue
Custom global host commands currently only be run inside a project directory - even if they don't need a project in order to do their stuff.
A great example of this is
ddev self-upgrade
which should be able to run from anywhere - but currently it has to be run from inside a project directory.How This PR Solves The Issue
This PR adds a new
CanRunGlobally
annotation. If custom global host commands set this annotation totrue
, they will be added to the cobra command set, and can be run from anywhere, even outside project directories.Manual Testing Instructions
ddev help
- you should see theself-upgrade
command there.ddev self-upgrade
- it should work from anywhere, even outside a project directory.## CanRunGlobally: true
to a custom global host command, then perform the first two steps again, but with your custom command rather thanself-upgrade
.Automated Testing Overview
I've added checks for the following the following:
CanRunGlobally: true
shows and can be run from arbitrary working directoriesCanRunGlobally: true
still shows and can be run from inside a project directoryCanRunGlobally: true
do not show from arbitrary working directoriesThis is my first time really looking at how to add tests and I've gone in with a fairly light touch - if you want more test coverage I'll be happy to add it.
Related Issue Link(s)
NOTE: This PR will be one of several iterative features that together will fulfil the requirements set forth in that issue. The issue should not be closed until all of its requirements are fulfilled.
Release/Deployment Notes
Anyone who maintains a DDEV extension or who has some custom commands in projects they manage should review their custom global host commands, and add the new
CanRunGlobally
annotation to any commands that should be allowed to run even outside of project directories.