Skip to content

refactor: consolidate reinvented semver helpers into pkg/semverutil - #42156

Merged
pelikhan merged 6 commits into
mainfrom
copilot/refactor-reinvented-semver-helpers
Jun 29, 2026
Merged

refactor: consolidate reinvented semver helpers into pkg/semverutil#42156
pelikhan merged 6 commits into
mainfrom
copilot/refactor-reinvented-semver-helpers

Conversation

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Three semver helpers had been independently reimplemented in feature files despite pkg/semverutil already providing equivalent functionality. This PR removes the duplicates and routes all callers through the shared package.

Changes

  • pkg/semverutil — adds IsMorePreciseVersion(v1, v2 string) bool, the canonical replacement for the private isMorePreciseVersion in action_cache.go
  • pkg/cli/compile_update_check.go — removes ensureSemverPrefix (≡ semverutil.EnsureVPrefix) and semverMajorMinorParts (≡ semverutil.ParseVersion .Major/.Minor); replaces direct golang.org/x/mod/semver calls with semverutil wrappers; drops strconv import
  • pkg/cli/update_check.go — same ensureSemverPrefix / semver.* replacement
  • pkg/workflow/action_cache.go — removes isMorePreciseVersion, calls semverutil.IsMorePreciseVersion
  • pkg/workflow/action_cache_test.go — updates test to call semverutil.IsMorePreciseVersion

Before:

// pkg/cli/compile_update_check.go
currentSV := ensureSemverPrefix(currentVersion)           // private duplicate
major, minor, ok := semverMajorMinorParts(currentSV)      // private duplicate

After:

currentSV := semverutil.EnsureVPrefix(currentVersion)
parsed := semverutil.ParseVersion(currentSV)
// parsed.Major, parsed.Minor

Generated by 👨‍🍳 PR Sous Chef · 67.9 AIC · ⌖ 1.53 AIC · ⊞ 17.6K ·

Copilot AI and others added 2 commits June 29, 2026 01:36
- Add IsMorePreciseVersion to pkg/semverutil
- Replace ensureSemverPrefix/semverMajorMinorParts in compile_update_check.go
  with semverutil.EnsureVPrefix/semverutil.ParseVersion
- Replace ensureSemverPrefix in update_check.go with semverutil.EnsureVPrefix
- Remove isMorePreciseVersion from action_cache.go, use semverutil.IsMorePreciseVersion
- Update action_cache_test.go to call semverutil.IsMorePreciseVersion

Closes #42151

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Remove redundant nil checks after ParseVersion (already guarded by IsValid)
- Clarify IsMorePreciseVersion doc comment re: no input validation

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor semver helpers to reuse pkg/semverutil refactor: consolidate reinvented semver helpers into pkg/semverutil Jun 29, 2026
Copilot AI requested a review from pelikhan June 29, 2026 01:39
@github-actions

Copy link
Copy Markdown
Contributor

Hey @app/copilot-swe-agent 👋 — nice consolidation! Moving isMorePreciseVersion, ensureSemverPrefix, and semverMajorMinorParts into pkg/semverutil is a clean win — the diff removes ~67 lines of duplicated logic across three packages.

One thing to tidy up before this is ready for review:

  • Add a PR description — the body is currently a task checklist (all items unchecked), but the implementation looks complete. A short prose summary explaining why this refactoring is worthwhile (e.g. eliminates duplication, makes semver helpers discoverable in one place, reduces direct golang.org/x/mod/semver call-sites) would help reviewers quickly understand the intent and validate the change.
  • Remove [WIP] and check off completed tasks — the title still carries [WIP] and all checklist items show unchecked, which signals the PR isn't ready. If the implementation is done, update the title and tick the boxes.

If you'd like a hand polishing this up, you can use the following prompt:

For PR #42156 in github/gh-aw titled "[WIP] Refactor semver helpers to reuse pkg/semverutil":
1. Remove the "[WIP]" prefix from the PR title.
2. Mark all checklist items in the PR body as completed (change [ ] to [x]).
3. Prepend a short prose description (2-4 sentences) to the PR body that explains:
   - What this PR does: consolidates semver helper functions from pkg/cli and pkg/workflow into the shared pkg/semverutil package.
   - Why: eliminates duplicated logic, reduces direct golang.org/x/mod/semver call-sites outside the utility package, and makes semver helpers discoverable in one place.
Do not change any code files.

Generated by ✅ Contribution Check · 277.8 AIC · ⌖ 16.5 AIC · ⊞ 6K ·

@pelikhan
pelikhan marked this pull request as ready for review June 29, 2026 02:50
Copilot AI review requested due to automatic review settings June 29, 2026 02:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors semver-related logic to remove duplicated helpers in feature code and route callers through the shared pkg/semverutil package, improving consistency and reducing drift across the CLI and workflow packages.

Changes:

  • Added semverutil.IsMorePreciseVersion and migrated pkg/workflow/action_cache.go + tests to use it.
  • Replaced local semver helpers and direct golang.org/x/mod/semver usage in CLI update-check code with semverutil wrappers.
  • Simplified CLI semver parsing logic by using semverutil.ParseVersion for major/minor comparisons.
Show a summary per file
File Description
pkg/workflow/action_cache.go Switched dedup sort logic to use semverutil.IsMorePreciseVersion and removed the local helper.
pkg/workflow/action_cache_test.go Updated precision-comparison tests to call into semverutil.
pkg/semverutil/semverutil.go Added exported IsMorePreciseVersion helper for shared use.
pkg/cli/update_check.go Replaced x/mod/semver calls with semverutil wrappers for validation and comparison.
pkg/cli/compile_update_check.go Replaced local semver prefix/major-minor parsing helpers with semverutil functions.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment on lines +288 to +291
currentParsed := semverutil.ParseVersion(currentSV)
latestParsed := semverutil.ParseVersion(latestSV)

major, err := strconv.Atoi(parts[0])
if err != nil {
return 0, 0, false
}
minor, err := strconv.Atoi(parts[1])
if err != nil {
return 0, 0, false
}

return major, minor, true
}

func ensureSemverPrefix(version string) string {
if strings.HasPrefix(version, "v") {
return version
}
return "v" + version
return currentParsed.Major == latestParsed.Major && latestParsed.Minor > currentParsed.Minor
Comment thread pkg/semverutil/semverutil.go Outdated
Comment on lines +140 to +145
// IsMorePreciseVersion reports whether v1 is more version-precise than v2.
// Precision is measured by the number of dot-separated components: "v4.3.0"
// (three components) is more precise than "v4" (one component). When both
// versions have the same number of components, lexicographic ordering is used.
// No validation is performed; the function counts dots in the raw strings, so
// callers should ensure both inputs are well-formed version tags.
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please address the review feedback, refresh this branch from main, and run the pr-finisher skill to bring the PR to ready state.

Generated by 👨‍🍳 PR Sous Chef · 67.9 AIC · ⌖ 1.53 AIC · ⊞ 17.6K ·

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please address the review feedback, refresh this branch from main, and run the pr-finisher skill to bring the PR to ready state.

...

Addressed the requested review feedback in 2e500cb:

  • Restored isMinorVersionBehind behavior to require explicit minor components (so v1 cases no longer report minor-behind).
  • Added targeted tests covering missing-minor and prerelease cases.
  • Clarified semverutil.IsMorePreciseVersion docs to state comparator/tie-break semantics.

Branch is already refreshed from main (git merge origin/main reported up-to-date), and I ran the PR finisher workflow steps available here. Note: full local validation currently still fails in pre-existing wasm golden tests under pkg/workflow (same failure signature during make test-unit/make agent-report-progress).

Copilot AI requested a review from gh-aw-bot June 29, 2026 03:43
@pelikhan

Copy link
Copy Markdown
Collaborator

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix tests https://github.com/github/gh-aw/actions/runs/28347157396/job/83980899590

Fixed in 34388f9.

I pulled the failing job logs, reproduced the failures locally, and updated the wasm golden snapshots to match the current awf/firewall version (v0.27.13).

Validation run:

  • go test -v -timeout=10m -run='^TestWasmGolden_' ./pkg/workflow
  • make agent-report-progress

@pelikhan
pelikhan merged commit 3e87b27 into main Jun 29, 2026
29 checks passed
@pelikhan
pelikhan deleted the copilot/refactor-reinvented-semver-helpers branch June 29, 2026 05:53
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.0

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.

4 participants