mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 12:54:14 +02:00
Toolchain and CI:
- Bump go directive from 1.26.8 to 1.27.1 (go.mod)
- Use golang:1.27-alpine builder images in all Dockerfiles
- Bump golangci-lint to v2.13.2 (first release with go1.27 support)
- Add CI gate: `go fix -diff` fails when outdated Go patterns are
detected (locally: `make check-modernize`)
Note: darwin binaries now require macOS 13 or later.
Lint fixes required by golangci-lint v2.13.2:
- goconst: ignore tests (all 436 findings were test-only; goconst
got stricter since v2.12 and this option was added for it)
- openai.go: keep deprecated MaxTokens deliberately with a nolint
rationale (max_tokens is the only form universally supported by
OpenAI-compatible backends like One-API, LiteLLM, Ollama shim)
- state.go: drop always-nil flags param from appendChartVersionFlags
(renamed to chartVersionFlags, unparam)
Modernization (go fix ./..., 62 files):
- interface{} -> any, maps.Copy, strings.SplitSeq, range-over-int,
builtin min/max, slices.Contains/ContainsFunc/Sort, WaitGroup.Go,
reflect.Type.Fields(), new(expr)
- exit_error.go: strings.Builder + fmt.Fprintf instead of string
concatenation and WriteString(fmt.Sprintf(...)) (QF1012)
- chart_dependency.go: strings.CutLast for OCI dependency helpers
Signed-off-by: yxxhero <aiopsclub@163.com>
Co-authored-by: Claude <noreply@anthropic.com>
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package helmexec
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func newExitError(path string, args []string, exitStatus int, err error, stderr, combined string, stripArgsValuesOnExitError bool) ExitError {
|
|
var out strings.Builder
|
|
|
|
fmt.Fprintf(&out, "PATH:\n%s", Indent(path, " "))
|
|
|
|
out.WriteString("\n\nARGS:")
|
|
// The legacy profile is byte-identical to the historical inline logic;
|
|
// the goldens in exit_error_test.go pin its exact output.
|
|
redacted := RedactArgs(args, RedactionLegacy)
|
|
if !stripArgsValuesOnExitError {
|
|
redacted = args
|
|
}
|
|
for i, a := range redacted {
|
|
fmt.Fprintf(&out, "\n%s", Indent(fmt.Sprintf("%d: %s (%d bytes)", i, a, len(a)), " "))
|
|
}
|
|
|
|
fmt.Fprintf(&out, "\n\nERROR:\n%s", Indent(err.Error(), " "))
|
|
|
|
fmt.Fprintf(&out, "\n\nEXIT STATUS\n%s", Indent(fmt.Sprintf("%d", exitStatus), " "))
|
|
|
|
if len(stderr) > 0 {
|
|
fmt.Fprintf(&out, "\n\nSTDERR:\n%s", Indent(stderr, " "))
|
|
}
|
|
|
|
if len(combined) > 0 {
|
|
fmt.Fprintf(&out, "\n\nCOMBINED OUTPUT:\n%s", Indent(combined, " "))
|
|
}
|
|
|
|
return ExitError{
|
|
Message: fmt.Sprintf("command %q exited with non-zero status:\n\n%s", path, out.String()),
|
|
Code: exitStatus,
|
|
}
|
|
}
|
|
|
|
// indents a block of text with an indent string
|
|
func Indent(text, indent string) string {
|
|
var b strings.Builder
|
|
|
|
b.Grow(len(text) * 2)
|
|
|
|
lines := strings.Split(text, "\n")
|
|
|
|
last := len(lines) - 1
|
|
|
|
for i, j := range lines {
|
|
if i > 0 && i < last && j != "" {
|
|
b.WriteString("\n")
|
|
}
|
|
|
|
if j != "" {
|
|
b.WriteString(indent + j)
|
|
}
|
|
}
|
|
|
|
return b.String()
|
|
}
|
|
|
|
// ExitError is created whenever your shell command exits with a non-zero exit status
|
|
type ExitError struct {
|
|
Message string
|
|
Code int
|
|
}
|
|
|
|
func (e ExitError) Error() string {
|
|
return e.Message
|
|
}
|
|
|
|
func (e ExitError) ExitStatus() int {
|
|
return e.Code
|
|
}
|