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

Function GenerateAutoUpdateWorkflow

pkg/workflow/auto_update_workflow.go:66–123  ·  view source on GitHub ↗

GenerateAutoUpdateWorkflow generates or removes the agentic-auto-upgrade.yml workflow based on whether auto-updates are enabled in the repository's aw.json. When enabled, it generates a workflow that runs on a fuzzy weekly schedule and inlines the upgrade operation JavaScript to check for and repor

(opts GenerateAutoUpdateWorkflowOptions)

Source from the content-addressed store, hash-verified

64// When disabled (or when maintenance is disabled), any existing agentic-auto-upgrade.yml
65// is deleted.
66func GenerateAutoUpdateWorkflow(opts GenerateAutoUpdateWorkflowOptions) error {
67 outputFile := filepath.Join(opts.WorkflowDir, AutoUpdateWorkflowFileName)
68
69 if !opts.Enabled {
70 autoUpdateWorkflowLog.Print("Auto-updates not enabled, removing agentic-auto-upgrade.yml if present")
71 if _, err := os.Stat(outputFile); err == nil {
72 autoUpdateWorkflowLog.Printf("Deleting existing auto-upgrade workflow: %s", outputFile)
73 if err := os.Remove(outputFile); err != nil {
74 return fmt.Errorf("failed to delete auto-upgrade workflow: %w", err)
75 }
76 autoUpdateWorkflowLog.Print("Auto-upgrade workflow deleted successfully")
77 }
78 return nil
79 }
80
81 seed := buildAutoUpdateSeed(opts.RepoSlug)
82 cronSchedule, err := parser.ScatterSchedule("FUZZY:WEEKLY", seed)
83 if err != nil {
84 return fmt.Errorf("failed to scatter FUZZY:WEEKLY schedule for auto-update workflow: %w", err)
85 }
86 autoUpdateWorkflowLog.Printf("Scattered FUZZY:WEEKLY to %q for seed %q", cronSchedule, seed)
87
88 setupActionRef := opts.SetupActionRef
89 if setupActionRef == "" {
90 setupActionRef = "./actions/setup"
91 }
92 githubScriptPin := opts.GitHubScriptPin
93 if githubScriptPin == "" {
94 githubScriptPin = getActionPin("actions/github-script")
95 }
96
97 actionMode := opts.ActionMode
98 if actionMode == "" {
99 actionMode = ActionModeDev
100 }
101 ctx := opts.Context
102 if ctx == nil {
103 ctx = context.Background()
104 }
105 content := buildAutoUpdateWorkflowYAML(
106 cronSchedule,
107 setupActionRef,
108 githubScriptPin,
109 generateInstallCLISteps(ctx, actionMode, opts.Version, opts.ActionTag, opts.Resolver),
110 getCLICmdPrefix(actionMode),
111 )
112
113 autoUpdateWorkflowLog.Printf("Writing auto-update workflow to %s", outputFile)
114 if err := fileutil.EnsureParentDir(outputFile, constants.DirPermPublic); err != nil {
115 return fmt.Errorf("failed to create auto-update workflow directory: %w", err)
116 }
117 if err := os.WriteFile(outputFile, []byte(content), constants.FilePermPublic); err != nil {
118 return fmt.Errorf("failed to write auto-update workflow: %w", err)
119 }
120
121 autoUpdateWorkflowLog.Print("Auto-update workflow generated successfully")
122 return nil
123}

Calls 11

ScatterScheduleFunction · 0.92
EnsureParentDirFunction · 0.92
buildAutoUpdateSeedFunction · 0.85
getActionPinFunction · 0.85
generateInstallCLIStepsFunction · 0.85
getCLICmdPrefixFunction · 0.85
PrintMethod · 0.80
BackgroundMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45