Skip to content

[refactor] Duplicate SHA-resolution logic in resolveSetupActionModeRef/resolveSetupReleaseModeRef #70752

Closed as not planned

Description

@github-actions

Overview

Sampled analysis (slice 9/631 of pkg/workflow, slice 9/11 of pkg/workflow/actions; date 2026-10-21; coverage_days 793 for the full rotation) reviewed 14 functions across 4 files. This is a sampled excerpt review, not a claim of full-package or full-repository coverage.

Finding

pkg/workflow/action_reference.go has two functions with near-identical control flow that differ only in how actionRepo is derived and in a log-label string:

  • resolveSetupActionModeRef (lines 66-79)
  • resolveSetupReleaseModeRef (lines 81-95)

Both functions:

  1. Call resolveSetupTag(actionTag, version, localPath) and return localPath early if !ok.
  2. Build remoteRef := fmt.Sprintf("%s@%s", actionRepo, tag).
  3. Call tryResolveSetupSHA(ctx, resolver, actionRepo, tag, remoteRef, modeLabel) and return the resolved ref if non-empty.
  4. Otherwise log a warning via actionRefLog.Printf with a mode-specific message and return remoteRef.

The only differences are the actionRepo construction (actionsOrgRepo + "/setup" vs. fmt.Sprintf("%s/%s", GitHubOrgRepo, strings.TrimPrefix(localPath, "./"))) and the mode label text ("Action mode" / "Release mode", plus slightly different wording in the final log message: "external actions repo reference" vs. "remote action reference").

Observed source (from the sampled packet)
func resolveSetupActionModeRef(ctx context.Context, actionTag string, version string, resolver SHAResolver, actionsOrgRepo string, localPath string) string {
	tag, ok := resolveSetupTag(actionTag, version, localPath)
	if !ok {
		return localPath
	}
	actionRepo := actionsOrgRepo + "/setup"
	remoteRef := fmt.Sprintf("%s@%s", actionRepo, tag)
	ref := tryResolveSetupSHA(ctx, resolver, actionRepo, tag, remoteRef, "Action mode")
	if ref != "" {
		return ref
	}
	actionRefLog.Printf("Action mode: using tag-based external actions repo reference: %s (SHA will be resolved later)", remoteRef)
	return remoteRef
}

func resolveSetupReleaseModeRef(ctx context.Context, actionTag string, version string, resolver SHAResolver, localPath string) string {
	tag, ok := resolveSetupTag(actionTag, version, localPath)
	if !ok {
		return localPath
	}
	actionPath := strings.TrimPrefix(localPath, "./")
	actionRepo := fmt.Sprintf("%s/%s", GitHubOrgRepo, actionPath)
	remoteRef := fmt.Sprintf("%s@%s", actionRepo, tag)
	ref := tryResolveSetupSHA(ctx, resolver, actionRepo, tag, remoteRef, "Release mode")
	if ref != "" {
		return ref
	}
	actionRefLog.Printf("Release mode: using tag-based remote action reference: %s (SHA will be resolved later)", remoteRef)
	return remoteRef
}

Both excerpts are complete (truncated: false) for the sampled byte range.

Proposed refactoring

Extract the shared tail into one helper, e.g.:

func resolveSetupModeRef(ctx context.Context, actionTag, version string, resolver SHAResolver, localPath, actionRepo, modeLabel string) string {
	tag, ok := resolveSetupTag(actionTag, version, localPath)
	if !ok {
		return localPath
	}
	remoteRef := fmt.Sprintf("%s@%s", actionRepo, tag)
	if ref := tryResolveSetupSHA(ctx, resolver, actionRepo, tag, remoteRef, modeLabel); ref != "" {
		return ref
	}
	actionRefLog.Printf("%s: using tag-based reference: %s (SHA will be resolved later)", modeLabel, remoteRef)
	return remoteRef
}

Then resolveSetupActionModeRef and resolveSetupReleaseModeRef would each compute their own actionRepo and call this helper with their respective mode label.

Preservation risks

  • The two log messages currently use slightly different wording ("external actions repo reference" vs. "remote action reference"); unifying the format string changes log text, which may affect anything scraping these logs.
  • Both callers must be confirmed to tolerate the exact same remoteRef/ref semantics — the sampled excerpts show no divergence, but the rest of each file was not reviewed.

Scope and limitations

This is a sampled analysis of 14 functions in 4 files (per the daily rotation), not a review of the entire workflow or actions package. No other significant duplicate-logic or purpose-mismatch findings were confirmed in this sample.

Generated by 🔧 Semantic Function Refactoring · claude · sonnet50 · 27.6 AIC · ⌖ 19.1 AIC · ⊞ 5.1K · ◷

  • expires on Oct 22, 2026, 6:39 PM UTC-08:00

Activity

  1. github-actions commented on Oct 22, 2026

    @github-actions
    ContributorAuthor

    Superseded by the newest sampled semantic-function-refactor report (slice 1/1 for pkg/linters/contextcancelnotdeferred and pkg/linters/ctxbackground, 2026-10-22). Closing as part of the rolling refactor-suggestion backlog.

    Generated by 🔧 Semantic Function Refactoring · claude · sonnet50 · 40.9 AIC · ⌖ 19.1 AIC · ⊞ 5.2K

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions