Refactor workflow cache/action/validation paths by extracting focused helpers#36248
Merged
pelikhan merged 7 commits intoJun 1, 2026
Merged
Conversation
9 tasks
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor long functions in workflow and CLI packages
Refactor workflow cache/action/validation paths by extracting focused helpers
Jun 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors several pkg/workflow hotspots by extracting smaller helper functions for cache parsing/rendering, action reference resolution, lock parsing, and workflow validation, aiming to reduce control-flow complexity while preserving behavior.
Changes:
- Decomposed cache-memory parsing/config extraction and cache step generation into focused helpers (including new numeric normalization for YAML-derived ints).
- Split action setup/reference resolution and action lock parsing into reusable helpers; refactored action cache deduplication into discrete phases.
- Broke down workflow validation logic (call-workflow + workflow_run) into smaller validation helpers.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/call_workflow_validation.go | Extracts call-workflow validation into dedicated helpers (self-reference, existence, trigger support). |
| pkg/workflow/cache.go | Refactors cache-memory parsing and cache step generation; introduces parseOptionalInt for safer YAML numeric normalization. |
| pkg/workflow/agent_validation.go | Splits workflow_run validation into trigger parsing + focused validation helpers. |
| pkg/workflow/action_sha_checker.go | Extracts lock YAML validation and action usage parsing/version resolution helpers. |
| pkg/workflow/action_reference.go | Refactors setup action reference resolution and release pinning into mode-specific helpers. |
| pkg/workflow/action_cache.go | Refactors deduplication into grouping, ranking, removal collection, and deletion helpers. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 2
Comment on lines
+210
to
+214
| if floatValue, ok := value.(float64); ok { | ||
| if math.IsNaN(floatValue) || math.IsInf(floatValue, 0) { | ||
| return nil | ||
| } | ||
| // Validate retention-days bounds | ||
| if entry.RetentionDays != nil { | ||
| if err := validateIntRange(*entry.RetentionDays, 1, 90, "retention-days"); err != nil { | ||
| return entry, err | ||
| } | ||
| if floatValue != math.Trunc(floatValue) { |
Comment on lines
+196
to
+205
| // parseOptionalInt safely converts YAML numeric values (int, float64, uint64) to *int. | ||
| // | ||
| // It returns nil when the input cannot be represented as an integer for the current | ||
| // architecture, including: | ||
| // - NaN/Inf float64 values | ||
| // - fractional float64 values | ||
| // - float64 values outside the exact-integer range [-2^53, 2^53] | ||
| // - uint64 values larger than math.MaxInt | ||
| // - unsupported types | ||
| func parseOptionalInt(value any) *int { |
Collaborator
|
@copilot /copilot-review |
Collaborator
|
@copilot apply copilot-review skill |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
Applied the copilot-review skill and addressed the follow-up review findings in commits |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the lint-monster Part 2 workflow refactor scope by decomposing long functions in
pkg/workflow(cache support, action resolution, validation) into smaller units while preserving behavior. The changes target the specified hotspots and reduce control-flow complexity through helper extraction and reuse.Cache parsing and config extraction (
pkg/workflow/cache.go)parseCacheMemoryEntryinto focused parsers for identity/key, retention, scope, restore-only, and allowed extensions.extractCacheMemoryConfiginto default-entry and array/object parsing helpers.generateCacheStepsinto parse/render helpers (parseCacheStepConfigs,writeCacheStep, field writers) to isolate YAML parsing from step emission.int/float64/uint64) inparseOptionalInt.Action resolution and lock parsing (
pkg/workflow/action_reference.go,action_cache.go,action_sha_checker.go)resolveSetupActionRefinto mode-specific helpers (resolveSetupActionModeRef,resolveSetupReleaseModeRef) with shared tag/SHA resolution helpers.resolveActionReferenceinto explicit helpers for frontmatter tag detection, setup-action resolution, and release pin resolution.deduplicateEntriesby separating grouping, candidate ranking, removal collection, and deletion.ExtractActionsFromLockFileinto YAML validation + match parsing + version resolution helpers.Workflow validation decomposition (
pkg/workflow/agent_validation.go,call_workflow_validation.go)validateWorkflowRunBranchesinto trigger parsing, required-workflows validation, and strict/non-strict branch-warning handling.validateCallWorkflowinto self-reference checks, existence checks, YAML/MD trigger checks, and reusable trigger-validation helpers.