matchWorkflowFilenameByExperiment returns the basename (without .md) of the first file in filenames whose sanitized name matches experimentName. Returns "" when no match is found. Logs a warning when more than one file maps to the same sanitized name.
(filenames []string, experimentName string)
| 435 | // filenames whose sanitized name matches experimentName. Returns "" when no match is found. |
| 436 | // Logs a warning when more than one file maps to the same sanitized name. |
| 437 | func matchWorkflowFilenameByExperiment(filenames []string, experimentName string) string { |
| 438 | var matches []string |
| 439 | for _, filename := range filenames { |
| 440 | base := strings.TrimSuffix(filename, ".md") |
| 441 | if workflow.SanitizeWorkflowIDForCacheKey(base) == experimentName { |
| 442 | matches = append(matches, base) |
| 443 | } |
| 444 | } |
| 445 | if len(matches) == 0 { |
| 446 | return "" |
| 447 | } |
| 448 | if len(matches) > 1 { |
| 449 | experimentsLog.Printf("Ambiguous experiment name %q: multiple workflow files match (%s); using first", experimentName, strings.Join(matches, ", ")) |
| 450 | } |
| 451 | return matches[0] |
| 452 | } |
| 453 | |
| 454 | // findWorkflowFileForExperiment scans .github/workflows/ for a .md file whose sanitized |
| 455 | // basename (lowercase, hyphens removed) matches the given experiment name. |