mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Feature/dependency pinning and update automation (#5451)
* * handle local flag * add managerfactory handling for local flag * add shortName handling for local flag * add dot git file handling for local flag * add tests * fix normal listing * add ParseGitRepository function, add viper, add testing for utils * add latest tag logic, add auto pinning and auto fetching * makke gorepomod list works with --local * make pinning works with local flag, enable auto update on fork and non-fork repo * fix: refactor to pass linter * refactor code and fix comments * edit README * refactor code to pass linting * refactor code * refactor code and enable patch branch label * ru add license * fbackward compatibility for unpin
This commit is contained in:
committed by
GitHub
parent
f3fedac429
commit
ab519fdc13
@@ -8,8 +8,10 @@ import (
|
||||
"os"
|
||||
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/arguments"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/git"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/misc"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/repo"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/semver"
|
||||
)
|
||||
|
||||
//go:generate go run internal/gen/main.go
|
||||
@@ -19,14 +21,19 @@ func loadRepoManager(args *arguments.Args) (*repo.Manager, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dg, err := repo.NewDotGitDataFromPath(path)
|
||||
dg, err := repo.NewDotGitDataFromPath(path, args.LocalFlag())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pr, err := dg.NewRepoFactory(args.Exclusions())
|
||||
pr, err := dg.NewRepoFactory(args.Exclusions(), args.LocalFlag())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if args.LocalFlag() {
|
||||
return pr.NewRepoManagerWithLocalFlag(args.AllowedReplacements()), nil
|
||||
}
|
||||
|
||||
return pr.NewRepoManager(args.AllowedReplacements()), nil
|
||||
}
|
||||
|
||||
@@ -67,18 +74,72 @@ func actualMain() error {
|
||||
return mgr.Tidy(args.DoIt())
|
||||
case arguments.Pin:
|
||||
v := args.Version()
|
||||
if v.IsZero() {
|
||||
v = targetModule.VersionLocal()
|
||||
// Update branch history
|
||||
gr := git.NewQuiet(mgr.AbsPath(), args.DoIt(), false)
|
||||
err = gr.FetchRemote(misc.TrackedRepo(gr.GetMainBranch()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w", err)
|
||||
}
|
||||
return mgr.Pin(args.DoIt(), targetModule, v)
|
||||
|
||||
if v.IsZero() {
|
||||
// Always use latest tag while does not removing manual usage capability
|
||||
releaseBranch := fmt.Sprintf("release-%s", targetModule.ShortName())
|
||||
fmt.Printf("new version not specified, fall back to latest version according to release branch: %s-*\n", releaseBranch)
|
||||
latest, err := gr.GetLatestTag(releaseBranch)
|
||||
if err != nil {
|
||||
v = targetModule.VersionLocal()
|
||||
err = mgr.Pin(args.DoIt(), targetModule, v)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
v, err = semver.Parse(latest)
|
||||
if err != nil {
|
||||
v = targetModule.VersionLocal()
|
||||
err = mgr.Pin(args.DoIt(), targetModule, v)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// If we can't find revision extracted from latest version specified on release branch
|
||||
err = mgr.Pin(args.DoIt(), targetModule, v)
|
||||
if err != nil {
|
||||
v = targetModule.VersionLocal()
|
||||
err = mgr.Pin(args.DoIt(), targetModule, v)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
case arguments.UnPin:
|
||||
return mgr.UnPin(args.DoIt(), targetModule, conditionalModule)
|
||||
err = mgr.UnPin(args.DoIt(), targetModule, conditionalModule)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: %w", err)
|
||||
}
|
||||
return nil
|
||||
case arguments.Release:
|
||||
return mgr.Release(targetModule, args.Bump(), args.DoIt())
|
||||
err = mgr.Release(targetModule, args.Bump(), args.DoIt(), args.LocalFlag())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: %w", err)
|
||||
}
|
||||
return nil
|
||||
case arguments.UnRelease:
|
||||
return mgr.UnRelease(targetModule, args.DoIt())
|
||||
err = mgr.UnRelease(targetModule, args.DoIt(), args.LocalFlag())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: %w", err)
|
||||
}
|
||||
return nil
|
||||
case arguments.Debug:
|
||||
return mgr.Debug(targetModule, args.DoIt())
|
||||
err = mgr.Debug(targetModule, args.DoIt(), args.LocalFlag())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: %w", err)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("cannot handle cmd %v", args.GetCommand())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user