dependencyExample demonstrates plan with step dependencies
()
| 125 | |
| 126 | // dependencyExample demonstrates plan with step dependencies |
| 127 | func dependencyExample() { |
| 128 | plan := executionplan.NewExecutionPlan("Build and test project") |
| 129 | |
| 130 | // Step 1: Install dependencies |
| 131 | step1 := plan.AddStep("install", "Install project dependencies", map[string]any{ |
| 132 | "command": "go mod download", |
| 133 | }) |
| 134 | |
| 135 | // Step 2: Build (depends on step 1) |
| 136 | step2 := plan.AddStep("build", "Build the project", map[string]any{ |
| 137 | "command": "go build ./...", |
| 138 | }) |
| 139 | step2.DependsOn = []string{step1.ID} |
| 140 | |
| 141 | // Step 3: Run tests (depends on step 2) |
| 142 | step3 := plan.AddStep("test", "Run unit tests", map[string]any{ |
| 143 | "command": "go test ./...", |
| 144 | }) |
| 145 | step3.DependsOn = []string{step2.ID} |
| 146 | |
| 147 | // Step 4: Run linter (depends on step 1, can run parallel with build/test) |
| 148 | step4 := plan.AddStep("lint", "Run linter checks", map[string]any{ |
| 149 | "command": "golangci-lint run", |
| 150 | }) |
| 151 | step4.DependsOn = []string{step1.ID} |
| 152 | |
| 153 | fmt.Println(executionplan.FormatPlan(plan)) |
| 154 | |
| 155 | // Show dependency graph |
| 156 | fmt.Println("Dependency Graph:") |
| 157 | for _, step := range plan.Steps { |
| 158 | deps := "none" |
| 159 | if len(step.DependsOn) > 0 { |
| 160 | deps = fmt.Sprintf("%v", step.DependsOn) |
| 161 | } |
| 162 | fmt.Printf(" %s (deps: %s)\n", step.ToolName, deps) |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // MockTool is a simple mock tool for demonstration |
| 167 | type MockTool struct { |
no test coverage detected