26f897c1ec
release / release-please (push) Failing after 1m49s
docs / build (push) Failing after 6m34s
release / build-and-upload (arm64, linux) (push) Has been cancelled
release / build-and-upload (arm64, windows) (push) Has been cancelled
release / build-darwin (amd64, darwin) (push) Has been cancelled
release / checksums (push) Has been cancelled
release / finalize (push) Has been cancelled
release / build-darwin (arm64, darwin) (push) Has been cancelled
release / build-and-upload (amd64, linux) (push) Has been cancelled
release / build-and-upload (amd64, windows) (push) Has been cancelled
docs / deploy (push) Has been cancelled
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/kunchenguid/no-mistakes/internal/daemon"
|
|
"github.com/kunchenguid/no-mistakes/internal/git"
|
|
"github.com/kunchenguid/no-mistakes/internal/ipc"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newRerunCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "rerun",
|
|
Short: "Rerun the pipeline for the current branch",
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return trackCommand("rerun", func() error {
|
|
p, d, err := openResources()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer d.Close()
|
|
|
|
repo, err := findRepo(d)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
branch, err := git.CurrentBranch(context.Background(), ".")
|
|
if err != nil {
|
|
return fmt.Errorf("get current branch: %w", err)
|
|
}
|
|
if branch == "HEAD" {
|
|
return fmt.Errorf("not on a branch")
|
|
}
|
|
|
|
if err := daemon.EnsureDaemon(p); err != nil {
|
|
return fmt.Errorf("start daemon: %w", err)
|
|
}
|
|
|
|
client, err := ipc.Dial(p.Socket())
|
|
if err != nil {
|
|
return fmt.Errorf("connect to daemon: %w", err)
|
|
}
|
|
defer client.Close()
|
|
|
|
var result ipc.RerunResult
|
|
if err := client.Call(ipc.MethodRerun, &ipc.RerunParams{RepoID: repo.ID, Branch: branch}, &result); err != nil {
|
|
return fmt.Errorf("rerun pipeline: %w", err)
|
|
}
|
|
|
|
fmt.Fprintf(cmd.OutOrStdout(), " %s Rerun started for %s %s\n", sGreen.Render("✓"), branch, sDim.Render(result.RunID))
|
|
return nil
|
|
})
|
|
},
|
|
}
|
|
}
|