Skip to content

Commit

Permalink
Adds Resource Trigger Hotkey to HUD/TUI (#6039)
Browse files Browse the repository at this point in the history
* add 't' hotkey to trigger resource update in HUD/TUI mode

Signed-off-by: bshore <[email protected]>

* minor cleanup, re-generate goldenfiles

Signed-off-by: bshore <[email protected]>

* move AppendToTriggerQueueAction to internal/store and update references

Signed-off-by: bshore <[email protected]>

---------

Signed-off-by: bshore <[email protected]>
  • Loading branch information
bshore authored Feb 10, 2023
1 parent 53d7a76 commit dcc0d08
Show file tree
Hide file tree
Showing 60 changed files with 38 additions and 29 deletions.
23 changes: 11 additions & 12 deletions internal/engine/buildcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/tilt-dev/tilt/internal/container"
"github.com/tilt-dev/tilt/internal/controllers/apis/uibutton"
"github.com/tilt-dev/tilt/internal/hud/server"
"github.com/tilt-dev/tilt/internal/k8s"
"github.com/tilt-dev/tilt/internal/k8s/testyaml"
"github.com/tilt-dev/tilt/internal/store"
Expand Down Expand Up @@ -72,7 +71,7 @@ func TestBuildControllerManualTriggerBuildReasonInit(t *testing.T) {

// make sure there's a first build
if !manifest.TriggerMode.AutoInitial() {
f.store.Dispatch(server.AppendToTriggerQueueAction{Name: mName})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: mName})
}

f.nextCallComplete()
Expand Down Expand Up @@ -169,7 +168,7 @@ func TestBuildControllerImageBuildTrigger(t *testing.T) {
f.assertNoCall("even tho there are pending changes, manual manifest shouldn't build w/o explicit trigger")
}

f.store.Dispatch(server.AppendToTriggerQueueAction{Name: mName})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: mName})
call := f.nextCallComplete()
state := call.oneImageState()
assert.Equal(t, expectedFiles, state.FilesChanged())
Expand Down Expand Up @@ -222,11 +221,11 @@ func TestBuildQueueOrdering(t *testing.T) {
})
f.assertNoCall("even tho there are pending changes, manual manifest shouldn't build w/o explicit trigger")

f.store.Dispatch(server.AppendToTriggerQueueAction{Name: "manifest1"})
f.store.Dispatch(server.AppendToTriggerQueueAction{Name: "manifest2"})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: "manifest1"})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: "manifest2"})
time.Sleep(10 * time.Millisecond)
f.store.Dispatch(server.AppendToTriggerQueueAction{Name: "manifest3"})
f.store.Dispatch(server.AppendToTriggerQueueAction{Name: "manifest4"})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: "manifest3"})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: "manifest4"})

for i := range manifests {
expName := fmt.Sprintf("manifest%d", i+1)
Expand Down Expand Up @@ -278,13 +277,13 @@ func TestBuildQueueAndAutobuildOrdering(t *testing.T) {
})
f.assertNoCall("even tho there are pending changes, manual manifest shouldn't build w/o explicit trigger")

f.store.Dispatch(server.AppendToTriggerQueueAction{Name: "manifest1"})
f.store.Dispatch(server.AppendToTriggerQueueAction{Name: "manifest2"})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: "manifest1"})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: "manifest2"})
// make our one auto-trigger manifest build - should be evaluated LAST, after
// all the manual manifests waiting in the queue
f.fsWatcher.Events <- watch.NewFileEvent(f.JoinPath("dirAuto/main.go"))
f.store.Dispatch(server.AppendToTriggerQueueAction{Name: "manifest3"})
f.store.Dispatch(server.AppendToTriggerQueueAction{Name: "manifest4"})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: "manifest3"})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: "manifest4"})

for i := range manifests {
call := f.nextCall()
Expand Down Expand Up @@ -904,7 +903,7 @@ func TestManifestsWithCommonAncestorAndTrigger(t *testing.T) {
call = f.nextCall("m2 build1")
assert.Equal(t, m2.K8sTarget(), call.k8s())

f.store.Dispatch(server.AppendToTriggerQueueAction{Name: m1.Name})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: m1.Name})
f.waitForCompletedBuildCount(3)

// Make sure that only one build was triggered.
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/upper.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ func upperReducerFn(ctx context.Context, state *store.EngineState, action store.
ctrltiltfile.HandleConfigsReloadStarted(ctx, state, action)
case ctrltiltfile.ConfigsReloadedAction:
ctrltiltfile.HandleConfigsReloaded(ctx, state, action)
case server.AppendToTriggerQueueAction:
state.AppendToTriggerQueue(action.Name, action.Reason)
case hud.DumpEngineStateAction:
handleDumpEngineStateAction(ctx, state)
case store.AnalyticsUserOptAction:
Expand All @@ -160,6 +158,8 @@ func upperReducerFn(ctx context.Context, state *store.EngineState, action store.
handlePanicAction(state, action)
case store.LogAction:
handleLogAction(state, action)
case store.AppendToTriggerQueueAction:
state.AppendToTriggerQueue(action.Name, action.Reason)
case sessions.SessionStatusUpdateAction:
sessions.HandleSessionStatusUpdateAction(state, action)
case prompt.SwitchTerminalModeAction:
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/upper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,7 @@ func TestHandleTiltfileTriggerQueue(t *testing.T) {
assert.Equal(t, model.BuildReasonNone, st.MainTiltfileState().TriggerReason,
"initial state should not have Tiltfile trigger reason")
})
action := server.AppendToTriggerQueueAction{Name: model.MainTiltfileManifestName, Reason: 123}
action := store.AppendToTriggerQueueAction{Name: model.MainTiltfileManifestName, Reason: 123}
f.store.Dispatch(action)

f.WaitUntil("Tiltfile trigger processed", func(st store.EngineState) bool {
Expand Down Expand Up @@ -3076,7 +3076,7 @@ func TestDisabledResourceRemovedFromTriggerQueue(t *testing.T) {

f.bc.DisableForTesting()

f.store.Dispatch(server.AppendToTriggerQueueAction{Name: m.Name, Reason: model.BuildReasonFlagTriggerCLI})
f.store.Dispatch(store.AppendToTriggerQueueAction{Name: m.Name, Reason: model.BuildReasonFlagTriggerCLI})

f.WaitUntil("in trigger queue", func(state store.EngineState) bool {
return state.ManifestInTriggerQueue(m.Name)
Expand Down
4 changes: 4 additions & 0 deletions internal/hud/hud.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ func (h *Hud) handleScreenEvent(ctx context.Context, dispatch func(action store.
escape()
case r == 'R': // hidden key for recovering from printf junk during demos
h.r.screen.Sync()
case r == 't': // [T]rigger resource update
_, selected := h.selectedResource()
h.recordInteraction("trigger_resource")
dispatch(store.AppendToTriggerQueueAction{Name: selected.Name, Reason: model.BuildReasonFlagTriggerHUD})
case r == 'x':
h.recordInteraction("cycle_view_log_state")
h.currentViewState.CycleViewLogState()
Expand Down
2 changes: 2 additions & 0 deletions internal/hud/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func renderPaneHeader(isMax bool) rty.Component {
l := rty.NewLine()
l.Add(rty.NewFillerString(' '))
l.Add(rty.TextString(fmt.Sprintf(" %s ", s)))
l.Add(rty.TextString("| "))
l.Add(rty.TextString("t: trigger update"))
return l
}

Expand Down
7 changes: 0 additions & 7 deletions internal/hud/server/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import (
"github.com/tilt-dev/tilt/pkg/model"
)

type AppendToTriggerQueueAction struct {
Name model.ManifestName
Reason model.BuildReason
}

func (AppendToTriggerQueueAction) Action() {}

// TODO: a way to clear an override
type OverrideTriggerModeAction struct {
ManifestNames []model.ManifestName
Expand Down
2 changes: 1 addition & 1 deletion internal/hud/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (s *HeadsUpServer) HandleTrigger(w http.ResponseWriter, req *http.Request)
} else if ms != nil && ms.DisableState == v1alpha1.DisableStateDisabled {
_, _ = fmt.Fprintf(w, "resource %q is currently disabled", mn)
} else {
s.store.Dispatch(AppendToTriggerQueueAction{Name: mn, Reason: payload.BuildReason})
s.store.Dispatch(store.AppendToTriggerQueueAction{Name: mn, Reason: payload.BuildReason})
}
}

Expand Down
10 changes: 5 additions & 5 deletions internal/hud/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ func TestHandleTriggerTiltfileOK(t *testing.T) {
assert.Equal(t, "", resp)
assert.Equal(t, http.StatusOK, status)

a := store.WaitForAction(t, reflect.TypeOf(server.AppendToTriggerQueueAction{}), f.getActions)
action, ok := a.(server.AppendToTriggerQueueAction)
a := store.WaitForAction(t, reflect.TypeOf(store.AppendToTriggerQueueAction{}), f.getActions)
action, ok := a.(store.AppendToTriggerQueueAction)
if !ok {
t.Fatalf("Action was not of type 'AppendToTriggreQueueAction': %+v", action)
}

expected := server.AppendToTriggerQueueAction{
expected := store.AppendToTriggerQueueAction{
Name: model.MainTiltfileManifestName,
Reason: model.BuildReasonFlagTriggerWeb,
}
Expand Down Expand Up @@ -212,8 +212,8 @@ func TestHandleTriggerNonTiltfileManifest(t *testing.T) {
assert.Equal(t, "", resp)
assert.Equal(t, http.StatusOK, status)

a := store.WaitForAction(t, reflect.TypeOf(server.AppendToTriggerQueueAction{}), f.getActions)
action, ok := a.(server.AppendToTriggerQueueAction)
a := store.WaitForAction(t, reflect.TypeOf(store.AppendToTriggerQueueAction{}), f.getActions)
action, ok := a.(store.AppendToTriggerQueueAction)
if !ok {
t.Fatalf("Action was not of type 'AppendToTriggerQueueAction': %+v", action)
}
Expand Down
Binary file modified internal/hud/testdata/Completed is a good status.gob
Binary file not shown.
Binary file modified internal/hud/testdata/Tiltfile resource first run.gob
Binary file not shown.
Binary file modified internal/hud/testdata/Tiltfile resource no run.gob
Binary file not shown.
Binary file modified internal/hud/testdata/Tiltfile resource pending.gob
Binary file not shown.
Binary file modified internal/hud/testdata/Tiltfile resource with warning.gob
Binary file not shown.
Binary file modified internal/hud/testdata/alert message.gob
Binary file not shown.
Binary file modified internal/hud/testdata/all the data at once 10w.gob
Binary file not shown.
Binary file modified internal/hud/testdata/all the data at once 50w.gob
Binary file not shown.
Binary file modified internal/hud/testdata/all the data at once.gob
Binary file not shown.
Binary file modified internal/hud/testdata/build in progress.gob
Binary file not shown.
Binary file modified internal/hud/testdata/collapse-auto-bad.gob
Binary file not shown.
Binary file modified internal/hud/testdata/collapse-auto-good.gob
Binary file not shown.
Binary file modified internal/hud/testdata/collapse-no-good.gob
Binary file not shown.
Binary file modified internal/hud/testdata/collapse-yes-bad.gob
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified internal/hud/testdata/docker-compose up expanded.gob
Binary file not shown.
Binary file modified internal/hud/testdata/edited files narrow term.gob
Binary file not shown.
Binary file modified internal/hud/testdata/edited files normal term.gob
Binary file not shown.
Binary file modified internal/hud/testdata/edited files wide term.gob
Binary file not shown.
Binary file modified internal/hud/testdata/escaped nbsp.gob
Binary file not shown.
Binary file modified internal/hud/testdata/failed build local resource.gob
Binary file not shown.
Binary file modified internal/hud/testdata/finished local resource.gob
Binary file not shown.
Binary file modified internal/hud/testdata/inline build log with wrapping.gob
Binary file not shown.
Binary file modified internal/hud/testdata/inline build log.gob
Binary file not shown.
Binary file modified internal/hud/testdata/line wrapping in inline error.gob
Binary file not shown.
Binary file modified internal/hud/testdata/local resource errored serve.gob
Binary file not shown.
Binary file modified internal/hud/testdata/log tab build.gob
Binary file not shown.
Binary file modified internal/hud/testdata/log tab default.gob
Binary file not shown.
Binary file modified internal/hud/testdata/log tab pod.gob
Binary file not shown.
Binary file modified internal/hud/testdata/manifest error and build error.gob
Binary file not shown.
Binary file modified internal/hud/testdata/multiple build history entries.gob
Binary file not shown.
Binary file modified internal/hud/testdata/narration message.gob
Binary file not shown.
Binary file modified internal/hud/testdata/no collapse unresourced yaml manifest.gob
Binary file not shown.
Binary file not shown.
Binary file modified internal/hud/testdata/one undeployed resource.gob
Binary file not shown.
Binary file modified internal/hud/testdata/pending build with manual trigger.gob
Binary file not shown.
Binary file modified internal/hud/testdata/pending build.gob
Binary file not shown.
Binary file modified internal/hud/testdata/pending pod no status.gob
Binary file not shown.
Binary file modified internal/hud/testdata/pending pod pending status.gob
Binary file not shown.
Binary file modified internal/hud/testdata/pod log displayed inline.gob
Binary file not shown.
Binary file modified internal/hud/testdata/pod log with inline wrapping.gob
Binary file not shown.
Binary file not shown.
Binary file modified internal/hud/testdata/text in brackets.gob
Binary file not shown.
Binary file modified internal/hud/testdata/tilt log full screen.gob
Binary file not shown.
Binary file modified internal/hud/testdata/tilt log half screen.gob
Binary file not shown.
Binary file modified internal/hud/testdata/tilt log.gob
Binary file not shown.
Binary file modified internal/hud/testdata/unfinished local resource.gob
Binary file not shown.
7 changes: 7 additions & 0 deletions internal/store/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,10 @@ type PanicAction struct {
}

func (PanicAction) Action() {}

type AppendToTriggerQueueAction struct {
Name model.ManifestName
Reason model.BuildReason
}

func (AppendToTriggerQueueAction) Action() {}
4 changes: 4 additions & 0 deletions pkg/model/build_reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (

BuildReasonFlagTriggerWeb
BuildReasonFlagTriggerCLI
BuildReasonFlagTriggerHUD
BuildReasonFlagTriggerUnknown

// An external process called `tilt args`
Expand Down Expand Up @@ -73,6 +74,7 @@ var translations = map[BuildReason]string{
BuildReasonFlagInit: "Initial Build",
BuildReasonFlagTriggerWeb: "Web Trigger",
BuildReasonFlagTriggerCLI: "CLI Trigger",
BuildReasonFlagTriggerHUD: "HUD Trigger",
BuildReasonFlagTriggerUnknown: "Unknown Trigger",
BuildReasonFlagTiltfileArgs: "Tilt Args",
BuildReasonFlagChangedDeps: "Dependency Updated",
Expand All @@ -81,6 +83,7 @@ var translations = map[BuildReason]string{
var triggerBuildReasons = []BuildReason{
BuildReasonFlagTriggerWeb,
BuildReasonFlagTriggerCLI,
BuildReasonFlagTriggerHUD,
BuildReasonFlagTriggerUnknown,
}

Expand All @@ -91,6 +94,7 @@ var allBuildReasons = []BuildReason{
BuildReasonFlagCrashDeprecated,
BuildReasonFlagTriggerWeb,
BuildReasonFlagTriggerCLI,
BuildReasonFlagTriggerHUD,
BuildReasonFlagChangedDeps,
BuildReasonFlagTriggerUnknown,
BuildReasonFlagTiltfileArgs,
Expand Down

0 comments on commit dcc0d08

Please sign in to comment.