-
Notifications
You must be signed in to change notification settings - Fork 302
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
Experiment: Polyglot hooks #2040
Changes from all commits
ace3fbb
d8b5c36
af4656f
8879ad5
fa98c76
775cb16
6634945
aee1191
1a5f050
251b72f
3971f6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
FROM golang:1.20.4@sha256:6876eff5b20336c5c2896b0c3055f3258bdeba7aa38bbdabcb5a4abb5cdd39c7 | ||
COPY build/ssh.conf /etc/ssh/ssh_config.d/ | ||
RUN go install github.com/google/go-licenses@latest | ||
|
||
# Ruby used for polyglot hook integration tests | ||
RUN apt update && apt install -y ruby |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/buildkite/agent/v3/jobapi" | ||
) | ||
|
||
// This file gets built and commited to this repo, then used as part of the hooks integration test to ensure that the | ||
// bootstrap can run binary hooks | ||
func main() { | ||
c, err := jobapi.NewDefaultClient(context.TODO()) | ||
if err != nil { | ||
log.Fatalf("error: %v", fmt.Errorf("creating job api client: %w", err)) | ||
} | ||
|
||
_, err = c.EnvUpdate(context.TODO(), &jobapi.EnvUpdateRequest{ | ||
Env: map[string]string{ | ||
"OCEAN": "Pacífico", | ||
"MOUNTAIN": "chimborazo", | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good thinking to test the jobapi as well 🧠 |
||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("error: %v", fmt.Errorf("updating env: %w", err)) | ||
} | ||
|
||
fmt.Println("hi there from golang 🌊") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,6 +282,30 @@ func (s *Shell) Run(ctx context.Context, command string, arg ...string) error { | |
return s.RunWithoutPrompt(ctx, command, arg...) | ||
} | ||
|
||
func (s *Shell) RunWithEnv(ctx context.Context, environ *env.Environment, command string, arg ...string) error { | ||
formatted := process.FormatCommand(command, arg) | ||
if s.stdin == nil { | ||
s.Promptf("%s", formatted) | ||
} else { | ||
// bash-syntax-compatible indication that input is coming from somewhere | ||
s.Promptf("%s < /dev/stdin", formatted) | ||
} | ||
|
||
cmd, err := s.buildCommand(command, arg...) | ||
if err != nil { | ||
s.Errorf("Error building command: %v", err) | ||
return err | ||
} | ||
|
||
cmd.Env = append(cmd.Env, environ.ToSlice()...) | ||
|
||
return s.executeCommand(ctx, cmd, s.Writer, executeFlags{ | ||
Stdout: true, | ||
Stderr: true, | ||
PTY: s.PTY, | ||
}) | ||
} | ||
|
||
Comment on lines
+285
to
+308
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function is just the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes please |
||
// RunWithoutPrompt runs a command, writes stdout and err to the logger, | ||
// and returns an error if it fails. It doesn't show a prompt. | ||
func (s *Shell) RunWithoutPrompt(ctx context.Context, command string, arg ...string) error { | ||
|
@@ -379,6 +403,8 @@ func (s *Shell) RunScript(ctx context.Context, path string, extra *env.Environme | |
case !isWindows && isSh: | ||
// If the script contains a shebang line, it can be run directly, | ||
// with the shebang line choosing the interpreter. | ||
// note that this means that it isn't necessarily a shell script in this case! | ||
// #!/usr/bin/env python would be totally valid, and would execute as a python script | ||
sb, err := shellscript.ShebangLine(path) | ||
if err == nil && sb != "" { | ||
command = path | ||
|
@@ -397,7 +423,7 @@ func (s *Shell) RunScript(ctx context.Context, path string, extra *env.Environme | |
s.Warningf("Couldn't find bash (%v). Attempting to fall back to sh. This may cause issues for hooks and plugins that assume Bash features.", err) | ||
shPath, err = s.AbsolutePath("sh") | ||
if err != nil { | ||
return fmt.Errorf("Error finding a shell, needed to run scripts: %v.", err) | ||
return fmt.Errorf("error finding a shell, needed to run scripts: %v", err) | ||
} | ||
} | ||
command = shPath | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,6 +197,10 @@ func (e *Environment) Apply(diff Diff) { | |
|
||
// Copy returns a copy of the env | ||
func (e *Environment) Copy() *Environment { | ||
if e == nil { | ||
return New() | ||
} | ||
|
||
Comment on lines
+200
to
+203
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gotta catch 'em all ('em being nil pointer dereference panics) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sort of expect a copy of |
||
c := New() | ||
|
||
e.underlying.Range(func(k, v string) bool { | ||
|
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.
💯% reasonable to cut this from scope.