MCPcopy Create free account
hub / github.com/github/gh-aw / updateActionsInWorkflowFiles

Function updateActionsInWorkflowFiles

pkg/cli/update_actions.go:606–684  ·  view source on GitHub ↗
(ctx context.Context, deps actionUpdateDeps, workflowsDir, engineOverride string, verbose, disableReleaseBump bool, noCompile bool, coolDown time.Duration)

Source from the content-addressed store, hash-verified

604}
605
606func updateActionsInWorkflowFiles(ctx context.Context, deps actionUpdateDeps, workflowsDir, engineOverride string, verbose, disableReleaseBump bool, noCompile bool, coolDown time.Duration) error {
607 if workflowsDir == "" {
608 workflowsDir = getWorkflowsDir()
609 }
610
611 updateLog.Printf("Updating action references in workflow files: dir=%s", workflowsDir)
612
613 // Per-invocation cache: key = "repo@currentVersion", avoids repeated API calls
614 cache := make(map[string]latestReleaseResult)
615 // Per-invocation cooldown cache: key = "repo@tag", avoids redundant date API calls
616 coolDownCache := make(map[string]coolDownCheckResult)
617
618 var updatedFiles []string
619
620 err := filepath.WalkDir(workflowsDir, func(path string, d os.DirEntry, walkErr error) error {
621 if walkErr != nil {
622 return walkErr
623 }
624 if ctx.Err() != nil {
625 return ctx.Err()
626 }
627 if d.IsDir() || !strings.HasSuffix(d.Name(), ".md") {
628 return nil
629 }
630
631 content, err := os.ReadFile(path)
632 if err != nil {
633 if verbose {
634 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to read %s: %v", path, err)))
635 }
636 return nil
637 }
638
639 updatedActions, newContent, err := updateActionRefsInContentWithDeps(ctx, deps, string(content), cache, coolDownCache, !disableReleaseBump, verbose, coolDown)
640 if err != nil {
641 if verbose {
642 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to update action refs in %s: %v", path, err)))
643 }
644 return nil
645 }
646 updatedSkills, newContent, err := updateSkillRefsInContent(ctx, newContent, !disableReleaseBump, verbose, coolDown)
647 if err != nil {
648 if verbose {
649 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to update skill refs in %s: %v", path, err)))
650 }
651 return nil
652 }
653
654 if !updatedActions && !updatedSkills {
655 return nil
656 }
657
658 if err := os.WriteFile(path, []byte(newContent), constants.FilePermPublic); err != nil {
659 return fmt.Errorf("failed to write updated workflow %s: %w", path, err)
660 }
661
662 fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Updated action/skill references in "+d.Name()))
663 updatedFiles = append(updatedFiles, path)

Calls 9

FormatWarningMessageFunction · 0.92
FormatSuccessMessageFunction · 0.92
FormatInfoMessageFunction · 0.92
getWorkflowsDirFunction · 0.85
updateSkillRefsInContentFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45