DetectLanguage detects the language of the test command and returns the executable
(logger *zap.Logger, cmd string)
| 1220 | |
| 1221 | // DetectLanguage detects the language of the test command and returns the executable |
| 1222 | func DetectLanguage(logger *zap.Logger, cmd string) (models.Language, string) { |
| 1223 | if cmd == "" { |
| 1224 | return models.Unknown, "" |
| 1225 | } |
| 1226 | fields := strings.Fields(cmd) |
| 1227 | |
| 1228 | // Find the actual executable by skipping environment variable assignments |
| 1229 | executable := "" |
| 1230 | for _, field := range fields { |
| 1231 | // Skip environment variable assignments (KEY=VALUE format) |
| 1232 | if strings.Contains(field, "=") && !strings.HasPrefix(field, "/") { |
| 1233 | continue |
| 1234 | } |
| 1235 | // This is the actual executable |
| 1236 | executable = field |
| 1237 | break |
| 1238 | } |
| 1239 | |
| 1240 | if executable == "" { |
| 1241 | return models.Unknown, "" |
| 1242 | } |
| 1243 | |
| 1244 | // Check for Python |
| 1245 | pythonRegex := regexp.MustCompile(`(?i)(^|.*/)(python(\d+(\.\d+)*)?)$`) |
| 1246 | if pythonRegex.MatchString(executable) { |
| 1247 | return models.Python, executable |
| 1248 | } |
| 1249 | |
| 1250 | // Check for Node.js |
| 1251 | if executable == "node" || executable == "npm" || executable == "yarn" { |
| 1252 | return models.Javascript, executable |
| 1253 | } |
| 1254 | |
| 1255 | // Check for Java |
| 1256 | if executable == "java" { |
| 1257 | return models.Java, executable |
| 1258 | } |
| 1259 | |
| 1260 | // Check for Go |
| 1261 | if executable == "go" || (isGoBinary(logger, executable)) { |
| 1262 | return models.Go, executable |
| 1263 | } |
| 1264 | |
| 1265 | return models.Unknown, executable |
| 1266 | } |
| 1267 | |
| 1268 | // FileExists checks if a file exists and is not a directory at the given path. |
| 1269 | func FileExists(path string) (bool, error) { |