Skip to content

Commit

Permalink
Add spacectl stack retry
Browse files Browse the repository at this point in the history
- Added a new retry command. This can be used to retry both proposed and tracked runs.
- Fixed a typo in some of the graphql field tags. It must have worked because the name wasn't being overridden.

Issues: #53
  • Loading branch information
adamconnelly committed Apr 1, 2022
1 parent 6b65d83 commit a05faa4
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/stack/local_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func localPreview() cli.ActionFunc {

var uploadMutation struct {
UploadLocalWorkspace struct {
ID string `grapqhl:"id"`
ID string `graphql:"id"`
UploadURL string `graphql:"uploadUrl"`
} `graphql:"uploadLocalWorkspace(stack: $stack)"`
}
Expand Down Expand Up @@ -65,7 +65,7 @@ func localPreview() cli.ActionFunc {

var triggerMutation struct {
RunProposeLocalWorkspace struct {
ID string `grapqhl:"id"`
ID string `graphql:"id"`
} `graphql:"runProposeLocalWorkspace(stack: $stack, workspace: $workspace)"`
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/stack/run_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func runConfirm() cli.ActionFunc {

var mutation struct {
RunConfirm struct {
ID string `grapqhl:"id"`
ID string `graphql:"id"`
} `graphql:"runConfirm(stack: $stack, run: $run)"`
}

Expand Down
48 changes: 48 additions & 0 deletions internal/cmd/stack/run_retry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package stack

import (
"fmt"

"github.com/shurcooL/graphql"
"github.com/urfave/cli/v2"

"github.com/spacelift-io/spacectl/internal/cmd/authenticated"
)

func runRetry(cliCtx *cli.Context) error {
stackID := cliCtx.String(flagStackID.Name)
runID := cliCtx.String(flagRun.Name)

var mutation struct {
RunRetry struct {
ID string `graphql:"id"`
} `graphql:"runRetry(stack: $stack, run: $run)"`
}

variables := map[string]interface{}{
"stack": graphql.ID(stackID),
"run": graphql.ID(runID),
}

if err := authenticated.Client.Mutate(cliCtx.Context, &mutation, variables); err != nil {
return err
}

fmt.Printf("Run ID %q has been successfully retried\n", runID)
fmt.Println("The live run can be visited at", authenticated.Client.URL(
"/stack/%s/run/%s",
stackID,
mutation.RunRetry.ID,
))

if !cliCtx.Bool(flagTail.Name) {
return nil
}

terminal, err := runLogs(cliCtx.Context, stackID, mutation.RunRetry.ID)
if err != nil {
return err
}

return terminal.Error()
}
2 changes: 1 addition & 1 deletion internal/cmd/stack/run_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func runTrigger(spaceliftType, humanType string) cli.ActionFunc {

var mutation struct {
RunTrigger struct {
ID string `grapqhl:"id"`
ID string `graphql:"id"`
} `graphql:"runTrigger(stack: $stack, commitSha: $sha, runType: $type)"`
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/stack/set_current_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func setCurrentCommit(cliCtx *cli.Context) error {
TrackedCommit *struct {
Hash string `graphql:"hash"`
Message string `graphql:"message"`
} `grapqhl:"trackedCommit"`
} `graphql:"trackedCommit"`
} `graphql:"stackSetCurrentCommit(id: $stack, sha: $sha)"`
}

Expand Down
13 changes: 13 additions & 0 deletions internal/cmd/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ func Command() *cli.Command {
Before: authenticated.Ensure,
ArgsUsage: cmd.EmptyArgsUsage,
},
{
Category: "Run management",
Name: "retry",
Usage: "Retry a failed run",
Flags: []cli.Flag{
flagStackID,
flagRun,
flagTail,
},
Action: runRetry,
Before: authenticated.Ensure,
ArgsUsage: cmd.EmptyArgsUsage,
},
{
Name: "list",
Usage: "List the stacks you have access to",
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/stack/task_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func taskCommand(cliCtx *cli.Context) error {

var mutation struct {
TaskCreate struct {
ID string `grapqhl:"id"`
ID string `graphql:"id"`
} `graphql:"taskCreate(stack: $stack, command: $command, skipInitialization: $noinit)"`
}

Expand Down

0 comments on commit a05faa4

Please sign in to comment.