refactor: pull actions as actions manager
This commit is contained in:
parent
222570b2f4
commit
7466ad21a9
3 changed files with 26 additions and 12 deletions
|
@ -2,7 +2,6 @@
|
||||||
package actions
|
package actions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
logger "courgette/internal/logging"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,13 +20,3 @@ func GetActionKey(url string) string {
|
||||||
|
|
||||||
return strings.Join(parts, "__")
|
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)
|
|
||||||
}
|
|
||||||
|
|
25
internal/actions/manager.go
Normal file
25
internal/actions/manager.go
Normal 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)
|
||||||
|
}
|
|
@ -49,7 +49,7 @@ func (r *Runner) RunWorkflow(workflow workflows.Workflow) TaskTracker {
|
||||||
switch n.(type) {
|
switch n.(type) {
|
||||||
case workflows.Step:
|
case workflows.Step:
|
||||||
if useAction := n.(workflows.Step).Use; useAction != "" {
|
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)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue