fix: fall back to debug.ReadBuildInfo for version when ldflags not set#332
Open
znd4 wants to merge 7 commits into
Open
fix: fall back to debug.ReadBuildInfo for version when ldflags not set#332znd4 wants to merge 7 commits into
znd4 wants to merge 7 commits into
Conversation
When helm-docs is installed via `go install` (e.g., by pre-commit's
`language: golang` hook type), no -ldflags are passed, so the `version`
variable remains empty. This causes the README footer template
(`{{ if .HelmDocsVersion }}`) to produce no output, resulting in
different output from the release binary and CI failures.
Add a fallback using `runtime/debug.ReadBuildInfo()` in an init()
function. When `go install module@version` builds a binary, Go embeds
the module version in the binary metadata. The ldflags-set version
still takes priority when present (e.g., goreleaser builds).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Temporary workflow to verify that the debug.ReadBuildInfo fallback works correctly for both `go install` and pre-commit helm-docs-built. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
go install from a local checkout sets a pseudo-version, not (devel). Check that the version string is non-empty instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
YAML heredoc content was indented by the workflow step indentation, producing invalid Chart.yaml. Use printf instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Strip leading "v" from debug.ReadBuildInfo version since the footer template already prepends "v" (avoids "vv0.0.0-..." output) - Use dedicated directory for test chart to avoid /tmp permission errors Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When helm-docs is built from a local checkout (e.g. pre-commit's language: golang hook), ReadBuildInfo().Main.Version returns "(devel)" rather than a meaningful version. Filter this out so the footer template skips the version rather than rendering "v(devel)". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
helm-docsis built viago install(e.g., by pre-commit'slanguage: golanghook type for thehelm-docs-builthook), no-ldflagsare passed, so theversionvariable remains an empty string. This causes:helm-docs --versionprintshelm-docs versionwith no versionAutogenerated from chart metadata using [helm-docs vX.Y.Z]) is not rendered, because the default template checks{{ if .HelmDocsVersion }}This means the
helm-docs-builtpre-commit hook produces different output than the release binary, causing CI failures when the committed README was generated by a release binary (or vice versa).Fix
Add a fallback using
runtime/debug.ReadBuildInfo()in aninit()function. When Go builds a binary viago install module@version, it embeds the module version in the binary metadata. This is a stdlib-only change with no new dependencies.vprefix from Go module versions is stripped to match the existing convention (the footer template already prependsv)Reproduction & validation
A test workflow on the fork validates both paths:
go install ./cmd/helm-docs(no ldflags): version is set, footer renders ✅helm-docs-builthook: footer renders, output is idempotent ✅