2022-03-22 16:13:00 -05:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/tar"
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/nektos/act/pkg/common"
|
|
|
|
"github.com/nektos/act/pkg/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stepActionLocal struct {
|
2022-05-24 08:36:06 -05:00
|
|
|
Step *model.Step
|
|
|
|
RunContext *RunContext
|
|
|
|
compositeRunContext *RunContext
|
|
|
|
compositeSteps *compositeSteps
|
|
|
|
runAction runAction
|
|
|
|
readAction readAction
|
|
|
|
env map[string]string
|
|
|
|
action *model.Action
|
2022-03-22 16:13:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sal *stepActionLocal) pre() common.Executor {
|
|
|
|
sal.env = map[string]string{}
|
|
|
|
|
2022-05-24 08:36:06 -05:00
|
|
|
return func(ctx context.Context) error {
|
2022-06-08 10:36:08 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sal *stepActionLocal) main() common.Executor {
|
|
|
|
return runStepExecutor(sal, stepStageMain, func(ctx context.Context) error {
|
2022-06-07 09:19:30 -05:00
|
|
|
if common.Dryrun(ctx) {
|
|
|
|
return nil
|
|
|
|
}
|
2022-06-08 10:36:08 -05:00
|
|
|
|
2022-03-22 16:13:00 -05:00
|
|
|
actionDir := filepath.Join(sal.getRunContext().Config.Workdir, sal.Step.Uses)
|
|
|
|
|
|
|
|
localReader := func(ctx context.Context) actionYamlReader {
|
|
|
|
_, cpath := getContainerActionPaths(sal.Step, path.Join(actionDir, ""), sal.RunContext)
|
|
|
|
return func(filename string) (io.Reader, io.Closer, error) {
|
|
|
|
tars, err := sal.RunContext.JobContainer.GetContainerArchive(ctx, path.Join(cpath, filename))
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, os.ErrNotExist
|
|
|
|
}
|
|
|
|
treader := tar.NewReader(tars)
|
|
|
|
if _, err := treader.Next(); err != nil {
|
|
|
|
return nil, nil, os.ErrNotExist
|
|
|
|
}
|
|
|
|
return treader, tars, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-06 16:58:16 -05:00
|
|
|
actionModel, err := sal.readAction(ctx, sal.Step, actionDir, "", localReader(ctx), os.WriteFile)
|
2022-03-22 16:13:00 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sal.action = actionModel
|
|
|
|
|
2022-03-29 12:42:11 -05:00
|
|
|
return sal.runAction(sal, actionDir, nil)(ctx)
|
2022-03-22 16:13:00 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sal *stepActionLocal) post() common.Executor {
|
2022-05-24 08:36:06 -05:00
|
|
|
return runStepExecutor(sal, stepStagePost, runPostStep(sal)).If(hasPostStep(sal)).If(shouldRunPostStep(sal))
|
2022-03-22 16:13:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sal *stepActionLocal) getRunContext() *RunContext {
|
|
|
|
return sal.RunContext
|
|
|
|
}
|
|
|
|
|
2022-10-06 16:58:16 -05:00
|
|
|
func (sal *stepActionLocal) getGithubContext(ctx context.Context) *model.GithubContext {
|
|
|
|
return sal.getRunContext().getGithubContext(ctx)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:13:00 -05:00
|
|
|
func (sal *stepActionLocal) getStepModel() *model.Step {
|
|
|
|
return sal.Step
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sal *stepActionLocal) getEnv() *map[string]string {
|
|
|
|
return &sal.env
|
|
|
|
}
|
|
|
|
|
2023-07-10 19:12:12 -05:00
|
|
|
func (sal *stepActionLocal) getIfExpression(_ context.Context, stage stepStage) string {
|
2022-05-24 08:36:06 -05:00
|
|
|
switch stage {
|
|
|
|
case stepStageMain:
|
|
|
|
return sal.Step.If.Value
|
|
|
|
case stepStagePost:
|
|
|
|
return sal.action.Runs.PostIf
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:13:00 -05:00
|
|
|
func (sal *stepActionLocal) getActionModel() *model.Action {
|
|
|
|
return sal.action
|
|
|
|
}
|
2022-05-24 08:36:06 -05:00
|
|
|
|
2022-06-17 10:55:21 -05:00
|
|
|
func (sal *stepActionLocal) getCompositeRunContext(ctx context.Context) *RunContext {
|
2022-05-24 08:36:06 -05:00
|
|
|
if sal.compositeRunContext == nil {
|
|
|
|
actionDir := filepath.Join(sal.RunContext.Config.Workdir, sal.Step.Uses)
|
|
|
|
_, containerActionDir := getContainerActionPaths(sal.getStepModel(), actionDir, sal.RunContext)
|
|
|
|
|
2022-06-17 10:55:21 -05:00
|
|
|
sal.compositeRunContext = newCompositeRunContext(ctx, sal.RunContext, sal, containerActionDir)
|
2022-05-24 08:36:06 -05:00
|
|
|
sal.compositeSteps = sal.compositeRunContext.compositeExecutor(sal.action)
|
|
|
|
}
|
|
|
|
return sal.compositeRunContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sal *stepActionLocal) getCompositeSteps() *compositeSteps {
|
|
|
|
return sal.compositeSteps
|
|
|
|
}
|