refactor: pull actions as actions manager

This commit is contained in:
Marc 2024-09-01 13:38:53 -04:00
parent 222570b2f4
commit 7466ad21a9
Signed by: marc
GPG key ID: 048E042F22B5DC79
3 changed files with 26 additions and 12 deletions

View file

@ -2,7 +2,6 @@
package actions
import (
logger "courgette/internal/logging"
"strings"
)
@ -21,13 +20,3 @@ func GetActionKey(url string) string {
return strings.Join(parts, "__")
}
// Prefetches and caches the action defined by <actionName> at <destination>.
//
// <actionName> is expected to be the full url of the repository where
// the action lives.
func PrefetchAction(client CliClient, actionName string, destination string) error {
logger.Info("Prefetching action: %s to %s", actionName, destination)
return client.Clone(actionName, destination)
}

View file

@ -0,0 +1,25 @@
package actions
import (
logger "courgette/internal/logging"
)
type ActionsManager struct {
git CliClient
}
func NewActionsManager() ActionsManager {
return ActionsManager{
git: GitClient{},
}
}
// Prefetches and caches the action defined by <actionName> at <destination>.
//
// <actionName> is expected to be the full url of the repository where
// the action lives.
func (a ActionsManager) PrefetchAction(actionName string, destination string) error {
logger.Info("Prefetching action: %s to %s", actionName, destination)
return a.git.Clone(actionName, destination)
}

View file

@ -49,7 +49,7 @@ func (r *Runner) RunWorkflow(workflow workflows.Workflow) TaskTracker {
switch n.(type) {
case workflows.Step:
if useAction := n.(workflows.Step).Use; useAction != "" {
actions.PrefetchAction(actions.GitClient{}, useAction, r.Cache.Path(actions.GetActionKey(useAction)))
actions.NewActionsManager().PrefetchAction(useAction, r.Cache.Path(actions.GetActionKey(useAction)))
}
}
})