func()

in codecatalyst-runner/pkg/actions/action_plan.go [151:200]


func (ap *actionPlan) loadNodeAction(action *Action, steps []string, executionType runner.ExecutionType) error {
	var image, entrypoint string
	if executionType == runner.ExecutionTypeDocker || executionType == runner.ExecutionTypeFinch {
		switch action.Runs.Using {
		case UsingTypeNode12:
			image = CodeCatalystImage()
		case UsingTypeNode16:
			image = CodeCatalystImage()
		default:
			return fmt.Errorf("unsupported value for 'using': %s", action.Runs.Using)
		}
		entrypoint = "/bin/cat"
		ap.environmentConfiguration.FileMaps = append(ap.environmentConfiguration.FileMaps, &runner.FileMap{
			SourcePath: action.Basedir,
			TargetPath: containerActionDir,
			Type:       runner.FileMapTypeCopyInWithGitignore,
		})
	}
	for i, command := range []string{action.Runs.Pre, action.Runs.Main, action.Runs.Post} {
		if command != "" {
			var fullCommand string
			switch executionType {
			case runner.ExecutionTypeDocker, runner.ExecutionTypeFinch:
				fullCommand = filepath.Join(containerActionDir, action.ID, command)
				ap.environmentConfiguration.Env["CATALYST_SOURCE_DIR_CawsCustomActionSource"] = containerActionDir
			case runner.ExecutionTypeShell:
				var err error
				fullCommand, err = filepath.Abs(fmt.Sprintf("%s/%s", action.Basedir, command))
				ap.environmentConfiguration.Env["CATALYST_SOURCE_DIR_CawsCustomActionSource"] = action.Basedir
				if err != nil {
					return err
				}
			default:
				return fmt.Errorf("unsupported execution type: %s", executionType)
			}
			cg, err := newCommandGroup(image, entrypoint)
			if err != nil {
				return err
			}
			cg.Commands = append(cg.Commands, []string{"node", fullCommand})
			if i == 1 { // add steps to the main command group
				for _, step := range steps {
					cg.Commands = append(cg.Commands, []string{step})
				}
			}
			ap.commandGroups = append(ap.commandGroups, cg)
		}
	}
	return nil
}