-
Notifications
You must be signed in to change notification settings - Fork 289
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
Support bash hooks on windows #636
Conversation
Nice!! |
db1fa1e
to
692cd94
Compare
Rad! Would this mean our plugins "just work" for the most part then? |
Yeah, hopefully :) |
# Executing "C:\Users\ContainerAdministrator\AppData\Local\Temp\buildkite-agent-bootstrap-hook-runner-066954642"
--
| > C:\Program Files\Git\usr\bin\bash.exe -c C:/Users/ContainerAdministrator/AppData/Local/Temp/buildkite-agent-bootstrap-hook-runner-066954642
| This is an example of a pre-command hook from .buildkite/hooks/pre-command |
I'm struggling with this error:
Any ideas @keithpitt? |
Ah, right. It seems to be mistakenly detecting that there is a STDIN. |
bootstrap/bootstrap.go
Outdated
func (b *Bootstrap) findHookFile(hookDir string, name string) (string, error) { | ||
if runtime.GOOS == "windows" { | ||
// check for windows types first | ||
if p, err := shell.LookPath(name, hookDir, ".BAT;.CMD;.EXE"); err == 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.
Unfortunately we can't support powershell hooks yet, as need to write a environment hook magic thing for them.
bootstrap/bootstrap.go
Outdated
func dirForAgentName(agentName string) string { | ||
badCharsPattern := regexp.MustCompile("[[:^alnum:]]") | ||
return badCharsPattern.ReplaceAllString(agentName, "-") | ||
} | ||
|
||
func buildkiteAgentBinary() string { |
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 replaces hardcoded buildkite-agent
b9f5db1
to
820ba8d
Compare
Replaced with golang.org/x/crypto/ssh/terminal which seems to work better.
820ba8d
to
33697a1
Compare
d35f0e8
to
59cdbc9
Compare
@@ -108,7 +108,7 @@ var AnnotateCommand = cli.Command{ | |||
|
|||
if cfg.Body != "" { | |||
body = cfg.Body | |||
} else if stdin.IsPipe() { | |||
} else if terminal.IsTerminal(int(os.Stdin.Fd())) { |
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.
Ah, is this the cross platform way to do it?
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.
Yup, or at least it let's it be someone else's problem. Our implementation didn't seem to work on Windows, despite it saying it did.
@@ -97,12 +105,11 @@ func newHookScriptWrapper(hookPath string) (*hookScriptWrapper, error) { | |||
"SET > \"" + h.afterEnvFile.Name() + "\"\n" + | |||
"EXIT %" + hookExitStatusEnv + "%" | |||
} else { | |||
script = "#!/bin/bash\n" + |
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 ditched this shebang, we always invoke these scripts with an interpreter and it was causing problems on windows bash.
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.
Everything looks good to me 🚀
@keithpitt had a neat suggestion for how to support plugin hooks on windows, which was to use the bash.exe bundled with Git for Windows. This generalizes that and searches for the best option under windows, either batch, powershell or if neither of those exist it uses the bash/sh options.