Skip to content

Commit b382060

Browse files
wbrezaCopilot
andcommitted
fix: scope tool middleware to workflow commands and add CI detection
- Add resource.IsRunningOnCI() check to both tool middlewares, matching the pattern used by LoginGuardMiddleware - Change middleware predicates from blocklist to allowlist of workflow commands (init, up, deploy, provision, build, package, restore, publish, down, monitor, add) - Utility commands (auth, config, env, show, etc.) no longer trigger the first-run experience or update notifications Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 674f192 commit b382060

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

cli/azd/cmd/middleware/tool_first_run.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/azure/azure-dev/cli/azd/cmd/actions"
1616
"github.com/azure/azure-dev/cli/azd/internal"
17+
"github.com/azure/azure-dev/cli/azd/internal/tracing/resource"
1718
"github.com/azure/azure-dev/cli/azd/pkg/config"
1819
"github.com/azure/azure-dev/cli/azd/pkg/input"
1920
"github.com/azure/azure-dev/cli/azd/pkg/output"
@@ -92,12 +93,17 @@ func (m *ToolFirstRunMiddleware) shouldSkip(ctx context.Context) bool {
9293
return true
9394
}
9495

95-
// 3. Non-interactive terminal (piped stdin/stdout).
96+
// 3. CI/CD environment — never prompt in CI.
97+
if resource.IsRunningOnCI() {
98+
return true
99+
}
100+
101+
// 4. Non-interactive terminal (piped stdin/stdout).
96102
if m.console.IsNoPromptMode() {
97103
return true
98104
}
99105

100-
// 4. Already completed.
106+
// 5. Already completed.
101107
cfg, err := m.configManager.Load()
102108
if err != nil {
103109
log.Printf("tool first-run: failed to load user config: %v", err)

cli/azd/cmd/middleware/tool_update_check.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/azure/azure-dev/cli/azd/cmd/actions"
1515
"github.com/azure/azure-dev/cli/azd/internal"
16+
"github.com/azure/azure-dev/cli/azd/internal/tracing/resource"
1617
"github.com/azure/azure-dev/cli/azd/pkg/input"
1718
"github.com/azure/azure-dev/cli/azd/pkg/output"
1819
"github.com/azure/azure-dev/cli/azd/pkg/tool"
@@ -104,6 +105,11 @@ func (m *ToolUpdateCheckMiddleware) shouldSkipNotification() bool {
104105
return true
105106
}
106107

108+
// CI/CD environment — no notifications.
109+
if resource.IsRunningOnCI() {
110+
return true
111+
}
112+
107113
// Machine-readable output (JSON, table, etc.) — keep stdout clean.
108114
if !m.console.IsUnformatted() {
109115
return true
@@ -140,6 +146,11 @@ func (m *ToolUpdateCheckMiddleware) triggerBackgroundCheckIfNeeded(ctx context.C
140146
return
141147
}
142148

149+
// CI/CD environment — skip background checks.
150+
if resource.IsRunningOnCI() {
151+
return
152+
}
153+
143154
if !m.manager.ShouldCheckForUpdates(ctx) {
144155
return
145156
}

cli/azd/cmd/root.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,18 +459,14 @@ func newRootCmd(
459459
"toolFirstRun",
460460
middleware.NewToolFirstRunMiddleware,
461461
func(descriptor *actions.ActionDescriptor) bool {
462-
cmd := descriptor.Options.Command
463-
return !strings.HasPrefix(cmd.CommandPath(), "azd tool") &&
464-
cmd.Name() != "version" && cmd.Name() != "config"
462+
return isWorkflowCommand(descriptor)
465463
},
466464
).
467465
UseMiddlewareWhen(
468466
"toolUpdateCheck",
469467
middleware.NewToolUpdateCheckMiddleware,
470468
func(descriptor *actions.ActionDescriptor) bool {
471-
cmd := descriptor.Options.Command
472-
return !strings.HasPrefix(cmd.CommandPath(), "azd tool") &&
473-
cmd.Name() != "version" && cmd.Name() != "config"
469+
return isWorkflowCommand(descriptor)
474470
},
475471
)
476472

@@ -547,6 +543,33 @@ func newRootCmd(
547543
return cmd
548544
}
549545

546+
// isWorkflowCommand reports whether the command is a primary workflow
547+
// command where a first-run tool check adds value. Utility commands
548+
// (auth, config, env, show, etc.) are excluded so they are never
549+
// blocked by the first-run experience or update notifications.
550+
func isWorkflowCommand(descriptor *actions.ActionDescriptor) bool {
551+
workflowCommands := map[string]bool{
552+
"init": true,
553+
"up": true,
554+
"deploy": true,
555+
"provision": true,
556+
"build": true,
557+
"package": true,
558+
"restore": true,
559+
"publish": true,
560+
"down": true,
561+
"monitor": true,
562+
"add": true,
563+
}
564+
565+
// Walk up to the root-level subcommand (first segment after "azd").
566+
cmd := descriptor.Options.Command
567+
for cmd.Parent() != nil && cmd.Parent().Parent() != nil {
568+
cmd = cmd.Parent()
569+
}
570+
return workflowCommands[cmd.Name()]
571+
}
572+
550573
func getCmdRootHelpFooter(cmd *cobra.Command) string {
551574
return fmt.Sprintf("%s\n%s\n%s\n\n%s\n\n%s",
552575
output.WithBold("%s", output.WithUnderline("Deploying a sample application")),

0 commit comments

Comments
 (0)