| 176 | } |
| 177 | |
| 178 | func executeHook(ctx devspacecontext.Context, hookConfig *latest.HookConfig, hookWriter io.WriteCloser, extraEnv map[string]string, hook Hook, event string) error { |
| 179 | hookLog := ctx.Log() |
| 180 | if hookConfig.Silent { |
| 181 | hookLog = logpkg.Discard |
| 182 | } |
| 183 | |
| 184 | if hookConfig.Background { |
| 185 | ctx.Log().Infof("Execute hook '%s' in background at %s", ansi.Color(hookName(hookConfig), "white+b"), ansi.Color(event, "white+b")) |
| 186 | go func() { |
| 187 | err := hook.Execute(ctx.WithLogger(hookLog), hookConfig, extraEnv) |
| 188 | if err != nil { |
| 189 | if hookConfig.Silent { |
| 190 | ctx.Log().Warnf("Error executing hook '%s' in background: %s %v", ansi.Color(hookName(hookConfig), "white+b"), hookWriter.(logpkg.NopCloser).Writer.(*bytes.Buffer).String(), err) |
| 191 | } else { |
| 192 | ctx.Log().Warnf("Error executing hook '%s' in background: %v", ansi.Color(hookName(hookConfig), "white+b"), err) |
| 193 | } |
| 194 | } |
| 195 | }() |
| 196 | |
| 197 | return nil |
| 198 | } |
| 199 | |
| 200 | ctx.Log().Infof("Execute hook '%s' at %s", ansi.Color(hookName(hookConfig), "white+b"), ansi.Color(event, "white+b")) |
| 201 | err := hook.Execute(ctx.WithLogger(hookLog), hookConfig, extraEnv) |
| 202 | if err != nil { |
| 203 | if hookConfig.Silent { |
| 204 | return errors.Wrapf(err, "in hook '%s': %s", ansi.Color(hookName(hookConfig), "white+b"), hookWriter.(*logpkg.NopCloser).Writer.(*bytes.Buffer).String()) |
| 205 | } |
| 206 | return errors.Wrapf(err, "in hook '%s'", ansi.Color(hookName(hookConfig), "white+b")) |
| 207 | } |
| 208 | |
| 209 | return nil |
| 210 | } |
| 211 | |
| 212 | func hookName(hook *latest.HookConfig) string { |
| 213 | if hook.Name != "" { |