Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/github-remote-mcp-auth-test.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions pkg/cli/upgrade_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ func NewUpgradeCommand() *cobra.Command {

This command:
1. Updates all agent and prompt files to the latest templates (like 'init' command)
2. Applies automatic codemods to fix deprecated fields in all workflows (like 'fix --write')
3. Compiles all workflows to generate lock files (like 'compile' command)
2. Updates workflows from their source repositories (for workflows with 'source' field)
3. Applies automatic codemods to fix deprecated fields in all workflows (like 'fix --write')
4. Compiles all workflows to generate lock files (like 'compile' command)

The upgrade process ensures:
- GitHub Copilot instructions are up-to-date (.github/aw/github-agentic-workflows.md)
- Dispatcher agent is current (.github/agents/agentic-workflows.agent.md)
- All workflow prompts are updated (create, update, debug, upgrade)
- Workflows with 'source' field are updated to their latest version
- All workflows use the latest syntax and configuration options
- Deprecated fields are automatically migrated across all workflows
- All workflows are compiled and lock files are up-to-date
Expand Down Expand Up @@ -111,7 +113,30 @@ func runUpgradeCommand(verbose bool, workflowDir string, noFix bool, noCompile b
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("✓ Updated agent and prompt files"))
}

// Step 2: Apply codemods to all workflows (unless --no-fix is specified)
// Step 2: Update workflows from source repositories (unless --no-fix is specified)
if !noFix {
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Updating workflows from source repositories..."))
upgradeLog.Print("Updating workflows from source repositories")

// Update workflows with source field
// Pass nil for workflowNames to update all workflows with source field
// Note: Each workflow is compiled immediately after update
if err := UpdateWorkflows(nil, false, false, verbose, "", workflowDir, false, "", false); err != nil {
upgradeLog.Printf("Failed to update workflows: %v", err)
// Don't fail the upgrade if update fails - this is non-critical
// Some workflows may not have source field, which is expected
if verbose {
fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Warning: Failed to update workflows: %v", err)))
}
}
} else {
upgradeLog.Print("Skipping workflow updates (--no-fix specified)")
if verbose {
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Skipping workflow updates (--no-fix specified)"))
}
}

// Step 3: Apply codemods to all workflows (unless --no-fix is specified)
if !noFix {
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Applying codemods to all workflows..."))
upgradeLog.Print("Applying codemods to all workflows")
Expand All @@ -135,7 +160,7 @@ func runUpgradeCommand(verbose bool, workflowDir string, noFix bool, noCompile b
}
}

// Step 3: Compile all workflows (unless --no-fix is specified)
// Step 4: Compile all workflows (unless --no-fix is specified)
if !noFix {
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Compiling all workflows..."))
upgradeLog.Print("Compiling all workflows")
Expand Down Expand Up @@ -178,7 +203,7 @@ func runUpgradeCommand(verbose bool, workflowDir string, noFix bool, noCompile b
fmt.Fprintln(os.Stderr, "")
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("✓ Upgrade complete"))

// Step 4: If --push is enabled, commit and push changes
// Step 5: If --push is enabled, commit and push changes
if push {
upgradeLog.Print("Push enabled - preparing to commit and push changes")
fmt.Fprintln(os.Stderr, "")
Expand Down
73 changes: 73 additions & 0 deletions pkg/cli/upgrade_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,76 @@ This workflow is already up to date.
require.Error(t, err, "Upgrade with --push should fail when no remote is configured")
assert.Contains(t, err.Error(), "--push requires a remote repository to be configured")
}

func TestUpgradeCommand_UpdatesWorkflowsWithSource(t *testing.T) {
// Create a temporary directory for test files
tmpDir := t.TempDir()
originalDir, _ := os.Getwd()
defer os.Chdir(originalDir)

// Initialize git repository
os.Chdir(tmpDir)
exec.Command("git", "init").Run()
exec.Command("git", "config", "user.email", "test@example.com").Run()
exec.Command("git", "config", "user.name", "Test User").Run()

// Create .github/workflows directory
workflowsDir := filepath.Join(tmpDir, ".github", "workflows")
err := os.MkdirAll(workflowsDir, 0755)
require.NoError(t, err, "Failed to create workflows directory")

// Create a workflow with source field
workflowWithSource := filepath.Join(workflowsDir, "workflow-with-source.md")
sourceWorkflowContent := `---
on:
workflow_dispatch:

permissions:
contents: read

source: example/repo/workflow.md@v1.0.0
---

# Workflow with Source

This workflow has a source field.
`
err = os.WriteFile(workflowWithSource, []byte(sourceWorkflowContent), 0644)
require.NoError(t, err, "Failed to create workflow with source")

// Create a workflow without source field
workflowWithoutSource := filepath.Join(workflowsDir, "workflow-without-source.md")
normalWorkflowContent := `---
on:
workflow_dispatch:

permissions:
contents: read
---

# Normal Workflow

This workflow has no source field.
`
err = os.WriteFile(workflowWithoutSource, []byte(normalWorkflowContent), 0644)
require.NoError(t, err, "Failed to create normal workflow")

// Run upgrade command (should attempt to update workflows with source field)
// Note: The actual update will fail because the source repo doesn't exist,
// but we're testing that the update step is executed
config := UpgradeConfig{
Verbose: true,
NoFix: false, // Enable update step
WorkflowDir: "",
Push: false,
}

// Capture the workflow execution - we expect the update to be attempted
// The upgrade should complete even if update fails (it's non-critical)
err = RunUpgrade(config)
require.NoError(t, err, "Upgrade should complete even if workflow update fails")

// Verify that both workflows still exist
assert.FileExists(t, workflowWithSource, "Workflow with source should still exist")
assert.FileExists(t, workflowWithoutSource, "Workflow without source should still exist")
}
Loading