Skip to content

refactor: standardize engine installation steps using template method pattern#5267

Merged
pelikhan merged 3 commits into
mainfrom
copilot/standardize-engine-installation-steps
Dec 2, 2025
Merged

refactor: standardize engine installation steps using template method pattern#5267
pelikhan merged 3 commits into
mainfrom
copilot/standardize-engine-installation-steps

Conversation

Copilot AI commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

All three engine files duplicate ~80% identical code in GetInstallationSteps(). This extracts the common pattern to a base implementation.

Changes

  • New EngineInstallConfig struct in engine_helpers.go centralizes engine configuration:

    • Secrets, DocsURL, NpmPackage, Version, Name, CliName, InstallStepName
  • New GetBaseInstallationSteps() function generates:

    • Secret validation step via GenerateMultiSecretValidationStep()
    • NPM installation steps via BuildStandardNpmEngineInstallSteps()
  • Engine refactoring:

    • claude_engine.go: Uses base method + appends network hook steps
    • codex_engine.go: Uses base method directly (single call)
    • copilot_engine.go: Uses config struct for values; retains custom step ordering for SRT/AWF

Example

Before (repeated in each engine):

secretValidation := GenerateMultiSecretValidationStep(
    []string{"CLAUDE_CODE_OAUTH_TOKEN", "ANTHROPIC_API_KEY"},
    "Claude Code",
    "https://githubnext.github.io/gh-aw/reference/engines/#anthropic-claude-code",
)
steps = append(steps, secretValidation)
npmSteps := BuildStandardNpmEngineInstallSteps(...)
steps = append(steps, npmSteps...)

After:

steps := GetBaseInstallationSteps(EngineInstallConfig{
    Secrets:         []string{"CLAUDE_CODE_OAUTH_TOKEN", "ANTHROPIC_API_KEY"},
    DocsURL:         "https://githubnext.github.io/gh-aw/reference/engines/#anthropic-claude-code",
    NpmPackage:      "@anthropic-ai/claude-code",
    Version:         string(constants.DefaultClaudeCodeVersion),
    Name:            "Claude Code",
    CliName:         "claude",
    InstallStepName: "Install Claude Code CLI",
}, workflowData)

Resolves #4843

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • go.googlesource.com
    • Triggering command: /update-job-proxy /update-job-proxy (dns block)
  • go.uber.org
    • Triggering command: /update-job-proxy /update-job-proxy (dns block)
  • gopkg.in
    • Triggering command: /update-job-proxy /update-job-proxy (dns block)
  • https://api.github.com/user
    • Triggering command: /usr/bin/gh gh api user --jq .login (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[task] Standardize engine installation steps using template method pattern</issue_title>
<issue_description>## Objective
Eliminate 80% code duplication in engine installation steps by extracting common patterns to a base implementation using the template method pattern.

Context

Part of issue #4640 - Priority 3 (Quick Win)

All engine files (claude_engine.go, codex_engine.go, copilot_engine.go) implement GetInstallationSteps() with 80% identical code. The only differences are configuration parameters (secrets, package names, versions).

Approach

  1. Create a base installation helper in pkg/workflow/engine.go:

    • Define EngineInstallConfig struct with fields: Secrets, DocsURL, NpmPackage, Version, Name, CliName
    • Implement GetInstallationSteps(config EngineInstallConfig, workflowData *WorkflowData) []GitHubActionStep
    • Include common steps: secret validation and NPM installation
  2. Simplify each engine's GetInstallationSteps() implementation:

    • Create config with engine-specific values
    • Call base GetInstallationSteps()
    • Add engine-specific steps (network permissions, settings, hooks) after base steps
  3. Maintain engine-specific customization while eliminating boilerplate

Files to Modify

  • Update: pkg/workflow/engine.go (add base installation method)
  • Update: pkg/workflow/claude_engine.go (use base method + Claude-specific steps)
  • Update: pkg/workflow/codex_engine.go (use base method + Codex-specific steps)
  • Update: pkg/workflow/copilot_engine.go (use base method + Copilot-specific steps)

Acceptance Criteria

  • EngineInstallConfig struct created with all required fields
  • Base GetInstallationSteps() method implemented
  • All three engines refactored to use base method
  • ~200 lines of duplicate code eliminated
  • Engine-specific customization preserved
  • All existing tests pass (make test)
  • Successful compilation (make build)
    Related to [refactor] 🔧 Semantic Function Clustering Analysis - November 2025 #4640

AI generated by Plan Command for #4640</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 2, 2025
Copilot AI and others added 2 commits December 2, 2025 06:20
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
… pattern

- Create EngineInstallConfig struct to centralize engine configuration
- Implement GetBaseInstallationSteps() for common patterns (secret validation + npm install)
- Refactor claude_engine.go to use base method + Claude-specific network hook steps
- Refactor codex_engine.go to use base method directly (simplest case)
- Refactor copilot_engine.go to use config struct for consistent configuration

Resolves #4843

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Standardize engine installation steps using template method pattern refactor: standardize engine installation steps using template method pattern Dec 2, 2025
Copilot AI requested a review from mnkiefer December 2, 2025 06:38
@pelikhan

pelikhan commented Dec 2, 2025

Copy link
Copy Markdown
Collaborator

@copilot recompile

Copilot AI commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

@copilot recompile

Recompiled 91 workflows successfully. No lock file changes needed - the compiled files are already up to date.

Copilot AI requested a review from pelikhan December 2, 2025 06:47
@pelikhan pelikhan marked this pull request as ready for review December 2, 2025 06:51
@pelikhan pelikhan merged commit baaf0f4 into main Dec 2, 2025
82 of 83 checks passed
@pelikhan pelikhan deleted the copilot/standardize-engine-installation-steps branch December 2, 2025 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[task] Standardize engine installation steps using template method pattern

3 participants