loadRemoteExperimentConfigs fetches the workflow .md file from the repository default branch via the GitHub API and returns the ExperimentConfig map from its frontmatter. Returns nil when the file cannot be fetched or parsed.
(repoOverride, experimentName string)
| 353 | // via the GitHub API and returns the ExperimentConfig map from its frontmatter. |
| 354 | // Returns nil when the file cannot be fetched or parsed. |
| 355 | func loadRemoteExperimentConfigs(repoOverride, experimentName string) map[string]*workflow.ExperimentConfig { |
| 356 | experimentsLog.Printf("Loading remote experiment configs for %s from %s", experimentName, repoOverride) |
| 357 | |
| 358 | // Build the candidate list. First, use the directory listing to find the exact filename |
| 359 | // whose sanitized basename matches experimentName (e.g. "ci-coach" for "cicoach"). |
| 360 | // Fall back to the bare experiment name if the listing is unavailable. |
| 361 | candidates := workflowFileCandidates(experimentName) |
| 362 | if resolved := findRemoteWorkflowFilenameForExperiment(repoOverride, experimentName); resolved != "" && resolved != experimentName { |
| 363 | // Prepend the resolved name so it is tried before the bare sanitized form. |
| 364 | // Skip when resolved == experimentName to avoid a redundant fetch. |
| 365 | candidates = append([]string{resolved}, candidates...) |
| 366 | } |
| 367 | |
| 368 | for _, candidate := range candidates { |
| 369 | apiPath := constants.WorkflowsDirSlash + candidate + ".md" |
| 370 | args := []string{"api", |
| 371 | "repos/{owner}/{repo}/contents/" + url.PathEscape(apiPath), |
| 372 | "--jq", ".content", |
| 373 | "--repo", repoOverride, |
| 374 | } |
| 375 | cmd := workflow.ExecGH(args...) |
| 376 | out, err := cmd.Output() |
| 377 | if err != nil { |
| 378 | continue |
| 379 | } |
| 380 | |
| 381 | b64 := strings.Join(strings.Fields(strings.TrimSpace(string(out))), "") |
| 382 | decoded, err := base64.StdEncoding.DecodeString(b64) |
| 383 | if err != nil { |
| 384 | experimentsLog.Printf("Failed to base64-decode workflow file %s: %v", candidate, err) |
| 385 | continue |
| 386 | } |
| 387 | |
| 388 | result, err := parser.ExtractFrontmatterFromContent(string(decoded)) |
| 389 | if err != nil { |
| 390 | continue |
| 391 | } |
| 392 | |
| 393 | cfg, err := workflow.ParseFrontmatterConfig(result.Frontmatter) |
| 394 | if err != nil { |
| 395 | continue |
| 396 | } |
| 397 | |
| 398 | if len(cfg.ExperimentConfigs) > 0 { |
| 399 | experimentsLog.Printf("Loaded remote configs from %s", apiPath) |
| 400 | return cfg.ExperimentConfigs |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | experimentsLog.Printf("No remote workflow file found for experiment %s", experimentName) |
| 405 | return nil |
| 406 | } |
| 407 | |
| 408 | // findRemoteWorkflowFilenameForExperiment lists .md files in .github/workflows/ via the |
| 409 | // GitHub API and returns the basename (without .md) of the first file whose sanitized name |
no test coverage detected