def run()

in builder/actions/script.py [0:0]


    def run(self, env):
        sh = env.shell

        def _expand_vars(cmd):
            cmd_type = type(cmd)
            if cmd_type == str:
                cmd = replace_variables(cmd, env.config['variables'])
            elif cmd_type == list:
                cmd = [replace_variables(sub, env.config['variables']) for sub in cmd]
            return cmd

        # Interpolate any variables
        self.commands = [_expand_vars(cmd) for cmd in self.commands]

        # Run each of the commands
        children = []
        for cmd in self.commands:
            cmd_type = type(cmd)
            # See if the string is actually an action
            if cmd_type == str:
                action_cls = Scripts.find_action(cmd)
                if action_cls:
                    cmd = action_cls()
                    cmd_type = type(cmd)

            if cmd_type == str:
                result = sh.exec(*cmd.split(' '))
                if result.returncode != 0:
                    print('Command failed, exiting')
                    sys.exit(12)
            elif cmd_type == list:
                result = sh.exec(*cmd)
                if result.returncode != 0:
                    print('Command failed, exiting')
                    sys.exit(12)
            elif isinstance(cmd, Action):
                Scripts.run_action(cmd, env)
            elif callable(cmd):
                children += to_list(cmd(env))
            else:
                print('Unknown script sub command: {}: {}', cmd_type, cmd)
                sys.exit(4)
        return children