From 673f76c8db4febd00f79f9e379299bf8395c83e5 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 24 Jun 2024 18:56:37 +0200 Subject: [PATCH] Don't run spinners in CI --- cmd/tea_ensuretoken.go | 8 ++++---- cmd/tea_initialisesources.go | 4 +++- cmd/tea_plan.go | 4 +++- cmd/tea_revlink.go | 5 ++++- cmd/tea_snapshot.go | 13 ++++++++++--- cmd/tea_submitplan.go | 19 ++++++++++++++----- cmd/tea_taskmodel.go | 3 ++- 7 files changed, 40 insertions(+), 16 deletions(-) diff --git a/cmd/tea_ensuretoken.go b/cmd/tea_ensuretoken.go index 87f05510..d6f5cbfd 100644 --- a/cmd/tea_ensuretoken.go +++ b/cmd/tea_ensuretoken.go @@ -100,10 +100,10 @@ func (m ensureTokenModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case instanceLoadedMsg: m.oi = msg.instance m.status = taskStatusRunning - cmds = append(cmds, - m.ensureTokenCmd(m.ctx), - m.spinner.Tick, - ) + cmds = append(cmds, m.ensureTokenCmd(m.ctx)) + if os.Getenv("CI") == "" { + cmds = append(cmds, m.spinner.Tick) + } case displayAuthorizationInstructionsMsg: m.deviceMessage = "manual" m.deviceConfig = msg.config diff --git a/cmd/tea_initialisesources.go b/cmd/tea_initialisesources.go index b2af7c75..485e3d4f 100644 --- a/cmd/tea_initialisesources.go +++ b/cmd/tea_initialisesources.go @@ -92,7 +92,9 @@ func (m initialiseSourcesModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.status = taskStatusRunning cmds = append(cmds, m.loadSourcesConfigCmd) - cmds = append(cmds, m.spinner.Tick) + if os.Getenv("CI") == "" { + cmds = append(cmds, m.spinner.Tick) + } case askForAwsConfigMsg: // load the config that was injected above. If it's not there, prompt the user. aws_config := viper.GetString("aws-config") diff --git a/cmd/tea_plan.go b/cmd/tea_plan.go index a103af64..c9db9605 100644 --- a/cmd/tea_plan.go +++ b/cmd/tea_plan.go @@ -60,7 +60,9 @@ func (m runPlanModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.taskModel.status = taskStatusRunning // since the taskModel will not be shown while `terraform plan` is running, // there's no need to actually kick off the spinner - // cmds = append(cmds, m.taskModel.spinner.Tick) + // if os.Getenv("CI") == "" { + // cmds = append(cmds, m.taskModel.spinner.Tick) + // } // defer the actual command to give the view a chance to show the header cmds = append(cmds, func() tea.Msg { return runPlanNowMsg{} }) diff --git a/cmd/tea_revlink.go b/cmd/tea_revlink.go index ac525d1c..02f401ab 100644 --- a/cmd/tea_revlink.go +++ b/cmd/tea_revlink.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "os" "time" "connectrpc.com/connect" @@ -58,7 +59,9 @@ func (m revlinkWarmupModel) Update(msg tea.Msg) (revlinkWarmupModel, tea.Cmd) { case sourcesInitialisedMsg: m.taskModel.status = taskStatusRunning // start the spinner - cmds = append(cmds, m.taskModel.spinner.Tick) + if os.Getenv("CI") == "" { + cmds = append(cmds, m.taskModel.spinner.Tick) + } // setup the watchdog infrastructure ctx, cancel := context.WithCancel(m.ctx) diff --git a/cmd/tea_snapshot.go b/cmd/tea_snapshot.go index 760d9a2d..d07d4667 100644 --- a/cmd/tea_snapshot.go +++ b/cmd/tea_snapshot.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "strings" tea "github.com/charmbracelet/bubbletea" @@ -58,7 +59,9 @@ func (m snapshotModel) Update(msg tea.Msg) (snapshotModel, tea.Cmd) { return m, nil } m.overall.status = taskStatusRunning - cmds = append(cmds, m.overall.spinner.Tick) + if os.Getenv("CI") == "" { + cmds = append(cmds, m.overall.spinner.Tick) + } case progressSnapshotMsg: if m.overall.spinner.ID() != msg.id { return m, nil @@ -68,7 +71,9 @@ func (m snapshotModel) Update(msg tea.Msg) (snapshotModel, tea.Cmd) { m.edges = msg.edges m.discovering.status = taskStatusRunning - cmds = append(cmds, m.discovering.spinner.Tick) + if os.Getenv("CI") == "" { + cmds = append(cmds, m.discovering.spinner.Tick) + } case savingSnapshotMsg: if m.overall.spinner.ID() != msg.id { return m, nil @@ -77,7 +82,9 @@ func (m snapshotModel) Update(msg tea.Msg) (snapshotModel, tea.Cmd) { m.discovering.status = taskStatusDone m.saving.status = taskStatusRunning - cmds = append(cmds, m.saving.spinner.Tick) + if os.Getenv("CI") == "" { + cmds = append(cmds, m.saving.spinner.Tick) + } case finishSnapshotMsg: if m.overall.spinner.ID() != msg.id { diff --git a/cmd/tea_submitplan.go b/cmd/tea_submitplan.go index 55594d9f..c694c418 100644 --- a/cmd/tea_submitplan.go +++ b/cmd/tea_submitplan.go @@ -101,12 +101,17 @@ func (m submitPlanModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case submitPlanNowMsg: cmds = append(cmds, m.submitPlanCmd, - m.removingSecretsTask.spinner.Tick, - m.resourceExtractionTask.spinner.Tick, - m.uploadChangesTask.spinner.Tick, m.waitForSubmitPlanActivity, ) + if os.Getenv("CI") == "" { + cmds = append(cmds, + m.removingSecretsTask.spinner.Tick, + m.resourceExtractionTask.spinner.Tick, + m.uploadChangesTask.spinner.Tick, + ) + } + case submitPlanUpdateMsg: // ensure that the wrapped message is submitted before we wait for the // next update. This is still not perfect, but there's currently no @@ -142,7 +147,9 @@ func (m submitPlanModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.riskMilestoneTasks[i].status = taskStatusDone case sdp.RiskCalculationStatus_ProgressMilestone_STATUS_INPROGRESS: m.riskMilestoneTasks[i].status = taskStatusRunning - cmds = append(cmds, m.riskMilestoneTasks[i].spinner.Tick) + if os.Getenv("CI") == "" { + cmds = append(cmds, m.riskMilestoneTasks[i].spinner.Tick) + } case sdp.RiskCalculationStatus_ProgressMilestone_STATUS_SKIPPED: m.riskMilestoneTasks[i].status = taskStatusSkipped } @@ -151,7 +158,9 @@ func (m submitPlanModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if len(m.riskMilestones) > 0 { m.riskTask.status = taskStatusRunning - cmds = append(cmds, m.riskTask.spinner.Tick) + if os.Getenv("CI") == "" { + cmds = append(cmds, m.riskTask.spinner.Tick) + } var allSkipped = true for _, ms := range m.riskMilestoneTasks { diff --git a/cmd/tea_taskmodel.go b/cmd/tea_taskmodel.go index 50efb23a..b07cd5e3 100644 --- a/cmd/tea_taskmodel.go +++ b/cmd/tea_taskmodel.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" @@ -58,7 +59,7 @@ func NewTaskModel(title string, width int) taskModel { } func (m taskModel) Init() tea.Cmd { - if m.status == taskStatusRunning { + if m.status == taskStatusRunning && os.Getenv("CI") == "" { return m.spinner.Tick } return nil