buildMaintenanceWorkflowYAML generates the complete YAML content for the agentics-maintenance.yml workflow. It is called by GenerateMaintenanceWorkflow after the cron schedule and setup parameters have been resolved.
( ctx context.Context, opts buildMaintenanceWorkflowYAMLOptions, )
| 32 | // agentics-maintenance.yml workflow. It is called by GenerateMaintenanceWorkflow |
| 33 | // after the cron schedule and setup parameters have been resolved. |
| 34 | func buildMaintenanceWorkflowYAML( |
| 35 | ctx context.Context, |
| 36 | opts buildMaintenanceWorkflowYAMLOptions, |
| 37 | ) string { |
| 38 | cronSchedule := opts.cronSchedule |
| 39 | scheduleDesc := opts.scheduleDesc |
| 40 | minExpiresDays := opts.minExpiresDays |
| 41 | runsOnValue := opts.runsOnValue |
| 42 | actionMode := opts.actionMode |
| 43 | version := opts.version |
| 44 | actionTag := opts.actionTag |
| 45 | resolver := opts.resolver |
| 46 | configuredRunsOn := opts.configuredRunsOn |
| 47 | defaultBranch := opts.defaultBranch |
| 48 | disableLabelTrigger := opts.disableLabelTrigger |
| 49 | compileGitHubToken := opts.compileGitHubToken |
| 50 | createCompilePR := opts.createCompilePR |
| 51 | copilotOrgBilling := opts.copilotOrgBilling |
| 52 | maintenanceWorkflowYAMLLog.Printf("Building maintenance workflow YAML: actionMode=%s minExpiresDays=%d cronSchedule=%q defaultBranch=%q disableLabelTrigger=%v createCompilePR=%v copilotOrgBilling=%v", actionMode, minExpiresDays, cronSchedule, defaultBranch, disableLabelTrigger, createCompilePR, copilotOrgBilling) |
| 53 | |
| 54 | var yaml strings.Builder |
| 55 | |
| 56 | // Add workflow header with logo and instructions |
| 57 | customInstructions := `This file defines the generated agentic maintenance workflow for this repository. |
| 58 | It runs scheduled cleanup for expiring safe outputs and supports manual maintenance operations. |
| 59 | |
| 60 | This workflow is generated automatically when workflows use expiring safe outputs |
| 61 | or when repository maintenance features are enabled in .github/workflows/aw.json. |
| 62 | |
| 63 | To disable maintenance workflow generation, set in .github/workflows/aw.json: |
| 64 | {"maintenance": false} |
| 65 | |
| 66 | Agentic maintenance docs: |
| 67 | https://github.github.com/gh-aw/reference/ephemerals/#manual-maintenance-operations` |
| 68 | |
| 69 | header := GenerateWorkflowHeader("", "pkg/workflow/maintenance_workflow.go", customInstructions) |
| 70 | yaml.WriteString(header) |
| 71 | |
| 72 | yaml.WriteString(`name: Agentic Maintenance |
| 73 | |
| 74 | on: |
| 75 | schedule: |
| 76 | - cron: "` + cronSchedule + `" # ` + scheduleDesc + ` (based on minimum expires: ` + strconv.Itoa(minExpiresDays) + ` days) |
| 77 | `) |
| 78 | |
| 79 | // Add push trigger in dev mode so compile-workflows runs when workflow files change |
| 80 | if actionMode == ActionModeDev { |
| 81 | maintenanceWorkflowYAMLLog.Printf("Adding dev-mode push trigger for branch %q", defaultBranch) |
| 82 | yaml.WriteString(` push: |
| 83 | branches: |
| 84 | - ` + defaultBranch + ` |
| 85 | paths: |
| 86 | - '.github/workflows/*.md' |
| 87 | `) |
| 88 | } |
| 89 | |
| 90 | // Add label-event trigger only when the label-triggered jobs are enabled |
| 91 | if !disableLabelTrigger { |