4391a10d5a
* feat: use logger from context wherever possible Co-authored-by: Markus Wolf <markus.wolf@new-work.se> * feat: add step/job id and results to json logs Co-authored-by: Markus Wolf <markus.wolf@new-work.se> * test: value to be masked should not be hard-coded in the action Co-authored-by: Markus Wolf <markus.wolf@new-work.se> * fix: replace values following ::add-mask:: in evaluated strings Co-authored-by: Markus Wolf <markus.wolf@new-work.se> * feat: [DEBUG] identifier for debug logs to distinguish them Co-authored-by: Markus Wolf <markus.wolf@new-work.se> * feat: replace logger with step logger The container gets injected a job logger, but during the time that steps are run, we want to use the step logger. This commit wraps pre/main/post steps in an executor that replaces the job logger with a step logger. Co-authored-by: Markus Wolf <markus.wolf@new-work.se> * feat: add pre/post stage identifier fields to json log output Co-authored-by: Markus Wolf <markus.wolf@new-work.se> * feat: add job/step result status to skipped steps/jobs Co-authored-by: Markus Wolf <markus.wolf@new-work.se> Co-authored-by: Markus Wolf <markus.wolf@new-work.se> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
112 lines
2.9 KiB
Go
112 lines
2.9 KiB
Go
package runner
|
|
|
|
import (
|
|
"archive/tar"
|
|
"context"
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
|
|
"github.com/nektos/act/pkg/common"
|
|
"github.com/nektos/act/pkg/model"
|
|
)
|
|
|
|
type stepActionLocal struct {
|
|
Step *model.Step
|
|
RunContext *RunContext
|
|
compositeRunContext *RunContext
|
|
compositeSteps *compositeSteps
|
|
runAction runAction
|
|
readAction readAction
|
|
env map[string]string
|
|
action *model.Action
|
|
}
|
|
|
|
func (sal *stepActionLocal) pre() common.Executor {
|
|
sal.env = map[string]string{}
|
|
|
|
return func(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (sal *stepActionLocal) main() common.Executor {
|
|
return runStepExecutor(sal, stepStageMain, func(ctx context.Context) error {
|
|
if common.Dryrun(ctx) {
|
|
return nil
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
actionModel, err := sal.readAction(ctx, sal.Step, actionDir, "", localReader(ctx), ioutil.WriteFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
sal.action = actionModel
|
|
|
|
return sal.runAction(sal, actionDir, nil)(ctx)
|
|
})
|
|
}
|
|
|
|
func (sal *stepActionLocal) post() common.Executor {
|
|
return runStepExecutor(sal, stepStagePost, runPostStep(sal)).If(hasPostStep(sal)).If(shouldRunPostStep(sal))
|
|
}
|
|
|
|
func (sal *stepActionLocal) getRunContext() *RunContext {
|
|
return sal.RunContext
|
|
}
|
|
|
|
func (sal *stepActionLocal) getStepModel() *model.Step {
|
|
return sal.Step
|
|
}
|
|
|
|
func (sal *stepActionLocal) getEnv() *map[string]string {
|
|
return &sal.env
|
|
}
|
|
|
|
func (sal *stepActionLocal) getIfExpression(context context.Context, stage stepStage) string {
|
|
switch stage {
|
|
case stepStageMain:
|
|
return sal.Step.If.Value
|
|
case stepStagePost:
|
|
return sal.action.Runs.PostIf
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (sal *stepActionLocal) getActionModel() *model.Action {
|
|
return sal.action
|
|
}
|
|
|
|
func (sal *stepActionLocal) getCompositeRunContext(ctx context.Context) *RunContext {
|
|
if sal.compositeRunContext == nil {
|
|
actionDir := filepath.Join(sal.RunContext.Config.Workdir, sal.Step.Uses)
|
|
_, containerActionDir := getContainerActionPaths(sal.getStepModel(), actionDir, sal.RunContext)
|
|
|
|
sal.compositeRunContext = newCompositeRunContext(ctx, sal.RunContext, sal, containerActionDir)
|
|
sal.compositeSteps = sal.compositeRunContext.compositeExecutor(sal.action)
|
|
}
|
|
return sal.compositeRunContext
|
|
}
|
|
|
|
func (sal *stepActionLocal) getCompositeSteps() *compositeSteps {
|
|
return sal.compositeSteps
|
|
}
|