Skip to content

Commit 9cabfb5

Browse files
committed
fix: --path flag in update
Recent changes have resulted in the `wolfictl update --path` flag breaking. This flag allows for working with a repo where the melange yaml's are in a subdir such as `./packages` of the repo. > ℹ️ | 2024/01/31 00:40:50 wolfictl update: attempt 1: failed to update packages in git repository: failed to parse open docker-compose.yaml: no such file or directory
1 parent 00ebf14 commit 9cabfb5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

pkg/update/update.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func (o *Options) updateGitPackage(ctx context.Context, repo *git.Repository, pa
369369
root := worktree.Filesystem.Root()
370370
log.Printf("working directory: %s", root)
371371

372-
configFile := filepath.Join(root, pc.Filename)
372+
configFile := filepath.Join(pc.Dir, pc.Filename)
373373
if configFile == "" {
374374
return "", fmt.Errorf("no config filename found for package %s", packageName)
375375
}
@@ -416,7 +416,7 @@ func (o *Options) updateGitPackage(ctx context.Context, repo *git.Repository, pa
416416
}
417417

418418
// now make sure update config is configured
419-
updated, err := config.ParseConfiguration(ctx, filepath.Join(root, pc.Filename))
419+
updated, err := config.ParseConfiguration(ctx, filepath.Join(pc.Dir, pc.Filename))
420420
if err != nil {
421421
return "", fmt.Errorf("failed to parse %v", err)
422422
}
@@ -435,7 +435,7 @@ func (o *Options) updateGitPackage(ctx context.Context, repo *git.Repository, pa
435435

436436
// Skip any processing for definitions with a single pipeline
437437
if len(updated.Pipeline) > 1 && deps.ContainsGoBumpPipeline(updated) {
438-
if err := o.updateGoBumpDeps(updated, root, pc.Filename, mutations); err != nil {
438+
if err := o.updateGoBumpDeps(updated, pc.Dir, pc.Filename, mutations); err != nil {
439439
return fmt.Sprintf("error cleaning up go/bump deps: %v", err), nil
440440
}
441441
}
@@ -447,12 +447,16 @@ func (o *Options) updateGitPackage(ctx context.Context, repo *git.Repository, pa
447447
o.Logger.Printf("after clean go bumps: %s git status: %s", packageName, string(rs))
448448

449449
// Run yam formatter
450-
err = yam.FormatConfigurationFile(root, pc.Filename)
450+
err = yam.FormatConfigurationFile(root, filepath.Join(pc.Dir, pc.Filename))
451451
if err != nil {
452452
return fmt.Sprintf("failed to format configuration file: %v", err), nil
453453
}
454454

455-
_, err = worktree.Add(pc.Filename)
455+
relativeFilename, err := filepath.Rel(pc.Dir, pc.Filename)
456+
if err != nil {
457+
return "", fmt.Errorf("failed to get relative path from dir %s and file %s: %v", pc.Dir, pc.Filename, err)
458+
}
459+
_, err = worktree.Add(relativeFilename)
456460
if err != nil {
457461
return "", fmt.Errorf("failed to git add %s: %w", configFile, err)
458462
}

pkg/yam/yam.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ func FormatConfigurationFile(dir, filename string) error {
2222
return fmt.Errorf("failed to read yam config file: %v", err)
2323
}
2424

25+
// remove root dir from filename
26+
relativeFilename, err := filepath.Rel(dir, filename)
27+
if err != nil {
28+
return fmt.Errorf("failed to get relative path from dir %s and file %s: %v", dir, filename, err)
29+
}
30+
2531
fsys := osAdapter.DirFS(dir)
2632
// Format file following the repo level format
27-
err = yam.Format(fsys, []string{filename}, yam.FormatOptions{EncodeOptions: *encodeOptions})
33+
err = yam.Format(fsys, []string{relativeFilename}, yam.FormatOptions{EncodeOptions: *encodeOptions})
2834
if err != nil {
2935
return fmt.Errorf("error formatting the file %s: %v", filename, err)
3036
}

0 commit comments

Comments
 (0)