1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-24 08:02:18 +02:00

Use UUID instead of step name where possible (#3136)

things I found while looking at  #3109
This commit is contained in:
6543 2024-01-09 05:43:03 +01:00 committed by GitHub
parent 31614d0e38
commit c64340cf8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 15 deletions

View File

@ -107,7 +107,7 @@ func (e *local) execClone(ctx context.Context, step *types.Step, state *workflow
e.output, _ = cmd.StdoutPipe() e.output, _ = cmd.StdoutPipe()
cmd.Stderr = cmd.Stdout cmd.Stderr = cmd.Stdout
state.stepCMDs[step.Name] = cmd state.stepCMDs[step.UUID] = cmd
return cmd.Start() return cmd.Start()
} }

View File

@ -166,7 +166,7 @@ func (e *local) execCommands(ctx context.Context, step *types.Step, state *workf
e.output = io.NopCloser(transform.NewReader(e.output, unicode.UTF8.NewDecoder().Transformer)) e.output = io.NopCloser(transform.NewReader(e.output, unicode.UTF8.NewDecoder().Transformer))
} }
state.stepCMDs[step.Name] = cmd state.stepCMDs[step.UUID] = cmd
return cmd.Start() return cmd.Start()
} }
@ -186,7 +186,7 @@ func (e *local) execPlugin(ctx context.Context, step *types.Step, state *workflo
e.output, _ = cmd.StdoutPipe() e.output, _ = cmd.StdoutPipe()
cmd.Stderr = cmd.Stdout cmd.Stderr = cmd.Stdout
state.stepCMDs[step.Name] = cmd state.stepCMDs[step.UUID] = cmd
return cmd.Start() return cmd.Start()
} }
@ -201,9 +201,9 @@ func (e *local) WaitStep(_ context.Context, step *types.Step, taskUUID string) (
return nil, err return nil, err
} }
cmd, ok := state.stepCMDs[step.Name] cmd, ok := state.stepCMDs[step.UUID]
if !ok { if !ok {
return nil, fmt.Errorf("step cmd %s not found", step.Name) return nil, fmt.Errorf("step cmd for %s not found", step.UUID)
} }
err = cmd.Wait() err = cmd.Wait()

View File

@ -31,22 +31,22 @@ var (
// An ExitError reports an unsuccessful exit. // An ExitError reports an unsuccessful exit.
type ExitError struct { type ExitError struct {
Name string UUID string
Code int Code int
} }
// Error returns the error message in string format. // Error returns the error message in string format.
func (e *ExitError) Error() string { func (e *ExitError) Error() string {
return fmt.Sprintf("%s : exit code %d", e.Name, e.Code) return fmt.Sprintf("uuid=%s: exit code %d", e.UUID, e.Code)
} }
// An OomError reports the process received an OOMKill from the kernel. // An OomError reports the process received an OOMKill from the kernel.
type OomError struct { type OomError struct {
Name string UUID string
Code int Code int
} }
// Error returns the error message in string format. // Error returns the error message in string format.
func (e *OomError) Error() string { func (e *OomError) Error() string {
return fmt.Sprintf("%s : received oom kill", e.Name) return fmt.Sprintf("uuid=%s: received oom kill", e.UUID)
} }

View File

@ -20,10 +20,10 @@ import (
func TestExitError(t *testing.T) { func TestExitError(t *testing.T) {
err := ExitError{ err := ExitError{
Name: "build", UUID: "14534321",
Code: 255, Code: 255,
} }
got, want := err.Error(), "build : exit code 255" got, want := err.Error(), "uuid=14534321: exit code 255"
if got != want { if got != want {
t.Errorf("Want error message %q, got %q", want, got) t.Errorf("Want error message %q, got %q", want, got)
} }
@ -31,9 +31,9 @@ func TestExitError(t *testing.T) {
func TestOomError(t *testing.T) { func TestOomError(t *testing.T) {
err := OomError{ err := OomError{
Name: "build", UUID: "14534321",
} }
got, want := err.Error(), "build : received oom kill" got, want := err.Error(), "uuid=14534321: received oom kill"
if got != want { if got != want {
t.Errorf("Want error message %q, got %q", want, got) t.Errorf("Want error message %q, got %q", want, got)
} }

View File

@ -280,12 +280,12 @@ func (r *Runtime) exec(step *backend.Step) (*backend.State, error) {
if waitState.OOMKilled { if waitState.OOMKilled {
return waitState, &OomError{ return waitState, &OomError{
Name: step.Name, UUID: step.UUID,
Code: waitState.ExitCode, Code: waitState.ExitCode,
} }
} else if waitState.ExitCode != 0 { } else if waitState.ExitCode != 0 {
return waitState, &ExitError{ return waitState, &ExitError{
Name: step.Name, UUID: step.UUID,
Code: waitState.ExitCode, Code: waitState.ExitCode,
} }
} }