Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 3b3ff9f

Browse files
authored
🎨 Pipeline cli fixes (#1266)
1 parent 3bd0e78 commit 3b3ff9f

File tree

6 files changed

+98
-94
lines changed

6 files changed

+98
-94
lines changed

cmd/common/pipeline.go

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,9 @@ func updatePipeline(
167167
header := []string{"Environment", "Manual Trigger", "Auto Trigger", "Field Prefixes"}
168168
rows := [][]string{}
169169
for _, p := range pipeline.Phases {
170-
manualTrigger := "None"
171-
if p.GetTriggers().GetManual() != nil {
172-
manualTrigger = triggerToString(p.GetTriggers().GetManual())
173-
}
174-
175-
autoTrigger := "None"
176-
if p.GetTriggers().GetAutomatic() != nil {
177-
autoTrigger = triggerToString(p.GetTriggers().GetAutomatic())
178-
}
170+
fmt.Println(p.GetTriggers())
171+
manualTrigger := triggerToString(p.GetTriggers().GetManual())
172+
autoTrigger := triggerToString(p.GetTriggers().GetAutomatic())
179173

180174
fieldsString := ""
181175
if len(p.GetFieldPrefixes().GetPrefixes()) > 0 {
@@ -349,30 +343,9 @@ func updateTriggers(prompter Prompter, triggers *model.Triggers) (*model.Trigger
349343
}
350344
triggers = proto.Clone(triggers).(*model.Triggers)
351345

352-
triggerToLabel := func(t *model.Trigger) string {
353-
if t == nil {
354-
return "None"
355-
}
356-
357-
var conditions []string
358-
for _, t := range t.GetConditions() {
359-
switch v := t.GetCondition().(type) {
360-
case *model.Trigger_Condition_TimeAlive:
361-
conditions = append(conditions, fmt.Sprintf("Time Alive: %s", v.TimeAlive.AsDuration().String()))
362-
}
363-
}
364-
365-
triggerType := "one-of"
366-
if t.GetRequireAll() {
367-
triggerType = "all-of"
368-
}
369-
370-
return fmt.Sprintf("%s (%s)", triggerType, strings.Join(conditions, ", "))
371-
}
372-
373346
triggerLabels := []string{
374-
"Auto " + triggerToLabel(triggers.GetAutomatic()),
375-
"Manual " + triggerToLabel(triggers.GetManual()),
347+
"Auto " + triggerToString(triggers.GetAutomatic()),
348+
"Manual " + triggerToString(triggers.GetManual()),
376349
"Done",
377350
}
378351

@@ -395,7 +368,7 @@ func updateTriggers(prompter Prompter, triggers *model.Triggers) (*model.Trigger
395368
}
396369

397370
triggers.Manual = t
398-
triggerLabels[1] = "Manual " + triggerToLabel(t)
371+
triggerLabels[1] = "Manual " + triggerToString(t)
399372
case 0:
400373
// Add new trigger
401374
t, err := updateTrigger(prompter, triggers.GetAutomatic())
@@ -407,7 +380,7 @@ func updateTriggers(prompter Prompter, triggers *model.Triggers) (*model.Trigger
407380
}
408381

409382
triggers.Automatic = t
410-
triggerLabels[0] = "Auto " + triggerToLabel(t)
383+
triggerLabels[0] = "Auto " + triggerToString(t)
411384
}
412385
}
413386
}
@@ -423,9 +396,15 @@ func updateTrigger(prompter Prompter, trigger *model.Trigger) (*model.Trigger, e
423396
require = "Require any condition"
424397
}
425398

399+
enable := "Enable"
400+
if trigger.GetEnabled() {
401+
enable = "Disable"
402+
}
403+
426404
fields := []string{
427-
require,
428405
"Conditions",
406+
require,
407+
enable,
429408
"Clear",
430409
"Done",
431410
}
@@ -438,12 +417,6 @@ func updateTrigger(prompter Prompter, trigger *model.Trigger) (*model.Trigger, e
438417

439418
switch i {
440419
case 0:
441-
trigger.RequireAll = !trigger.RequireAll
442-
fields[0] = "Require all conditions"
443-
if trigger.GetRequireAll() {
444-
fields[0] = "Require any condition"
445-
}
446-
case 1:
447420
conditions, err := updateConditions(prompter, trigger.GetConditions())
448421
if err != nil {
449422
if ErrIsAborted(err) {
@@ -453,9 +426,21 @@ func updateTrigger(prompter Prompter, trigger *model.Trigger) (*model.Trigger, e
453426
}
454427

455428
trigger.Conditions = conditions
429+
case 1:
430+
trigger.RequireAll = !trigger.RequireAll
431+
fields[0] = "Require all conditions"
432+
if trigger.GetRequireAll() {
433+
fields[0] = "Require any condition"
434+
}
456435
case 2:
457-
return nil, nil
436+
trigger.Enabled = !trigger.Enabled
437+
fields[1] = "Enable"
438+
if trigger.GetEnabled() {
439+
fields[1] = "Disable"
440+
}
458441
case 3:
442+
return nil, nil
443+
case 4:
459444
return trigger, nil
460445
}
461446
}
@@ -551,19 +536,34 @@ func updateTimeAliveCondition(prompter Prompter, c *model.Trigger_Condition) (*m
551536
}
552537

553538
func triggerToString(t *model.Trigger) string {
554-
require := "one-of"
555-
if t.GetRequireAll() {
556-
require = "all-of"
539+
if t == nil {
540+
return "None"
557541
}
558542

559-
conditions := []string{}
543+
if !t.GetEnabled() {
544+
return "Disabled"
545+
}
560546

547+
conditions := []string{}
561548
for _, c := range t.GetConditions() {
562549
switch v := c.GetCondition().(type) {
563550
case *model.Trigger_Condition_TimeAlive:
564551
conditions = append(conditions, fmt.Sprintf("Time Alive (%s)", v.TimeAlive.AsDuration().String()))
565552
}
566553
}
567554

555+
if len(conditions) == 0 {
556+
return "Instant"
557+
}
558+
559+
if len(conditions) == 1 {
560+
return conditions[0]
561+
}
562+
563+
require := "one-of"
564+
if t.GetRequireAll() {
565+
require = "all-of"
566+
}
567+
568568
return fmt.Sprintf("%s: %s)", require, strings.Join(conditions, ", "))
569569
}

cmd/rig/cmd/capsule/pipeline/progress.go renamed to cmd/rig/cmd/capsule/pipeline/promote.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pipeline
22

33
import (
44
"context"
5+
"fmt"
56
"strconv"
67

78
"connectrpc.com/connect"
@@ -56,19 +57,14 @@ func (c *Cmd) progress(ctx context.Context, cmd *cobra.Command, args []string) e
5657
var envLabels []string
5758
var outs []*pipelineDryOutput
5859
for _, out := range resp.Msg.GetDryRunOutcomes() {
59-
capsule := out.GetRevision().GetSpec()
60-
req := &capsule_api.DeployRequest{
61-
CapsuleId: capsule.GetName(),
62-
ProjectId: capsule.GetProject(),
63-
EnvironmentId: capsule.GetEnvironment(),
64-
DryRun: true,
65-
}
66-
resp, err := c.Rig.Capsule().Deploy(ctx, connect.NewRequest(req))
67-
if err != nil {
68-
return err
60+
61+
fmt.Printf("Dry run for environment %v: %v\n", out.GetEnvironmentId(), out.GetOutcome())
62+
63+
if out.GetOutcome() == nil {
64+
continue
6965
}
7066

71-
out2, err := capsule_cmd.ProcessDryRunOutput(out.GetOutcome(), resp.Msg.GetOutcome())
67+
out2, err := capsule_cmd.ProcessDryRunOutput(out.GetOutcome(), out.GetOutcome())
7268
if err != nil {
7369
return err
7470
}

cmd/rig/cmd/capsule/pipeline/setup.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/rigdev/rig-go-sdk"
1616
"github.com/rigdev/rig/cmd/common"
1717
"github.com/rigdev/rig/cmd/rig/cmd/capsule"
18+
capsule_cmd "github.com/rigdev/rig/cmd/rig/cmd/capsule"
1819
"github.com/rigdev/rig/cmd/rig/cmd/completions"
1920
"github.com/rigdev/rig/cmd/rig/services/auth"
2021
"github.com/rigdev/rig/pkg/cli"
@@ -38,6 +39,7 @@ var (
3839
limit int
3940
pipelineName string
4041
dryRun bool
42+
force bool
4143
)
4244

4345
var cmd Cmd
@@ -123,9 +125,9 @@ func Setup(parent *cobra.Command, s *cli.SetupContext) {
123125
pipeline.AddCommand(pipelineAbort)
124126

125127
pipelineProgress := &cobra.Command{
126-
Use: "progress [execution-id]",
127-
Short: "Progress the pipeline to the next phase. " +
128-
"This will only work if the pipeline is in a state that allows progression. " +
128+
Use: "promote [execution-id]",
129+
Short: "promote the pipeline to the next phase. " +
130+
"This will only work if the pipeline is in a state that allows promotion. " +
129131
"I.e. it has a manual trigger",
130132
Args: cobra.MaximumNArgs(1),
131133
ValidArgsFunction: common.Complete(
@@ -138,8 +140,11 @@ func Setup(parent *cobra.Command, s *cli.SetupContext) {
138140
},
139141
}
140142
pipelineProgress.Flags().BoolVar(&dryRun, "dry-run", false,
141-
"Dry run the progression. If interactive, it will interactively show the diffs. "+
143+
"Dry run the promotion. If interactive, it will interactively show the diffs. "+
142144
"Otherwise it will print the resulting resources.")
145+
pipelineProgress.Flags().BoolVar(&force, "force", false,
146+
"Force the promotion. This will bypass any ready checks and "+
147+
"force a manual promotion no matter the configured triggers.")
143148
pipeline.AddCommand(pipelineProgress)
144149

145150
parent.AddCommand(pipeline)
@@ -163,23 +168,26 @@ func (c *Cmd) promptForPipelineName(ctx context.Context) (string, error) {
163168
resp, err := c.Rig.Project().GetEffectivePipelineSettings(ctx,
164169
connect.NewRequest(&project_api.GetEffectivePipelineSettingsRequest{
165170
ProjectId: c.Scope.GetCurrentContext().GetProject(),
171+
CapsuleId: capsule_cmd.CapsuleID,
166172
}))
167173
if err != nil {
168174
return "", err
169175
}
170176

171177
header := []string{
172178
"Name",
173-
"Initial Environment",
179+
"1stEnv",
174180
"#Phases",
181+
"Running",
175182
}
176183

177184
var rows [][]string
178185
for _, pipeline := range resp.Msg.GetPipelines() {
179186
rows = append(rows, []string{
180-
pipeline.GetName(),
181-
pipeline.GetInitialEnvironment(),
182-
fmt.Sprint(len(pipeline.GetPhases())),
187+
pipeline.GetPipeline().GetName(),
188+
pipeline.GetPipeline().GetInitialEnvironment(),
189+
fmt.Sprint(len(pipeline.GetPipeline().GetPhases())),
190+
fmt.Sprint(pipeline.GetAlreadyRunning()),
183191
})
184192
}
185193

@@ -188,7 +196,7 @@ func (c *Cmd) promptForPipelineName(ctx context.Context) (string, error) {
188196
return "", err
189197
}
190198

191-
return resp.Msg.GetPipelines()[i].GetName(), nil
199+
return resp.Msg.GetPipelines()[i].GetPipeline().GetName(), nil
192200
}
193201

194202
func (c *Cmd) promptForPipelineID(ctx context.Context) (string, error) {
@@ -298,8 +306,8 @@ func (c *Cmd) pipelineNameCompletion(
298306

299307
var pipelineNames []string
300308
for _, pipeline := range resp.Msg.GetPipelines() {
301-
if strings.HasPrefix(pipeline.GetName(), toComplete) {
302-
pipelineNames = append(pipelineNames, pipeline.GetName())
309+
if strings.HasPrefix(pipeline.GetPipeline().GetName(), toComplete) {
310+
pipelineNames = append(pipelineNames, pipeline.GetPipeline().GetName())
303311
}
304312
}
305313

cmd/rig/cmd/capsule/root/setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ forwarded traffic.
269269
capsuleCmd.AddCommand(capsuleListSetProposal)
270270

271271
capsulePromote := &cobra.Command{
272-
Use: "promote [capsule] [from-environment] [to-environment]",
273-
Short: "Promote a capsule from one environment to another",
272+
Use: "copy [capsule] [from-environment] [to-environment]",
273+
Short: "copy a capsule from one environment to another",
274274
Args: cobra.MaximumNArgs(3),
275275
RunE: cli.CtxWrap(cmd.promote),
276276
ValidArgsFunction: common.ChainCompletions(

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/nyaruka/phonenumbers v1.1.7
3333
github.com/pkg/errors v0.9.1
3434
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.70.0
35-
github.com/rigdev/rig-go-api v0.0.0-20241003083013-6515051df8b3
35+
github.com/rigdev/rig-go-api v0.0.0-20241007181528-92da8b148ff2
3636
github.com/rigdev/rig-go-sdk v0.0.0-20240612092526-69df8621bc22
3737
github.com/rivo/tview v0.0.0-20240524063012-037df494fb76
3838
github.com/robfig/cron v1.2.0
@@ -49,10 +49,10 @@ require (
4949
go.uber.org/fx v1.19.3
5050
go.uber.org/zap v1.27.0
5151
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
52-
golang.org/x/net v0.29.0
53-
golang.org/x/term v0.24.0
52+
golang.org/x/net v0.30.0
53+
golang.org/x/term v0.25.0
5454
google.golang.org/grpc v1.67.1
55-
google.golang.org/protobuf v1.34.2
55+
google.golang.org/protobuf v1.35.1
5656
gopkg.in/yaml.v2 v2.4.0
5757
gopkg.in/yaml.v3 v3.0.1
5858
helm.sh/helm/v3 v3.15.4
@@ -173,16 +173,16 @@ require (
173173
go.opentelemetry.io/otel/trace v1.28.0 // indirect
174174
go.uber.org/atomic v1.11.0 // indirect
175175
go.uber.org/multierr v1.11.0 // indirect
176-
golang.org/x/crypto v0.27.0 // indirect
176+
golang.org/x/crypto v0.28.0 // indirect
177177
golang.org/x/mod v0.21.0 // indirect
178178
golang.org/x/oauth2 v0.23.0 // indirect
179179
golang.org/x/sync v0.8.0 // indirect
180-
golang.org/x/sys v0.25.0 // indirect
181-
golang.org/x/text v0.18.0 // indirect
180+
golang.org/x/sys v0.26.0 // indirect
181+
golang.org/x/text v0.19.0 // indirect
182182
golang.org/x/time v0.6.0 // indirect
183183
golang.org/x/tools v0.25.0 // indirect
184184
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
185-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect
185+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
186186
gopkg.in/inf.v0 v0.9.1 // indirect
187187
gopkg.in/ini.v1 v1.67.0 // indirect
188188
gotest.tools/v3 v3.5.1 // indirect

0 commit comments

Comments
 (0)