Repository navigation
fix(templater): keep unresolved dynamic vars in globs - #3103
Closed
Tyagiquamar wants to merge 1 commit into
Closed
Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
Member
|
AI slop |
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.
Summary
Fixes #2400. When a task's
sourcesuse a shell-derived (dynamic) variable, for example{{.PARENT}}/**/*, the fingerprint phase expanded the glob from the filesystem root (/**/*) and could hang on symlink cycles. The placeholder is now preserved when its variable has not been evaluated yet.Root Cause & Problem
FastCompiledTask()usesCompiler.FastGetVariables, which deliberately leavessh:variables unevaluated and stores them with an empty string value so templates can still be parsed.templater.ReplaceGlobsthen rendered{{.PARENT}}/**/*with that empty value;ReplaceWithExtraadditionally strips<no value>to an empty string. The result was an absolute/**/*pattern. After the switch tomvdan/sh/expand.Fieldsfor glob expansion, that pattern recursively follows symlinks and can loop forever. The task never starts and there is no useful error, only repeatedELOOPinstrace.Technical Solution
In
internal/templater/templater.go,ReplaceGlobsnow checks whether a glob references a variable that is missing or still unevaluated (Shset with an empty value). For those globs it keeps the original pattern instead of replacing it with an empty prefix. Fully resolved variables, including static variables, are replaced exactly as before. This keeps the pattern relative and prevents root-level traversal; it does not change compilation withCompiledTask(), where dynamic variables are available and substitution proceeds normally.Test Plan
Added
TestReplaceGlobsKeepsUnresolvedDynamicVariablesininternal/templater/glob_test.go:sh:variable keeps{{.PARENT}}/**/*unchanged;parent/**/*.Validation in Docker (
golang:1.27-bookworm; repogo.modrequires go 1.26.4):gofmt -lon LF-normalized copies of both changed files: no output, clean.go vet ./internal/templater/...: no findings.go test -count=1 -run TestReplaceGlobsKeepsUnresolvedDynamicVariables ./internal/templater/...: PASS.expected: "{{.PARENT}}/**/*", actual: "/**/*", confirming the regression is guarded.git diff --check: clean.Full
task lint/ full test suite are deferred to GitHub Actions CI.AI disclosure
AI assistance was used to analyze the glob substitution path and to draft the fix and the regression test. I reviewed the diff and executed all validation commands listed above.