Пример #1
0
    def validate_workflow_block(self):
        """Validate the syntax of the workflow block."""
        if self.wf_fmt == 'yml':
            return

        workflow_block_cnt = len(self.wf_dict.get('workflow', dict()).items())
        if workflow_block_cnt == 0:
            log.fail('A workflow block must be present.')

        if workflow_block_cnt > 1:
            log.fail('Cannot have more than one workflow blocks.')

        workflow_block = list(self.wf_dict['workflow'].values())[0]
        for key in workflow_block.keys():
            if key not in VALID_WORKFLOW_ATTRS:
                log.fail(f"Invalid workflow attribute '{key}'.")

        if not workflow_block.get('resolves', None):
            log.fail('[resolves] attribute must be present in a '
                     'workflow block.')

        if not pu.of_type(workflow_block['resolves'], ['str', 'los']):
            log.fail('[resolves] attribute must be a string or a list '
                     'of strings.')

        if workflow_block.get('on', None):
            if not pu.of_type(workflow_block['on'], ['str']):
                log.fail('[on] attribute mist be a string.')
Пример #2
0
    def validate_workflow_block(self):
        """Validate the syntax of the workflow block.
        """
        workflow_block_cnt = len(
            self.parsed_workflow.get(
                'workflow', dict()).items())
        if workflow_block_cnt == 0:
            log.fail('A workflow block must be present.')

        if workflow_block_cnt > 1:
            log.fail('Cannot have more than one workflow blocks.')

        workflow_block = list(self.parsed_workflow['workflow'].values())[0]
        for key in workflow_block.keys():
            if key not in VALID_WORKFLOW_ATTRS:
                log.fail(
                    'Invalid workflow attribute \'{}\' was found.'.format(key))

        if not workflow_block.get('resolves', None):
            log.fail('[resolves] attribute must be present in a '
                     'workflow block.')

        if not pu.of_type(workflow_block['resolves'], ['str', 'los']):
            log.fail('[resolves] attribute must be a string or a list '
                     'of strings.')

        if workflow_block.get('on', None):
            if not pu.of_type(workflow_block['on'], ['str']):
                log.fail('[on] attribute mist be a string.')
Пример #3
0
    def test_of_type(self):
        param = [u"hello", u"world"]
        self.assertEqual(pu.of_type(param, ['los']), True)

        param = u"hello world"
        self.assertEqual(pu.of_type(param, ['los']), False)

        param = {"org": "systemslab", "project": "popper"}
        self.assertEqual(pu.of_type(param, ['str', 'dict']), True)
Пример #4
0
    def normalize(self):
        """Takes properties from the `self.wf_dict` dict and makes them
        native to the `Workflow` class. Also it normalizes some of the
        attributes of a parsed workflow according to the Github defined
        specifications.

        For example, it changes `args`, `runs` and `secrets` attribute,
        if provided as a string to a list of string by splitting around
        whitespace. Also, it changes parameters like `uses` and `resolves`,
        if provided as a string to a list.

        Args:
            None

        Returns:
            None
        """
        for wf_name, wf_block in self.wf_dict['workflow'].items():

            self.name = wf_name
            self.resolves = wf_block['resolves']
            self.on = wf_block.get('on', 'push')
            self.root = set()
            self.steps = self.wf_dict['steps']
            self.props = dict()

            if pu.of_type(self.resolves, ['str']):
                self.resolves = [self.resolves]

        for a_name, a_block in self.steps.items():
            a_block['name'] = a_name

            if a_block.get('needs', None):
                if pu.of_type(a_block['needs'], ['str']):
                    a_block['needs'] = [a_block['needs']]

            if a_block.get('args', None):
                a_block['args'] = Workflow.format_command(a_block['args'])

            if a_block.get('runs', None):
                a_block['runs'] = Workflow.format_command(a_block['runs'])

            if a_block.get('secrets', None):
                a_block['secrets'] = Workflow.format_command(
                    a_block['secrets'])
Пример #5
0
    def format_command(params):
        """A static method that formats the `runs` and `args` attributes into a
        list of strings.

        Args:
          params(list/str): run or args that are being executed.

        Returns:
            list: List of strings of parameters.
        """
        if pu.of_type(params, ['str']):
            return params.split(" ")
        return params
Пример #6
0
    def validate_action_blocks(self):
        """Validate the syntax of the action blocks.
        """
        self.check_duplicate_actions()
        if not self.parsed_workflow.get('action', None):
            log.fail('Atleast one action block must be present.')

        for _, a_block in self.parsed_workflow['action'].items():
            for key in a_block.keys():
                if key not in VALID_ACTION_ATTRS:
                    log.fail(
                        'Invalid action attribute \'{}\' found.'.format(key))

            if not a_block.get('uses', None):
                log.fail('[uses] attribute must be present in action block.')

            if not pu.of_type(a_block['uses'], ['str']):
                log.fail('[uses] attribute must be a string.')

            if a_block.get('needs', None):
                if not pu.of_type(a_block['needs'], ['str', 'los']):
                    log.fail(
                        '[needs] attribute must be a string or a list '
                        'of strings.')

            if a_block.get('args', None):
                if not pu.of_type(a_block['args'], ['str', 'los']):
                    log.fail(
                        '[args] attribute must be a string or a list '
                        'of strings.')

            if a_block.get('runs', None):
                if not pu.of_type(a_block['runs'], ['str', 'los']):
                    log.fail(
                        '[runs] attribute must be a string or a list '
                        'of strings.')

            if a_block.get('env', None):
                if not pu.of_type(a_block['env'], ['dict']):
                    log.fail('[env] attribute must be a dict.')

            if a_block.get('secrets', None):
                if not pu.of_type(a_block['secrets'], ['str', 'los']):
                    log.fail(
                        '[secrets] attribute must be a string or a list '
                        'of strings.')
Пример #7
0
    def validate_step_blocks(self):
        """Validate the syntax of the step blocks."""
        if not self.wf_dict.get('steps', None):
            log.fail('At least one step block must be present.')

        for _, a_block in self.wf_dict['steps'].items():
            for key in a_block.keys():
                if key not in VALID_STEP_ATTRS:
                    log.fail(f"Invalid step attribute '{key}'.")

            if not a_block.get('uses', None):
                log.fail('[uses] attribute must be present in step block.')

            if not pu.of_type(a_block['uses'], ['str']):
                log.fail('[uses] attribute must be a string.')

            if a_block.get('needs', None):
                if not pu.of_type(a_block['needs'], ['str', 'los']):
                    log.fail('[needs] attribute must be a string or a list '
                             'of strings.')

            if a_block.get('args', None):
                if not pu.of_type(a_block['args'], ['str', 'los']):
                    log.fail('[args] attribute must be a string or a list '
                             'of strings.')

            if a_block.get('runs', None):
                if not pu.of_type(a_block['runs'], ['str', 'los']):
                    log.fail('[runs] attribute must be a string or a list '
                             'of strings.')

            if a_block.get('env', None):
                if not pu.of_type(a_block['env'], ['dict']):
                    log.fail('[env] attribute must be a dict.')

            if a_block.get('secrets', None):
                if not pu.of_type(a_block['secrets'], ['str', 'los']):
                    log.fail('[secrets] attribute must be a string or a list '
                             'of strings.')
Пример #8
0
 def format_command(params):
     """A static method that formats the `runs` and `args`
     attributes into a list of strings."""
     if pu.of_type(params, ['str']):
         return params.split(" ")
     return params