fix: cleanup from daily usage
ci/woodpecker/push/goreleaser Pipeline was successful Details
ci/woodpecker/tag/goreleaser Pipeline was successful Details

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main v0.0.8
jolheiser 2023-01-23 22:41:10 -06:00
parent 190ea6c7f3
commit f335f5805f
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
4 changed files with 39 additions and 4 deletions

View File

@ -24,6 +24,8 @@ func (h *Handler) Backport() *ffcli.Command {
fs.StringVar(toFlag, "t", *toFlag, "--to") fs.StringVar(toFlag, "t", *toFlag, "--to")
listFlag := fs.Bool("list", false, "Open repository to see needed backports") listFlag := fs.Bool("list", false, "Open repository to see needed backports")
fs.BoolVar(listFlag, "l", *listFlag, "--list") fs.BoolVar(listFlag, "l", *listFlag, "--list")
pushFlag := fs.Bool("push", false, "Push immediately")
fs.BoolVar(pushFlag, "p", *pushFlag, "--push")
return &ffcli.Command{ return &ffcli.Command{
Name: "backport", Name: "backport",
FlagSet: fs, FlagSet: fs,
@ -91,7 +93,15 @@ func (h *Handler) Backport() *ffcli.Command {
return err return err
} }
return run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]) if err := run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]); err != nil {
return err
}
if *pushFlag {
return run(ctx, h.Config.WorkspaceBranch(branch), "git", "push", "origin", "HEAD")
}
return nil
}, },
} }
} }

View File

@ -13,6 +13,8 @@ func (h *Handler) Cleanup() *ffcli.Command {
fs := flag.NewFlagSet("cleanup", flag.ContinueOnError) fs := flag.NewFlagSet("cleanup", flag.ContinueOnError)
forceFlag := fs.Bool("force", false, "Force cleanup") forceFlag := fs.Bool("force", false, "Force cleanup")
fs.BoolVar(forceFlag, "f", *forceFlag, "--force") fs.BoolVar(forceFlag, "f", *forceFlag, "--force")
pruneFlag := fs.Bool("prune", false, "Prune worktrees")
fs.BoolVar(pruneFlag, "p", *pruneFlag, "--prune")
return &ffcli.Command{ return &ffcli.Command{
Name: "cleanup", Name: "cleanup",
FlagSet: fs, FlagSet: fs,
@ -23,6 +25,10 @@ func (h *Handler) Cleanup() *ffcli.Command {
return err return err
} }
if *pruneFlag {
return run(ctx, h.Config.Workspace(), "git", "worktree", "prune")
}
if len(args) > 0 { if len(args) > 0 {
for _, arg := range args { for _, arg := range args {
if err := removeWorktree(h, ctx, arg, *forceFlag); err != nil { if err := removeWorktree(h, ctx, arg, *forceFlag); err != nil {

View File

@ -18,6 +18,8 @@ func (h *Handler) Frontport() *ffcli.Command {
fs.StringVar(fromFlag, "f", *fromFlag, "--from") fs.StringVar(fromFlag, "f", *fromFlag, "--from")
toFlag := fs.String("to", "", "Release to frontport to (ex: `main`, default: `main`)") toFlag := fs.String("to", "", "Release to frontport to (ex: `main`, default: `main`)")
fs.StringVar(toFlag, "t", *toFlag, "--to") fs.StringVar(toFlag, "t", *toFlag, "--to")
pushFlag := fs.Bool("push", false, "Push immediately")
fs.BoolVar(pushFlag, "p", *pushFlag, "--push")
return &ffcli.Command{ return &ffcli.Command{
Name: "frontport", Name: "frontport",
FlagSet: fs, FlagSet: fs,
@ -83,7 +85,15 @@ func (h *Handler) Frontport() *ffcli.Command {
return err return err
} }
return run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]) if err := run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]); err != nil {
return err
}
if *pushFlag {
return run(ctx, h.Config.WorkspaceBranch(branch), "git", "push", "origin", "HEAD")
}
return nil
}, },
} }
} }

View File

@ -23,6 +23,8 @@ var (
func (h *Handler) Tag() *ffcli.Command { func (h *Handler) Tag() *ffcli.Command {
fs := flag.NewFlagSet("tag", flag.ContinueOnError) fs := flag.NewFlagSet("tag", flag.ContinueOnError)
pushFlag := fs.Bool("push", false, "Push immediately")
fs.BoolVar(pushFlag, "p", *pushFlag, "--push")
return &ffcli.Command{ return &ffcli.Command{
Name: "tag", Name: "tag",
FlagSet: fs, FlagSet: fs,
@ -81,7 +83,7 @@ func (h *Handler) Tag() *ffcli.Command {
return err return err
} }
workspaceName := strings.ReplaceAll(branch, "/", "-") workspaceName := fmt.Sprintf("release-%s", version)
if err := h.Branch().ParseAndRun(ctx, []string{"--base", branch, workspaceName}); err != nil { if err := h.Branch().ParseAndRun(ctx, []string{"--base", branch, workspaceName}); err != nil {
return err return err
} }
@ -104,7 +106,14 @@ func (h *Handler) Tag() *ffcli.Command {
if err := fi.Close(); err != nil { if err := fi.Close(); err != nil {
return err return err
} }
run(ctx, h.Config.WorkspaceBranch(workspaceName), "git", "tag", "-s", "-F", "release.notes", version)
if err := run(ctx, h.Config.WorkspaceBranch(workspaceName), "git", "tag", "-s", "-F", "release.notes", version); err != nil {
return err
}
if *pushFlag {
return run(ctx, h.Config.WorkspaceBranch(workspaceName), "git", "push", "upstream", version)
}
fmt.Printf("cd %s && git push upstream %s \n", h.Config.WorkspaceBranch(workspaceName), version) fmt.Printf("cd %s && git push upstream %s \n", h.Config.WorkspaceBranch(workspaceName), version)
return nil return nil