def remove_action(actions, name):
    """
    Find all the occurrences of actions with a given name and return them and remove them from the list

    :param actions: List of actions
    :param name: str name to find

    :returns: List of actions matching the given name
    """

    matching = [action for action in actions if action.name == name]
    for action in matching:
        actions.remove(action)

    if not matching:
        raise ValueError(f'Action {name} not found')

    return matching