runUpgradeCommand executes the upgrade process
(opts upgradeOptions)
| 210 | |
| 211 | // runUpgradeCommand executes the upgrade process |
| 212 | func runUpgradeCommand(opts upgradeOptions) error { |
| 213 | upgradeLog.Printf("Running upgrade command: verbose=%v, workflowDir=%s, noFix=%v, noCompile=%v, noActions=%v, disabledCodemodIDs=%v, skipExtensionUpgrade=%v", |
| 214 | opts.verbose, opts.workflowDir, opts.noFix, opts.noCompile, opts.noActions, opts.disabledCodemodIDs, opts.skipExtensionUpgrade) |
| 215 | |
| 216 | // Step 0b: Ensure gh-aw extension is on the latest version. |
| 217 | // If the extension was just upgraded, re-launch the freshly-installed binary |
| 218 | // with the same flags so that all subsequent steps (e.g. lock-file compilation) |
| 219 | // use the correct new version string. The hidden --skip-extension-upgrade flag |
| 220 | // prevents the re-launched process from entering this branch again. |
| 221 | if !opts.skipExtensionUpgrade { |
| 222 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Checking gh-aw extension version...")) |
| 223 | upgraded, installPath, err := upgradeExtensionIfOutdated(opts.verbose, opts.preReleases) |
| 224 | if err != nil { |
| 225 | upgradeLog.Printf("Extension upgrade failed: %v", err) |
| 226 | return err |
| 227 | } |
| 228 | if upgraded { |
| 229 | upgradeLog.Print("Extension was upgraded; re-launching with new binary") |
| 230 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Continuing upgrade with newly installed version...")) |
| 231 | // Pass installPath so relaunchWithSameArgs uses the pre-rename path; |
| 232 | // on Linux os.Executable() returns a "(deleted)" suffix after the rename. |
| 233 | if err := relaunchWithSameArgs("--skip-extension-upgrade", installPath); err != nil { |
| 234 | return err |
| 235 | } |
| 236 | // The child process completed all upgrade steps (including any PR creation). |
| 237 | // Signal the entry-point to exit cleanly without repeating those steps. |
| 238 | return &ExitCodeError{Code: 0} |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | // Step 1: Update dispatcher skill and related Copilot artifacts (like init command) |
| 243 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Updating dispatcher skill...")) |
| 244 | upgradeLog.Print("Updating dispatcher skill") |
| 245 | |
| 246 | if err := updateCopilotArtifacts(opts.ctx, opts.verbose); err != nil { |
| 247 | upgradeLog.Printf("Failed to update dispatcher skill: %v", err) |
| 248 | return fmt.Errorf("failed to update dispatcher skill: %w", err) |
| 249 | } |
| 250 | |
| 251 | if opts.verbose { |
| 252 | fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("✓ Updated dispatcher skill")) |
| 253 | } |
| 254 | |
| 255 | // Step 2: Apply codemods to all workflows (unless --no-fix is specified) |
| 256 | if !opts.noFix { |
| 257 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Applying codemods to all workflows...")) |
| 258 | upgradeLog.Print("Applying codemods to all workflows") |
| 259 | |
| 260 | fixConfig := FixConfig{ |
| 261 | WorkflowIDs: nil, // nil means all workflows |
| 262 | Write: true, |
| 263 | Verbose: opts.verbose, |
| 264 | WorkflowDir: opts.workflowDir, |
| 265 | DisabledCodemodIDs: opts.disabledCodemodIDs, |
| 266 | } |
| 267 | |
| 268 | if err := RunFix(fixConfig); err != nil { |
| 269 | upgradeLog.Printf("Failed to apply codemods: %v", err) |
no test coverage detected