Skip to content

Commit fd90936

Browse files
Copilotpelikhan
andcommitted
refactor: introduce ActionSHAResolver interface, remove WorkflowData creation from ResolveSetupActionReference
Define ActionSHAResolver interface with ResolveSHA() method. Change ResolveSetupActionReference to accept the interface instead of *ActionResolver. Call ResolveSHA directly inside the function — no WorkflowData is created at all. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent b29c1b5 commit fd90936

4 files changed

Lines changed: 24 additions & 20 deletions

File tree

pkg/workflow/action_reference.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ const (
2222
// - actionMode: The action mode (dev or release)
2323
// - version: The version string to use for release mode
2424
// - actionTag: Optional override tag/SHA (takes precedence over version when in release mode)
25-
// - resolver: Optional ActionResolver for dynamic SHA resolution (can be nil for standalone use)
25+
// - resolver: Optional ActionSHAResolver for dynamic SHA resolution (can be nil for standalone use)
2626
//
2727
// Returns:
2828
// - For dev mode: "./actions/setup" (local path)
2929
// - For release mode with resolver: "github/gh-aw/actions/setup@<sha> # <version>" (SHA-pinned)
3030
// - For release mode without resolver: "github/gh-aw/actions/setup@<version>" (tag-based, SHA resolved later)
3131
// - Falls back to local path if version is invalid in release mode
32-
func ResolveSetupActionReference(actionMode ActionMode, version string, actionTag string, resolver *ActionResolver) string {
32+
func ResolveSetupActionReference(actionMode ActionMode, version string, actionTag string, resolver ActionSHAResolver) string {
3333
localPath := "./actions/setup"
3434

3535
// Dev mode - return local path
@@ -55,26 +55,20 @@ func ResolveSetupActionReference(actionMode ActionMode, version string, actionTa
5555
}
5656

5757
// Construct the remote reference with tag: github/gh-aw/actions/setup@tag
58-
remoteRef := fmt.Sprintf("%s/%s@%s", GitHubOrgRepo, actionPath, tag)
58+
actionRepo := fmt.Sprintf("%s/%s", GitHubOrgRepo, actionPath)
59+
remoteRef := fmt.Sprintf("%s@%s", actionRepo, tag)
5960

6061
// If a resolver is available, try to resolve the SHA
6162
if resolver != nil {
62-
data := &WorkflowData{
63-
ActionResolver: resolver,
64-
ActionPinWarnings: make(map[string]bool),
65-
}
66-
actionRepo := fmt.Sprintf("%s/%s", GitHubOrgRepo, actionPath)
67-
pinnedRef, err := GetActionPinWithData(actionRepo, tag, data)
68-
if err != nil {
69-
// In strict mode, GetActionPinWithData returns an error
70-
actionRefLog.Printf("Failed to pin action %s@%s: %v", actionRepo, tag, err)
71-
return ""
72-
}
73-
if pinnedRef != "" {
74-
// Successfully resolved to SHA
63+
sha, err := resolver.ResolveSHA(actionRepo, tag)
64+
if err == nil && sha != "" {
65+
pinnedRef := formatActionReference(actionRepo, sha, tag)
7566
actionRefLog.Printf("Release mode: resolved %s to SHA-pinned reference: %s", remoteRef, pinnedRef)
7667
return pinnedRef
7768
}
69+
if err != nil {
70+
actionRefLog.Printf("Failed to resolve SHA for %s@%s: %v", actionRepo, tag, err)
71+
}
7872
}
7973

8074
// If no resolver or SHA resolution failed, return tag-based reference
@@ -108,8 +102,8 @@ func (c *Compiler) resolveActionReference(localActionPath string, data *Workflow
108102
// For ./actions/setup, check for compiler-level actionTag override first
109103
if localActionPath == "./actions/setup" {
110104
// Use compiler actionTag if available, otherwise check features
111-
var resolver *ActionResolver
112-
if data != nil {
105+
var resolver ActionSHAResolver
106+
if data != nil && data.ActionResolver != nil {
113107
resolver = data.ActionResolver
114108
}
115109
if c.actionTag != "" {

pkg/workflow/action_resolver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111

1212
var resolverLog = logger.New("workflow:action_resolver")
1313

14+
// ActionSHAResolver is the minimal interface for resolving an action tag to its commit SHA.
15+
type ActionSHAResolver interface {
16+
ResolveSHA(repo, version string) (string, error)
17+
}
18+
1419
// ActionResolver handles resolving action SHAs using GitHub CLI
1520
type ActionResolver struct {
1621
cache *ActionCache

pkg/workflow/data/action_pins.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
"version": "v6",
111111
"sha": "b7c566a772e6b6bfb58ed0dc250532a479d7789f"
112112
},
113+
"anchore/sbom-action@v0": {
114+
"repo": "anchore/sbom-action",
115+
"version": "v0",
116+
"sha": "17ae1740179002c89186b61233e0f892c3118b11"
117+
},
113118
"anchore/sbom-action@v0.22.2": {
114119
"repo": "anchore/sbom-action",
115120
"version": "v0.22.2",

pkg/workflow/maintenance_workflow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ jobs:
150150

151151
// Get the setup action reference (local or remote based on mode)
152152
// Use the first available WorkflowData's ActionResolver to enable SHA pinning
153-
var resolver *ActionResolver
154-
if len(workflowDataList) > 0 {
153+
var resolver ActionSHAResolver
154+
if len(workflowDataList) > 0 && workflowDataList[0].ActionResolver != nil {
155155
resolver = workflowDataList[0].ActionResolver
156156
}
157157
setupActionRef := ResolveSetupActionReference(actionMode, version, actionTag, resolver)

0 commit comments

Comments
 (0)