Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support variable substitution in archive.files #1350

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions internal/pipe/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ func create(ctx *context.Context, archive config.Archive, binaries []*artifact.A
var log = log.WithField("archive", archivePath)
log.Info("creating")

wrap, err := tmpl.New(ctx).
WithArtifact(binaries[0], archive.Replacements).
template := tmpl.New(ctx).
WithArtifact(binaries[0], archive.Replacements)
wrap, err := template.
Apply(wrapFolder(archive))
if err != nil {
return err
Expand All @@ -141,7 +142,7 @@ func create(ctx *context.Context, archive config.Archive, binaries []*artifact.A
var a = NewEnhancedArchive(archivelib.New(archiveFile), wrap)
defer a.Close() // nolint: errcheck

files, err := findFiles(archive)
files, err := findFiles(template, archive)
if err != nil {
return fmt.Errorf("failed to find files to archive: %s", err.Error())
}
Expand Down Expand Up @@ -210,9 +211,13 @@ func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Art
return nil
}

func findFiles(archive config.Archive) (result []string, err error) {
func findFiles(template *tmpl.Template, archive config.Archive) (result []string, err error) {
for _, glob := range archive.Files {
files, err := zglob.Glob(glob)
replaced, err := template.Apply(glob)
if err != nil {
return result, errors.Wrapf(err, "failed to apply template %s", glob)
}
files, err := zglob.Glob(replaced)
if err != nil {
return result, fmt.Errorf("globbing failed for pattern %s: %s", glob, err.Error())
}
Expand Down