Skip to content

[file-diet] File Diet: pkg/cli/update_actions.go exceeds 800-line threshold (1144 lines) #52054

Description

@github-actions

Overview

The file pkg/cli/update_actions.go has grown to 1144 lines, making it the largest non-test Go source file in the repository. It mixes several distinct responsibilities — action-version resolution (GitHub API + git-based fallback), cooldown/version-gating logic, workflow-file rewriting, and skill-ref updating — which increases coupling and makes targeted testing harder. This task involves refactoring it into smaller, focused files with clearer boundaries.

Current State

  • File: pkg/cli/update_actions.go
  • Size: 1144 lines
  • Test Coverage: pkg/cli/update_actions_test.go (1256 lines) + pkg/cli/update_actions_integration_test.go exist — ratio ≈ 1.1x (source vs. unit test), indicating solid existing coverage that should be preserved/relocated alongside any split.
  • Complexity: 18 top-level functions spanning 4 loosely related domains (action classification, release resolution via API/git, workflow-file mutation, skill-ref mutation).
Full File Analysis

Detailed Breakdown

Functions and approximate line ranges:

  • isCoreAction (28), isGhAwNativeAction (35) — small classification helpers (~30 lines total)
  • actionUpdateDeps struct, cachedLatestRelease, cachedSHA types, newCachedActionUpdateDeps (61), defaultActionUpdateDeps (133) — dependency-injection/caching scaffolding (~100 lines)
  • UpdateActions (156), updateActions (160–402, ~240 lines) — top-level orchestrator for actions-lock.json updates
  • getLatestActionRelease (403), getLatestActionReleaseWithDeps (407–538, ~130 lines) — GitHub Releases API-based version resolution
  • getLatestActionReleaseViaGit (539–654, ~115 lines) — git-tag-based fallback version resolution
  • parseActionTagRefs (655), findCooledDownActionVersion (692), getActionSHAForTag (745–803, ~60 lines) — tag parsing and cooldown-window gating logic
  • UpdateActionsInWorkflowFiles (804), updateActionsInWorkflowFiles (833–911, ~80 lines) — orchestrator for rewriting .md workflow files
  • updateSkillRefsInContent (912), updateSkillRefsInContentWithResolver (916), updateSkillRefValue (982–1016, ~100 lines) — skill reference (source:) rewriting
  • updateActionRefsInContentWithDeps (1017–1144, ~127 lines) — action ref (uses:) rewriting in Markdown content

There are two clear domains mixed in this file: (1) resolving the latest/cooled-down action version (API + git fallback + cooldown), and (2) rewriting references (action uses: and skill source:) in workflow Markdown files. The dependency-injection scaffolding (actionUpdateDeps, caches) is shared infrastructure used by both.

Refactoring Strategy

Proposed File Splits

  1. update_actions_deps.go

    • Contents: actionUpdateDeps struct, cachedLatestRelease, cachedSHA, newCachedActionUpdateDeps, defaultActionUpdateDeps
    • Responsibility: dependency-injection/caching scaffolding shared by resolution and rewriting logic
    • Estimated LOC: ~110
  2. update_actions_release.go

    • Functions: isCoreAction, isGhAwNativeAction, getLatestActionRelease, getLatestActionReleaseWithDeps, getLatestActionReleaseViaGit, parseActionTagRefs, findCooledDownActionVersion, getActionSHAForTag
    • Responsibility: resolving the latest eligible action version (API + git fallback) and applying cooldown-window gating
    • Estimated LOC: ~450
  3. update_actions_lockfile.go

    • Functions: UpdateActions, updateActions
    • Responsibility: top-level command orchestrating actions-lock.json updates
    • Estimated LOC: ~250
  4. update_actions_workflow_refs.go

    • Functions: UpdateActionsInWorkflowFiles, updateActionsInWorkflowFiles, updateSkillRefsInContent, updateSkillRefsInContentWithResolver, updateSkillRefValue, updateActionRefsInContentWithDeps
    • Responsibility: rewriting uses: action refs and source: skill refs inside workflow Markdown files
    • Estimated LOC: ~340

Shared Utilities

No new utility file is needed beyond update_actions_deps.go; the dependency struct already serves as the shared abstraction point between resolution and rewriting logic.

Interface Abstractions

No new interfaces are strictly required — actionUpdateDeps already acts as a functional dependency-injection seam. Keep function signatures unchanged so callers in update_command.go/tests are unaffected.

Test Coverage Plan

Split update_actions_test.go (1256 lines) and update_actions_integration_test.go along the same boundaries:

  1. update_actions_release_test.go

    • Test cases: core/native action classification, API release resolution (major/minor/patch gating), git-fallback resolution, tag parsing, cooldown-window edge cases (exactly-at-boundary, expired, still-cooling)
    • Target coverage: >80%
  2. update_actions_lockfile_test.go

    • Test cases: full updateActions orchestration happy path, no-updates-needed path, disableReleaseBump flag behavior, error propagation from resolver
    • Target coverage: >80%
  3. update_actions_workflow_refs_test.go

    • Test cases: rewriting single/multiple uses: refs in Markdown, skill source: ref rewriting, no-compile flag behavior, approve-flag gating, malformed content handling
    • Target coverage: >80%

Keep update_actions_integration_test.go as-is or split only if it becomes easier to maintain against the new file boundaries.

Implementation Guidelines

  1. Preserve Behavior: Ensure all existing functionality works identically
  2. Maintain Exports: Keep public API unchanged (exported functions/types)
  3. Add Tests First: Write tests for each new file before refactoring
  4. Incremental Changes: Split one module at a time
  5. Run Tests Frequently: Verify make test-unit passes after each split
  6. Update Imports: Ensure all import paths are correct
  7. Document Changes: Add comments explaining module boundaries

Acceptance Criteria

  • Original file is split into 4 focused files
  • Each new file is under 500 lines
  • All tests pass (make test-unit)
  • Test coverage is ≥80% for new files
  • No breaking changes to public API
  • Code passes linting (make lint)
  • Build succeeds (make build)
Additional Context
  • Repository Guidelines: Follow patterns in .github/agents/developer.instructions.agent.md
  • Code Organization: Prefer many small files grouped by functionality
  • Testing: Match existing test patterns in pkg/cli/*_test.go

Priority: Medium
Effort: Medium (4-way split with corresponding test relocation, no behavioral changes expected)
Expected Impact: Improved maintainability, easier targeted testing of release-resolution vs. Markdown-rewriting logic, reduced file-level coupling

Generated by 🧹 Daily File Diet · auto · 69.8 AIC · ⌖ 3.95 AIC · ⊞ 9.7K ·

  • expires on Aug 13, 2026, 5:09 AM UTC-08:00

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions