downloadGoModFile run go mod commands to download dependencies
(b *buildingMaterial)
| 211 | |
| 212 | // downloadGoModFile run go mod commands to download dependencies |
| 213 | func downloadGoModFile(b *buildingMaterial) (err error) { |
| 214 | answerReplacement := b.answerModuleReplacement |
| 215 | |
| 216 | // If no replacement specified and current binary is v2+, auto-determine replacement. |
| 217 | // This is needed because go mod tidy would otherwise resolve github.com/apache/answer |
| 218 | // to the latest v1.x version, causing v2+ features (e.g. AI/MCP) to disappear. |
| 219 | if len(answerReplacement) == 0 && b.originalAnswerInfo.Version != "" { |
| 220 | ver, verErr := semver.NewVersion(strings.TrimPrefix(b.originalAnswerInfo.Version, "v")) |
| 221 | if verErr == nil && ver.Major() >= 2 { |
| 222 | answerReplacement = fmt.Sprintf("github.com/apache/answer@%s", b.originalAnswerInfo.Version) |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | if len(answerReplacement) > 0 { |
| 227 | // For v2+ versioned module paths (e.g. github.com/apache/answer@v2.0.0), |
| 228 | // go mod tidy rejects the version because the module path lacks a /v2 suffix. |
| 229 | // Work around this by cloning the repo locally and using a local path replacement. |
| 230 | localPath, resolveErr := resolveAnswerModuleReplacement(answerReplacement, b.tmpDir) |
| 231 | if resolveErr != nil { |
| 232 | return resolveErr |
| 233 | } |
| 234 | replacement := fmt.Sprintf("%s=%s", "github.com/apache/answer", localPath) |
| 235 | err = b.newExecCmd("go", "mod", "edit", "-replace", replacement).Run() |
| 236 | if err != nil { |
| 237 | return err |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | err = b.newExecCmd("go", "mod", "tidy").Run() |
| 242 | if err != nil { |
| 243 | return err |
| 244 | } |
| 245 | |
| 246 | err = b.newExecCmd("go", "mod", "vendor").Run() |
| 247 | if err != nil { |
| 248 | return err |
| 249 | } |
| 250 | return |
| 251 | } |
| 252 | |
| 253 | // resolveAnswerModuleReplacement resolves the ANSWER_MODULE value to a usable local path or |
| 254 | // remote replacement string. For v2+ versioned module paths (e.g. github.com/apache/answer@v2.0.0), |
nothing calls this directly
no test coverage detected