Beispiel #1
0
    def create_org(self):
        """ Uses heroku force:org:create to create the org """
        if not self.config_file:
            # FIXME: raise exception
            return
        if not self.scratch_org_type:
            self.config['scratch_org_type'] = 'workspace'

        command = 'heroku force:org:create -t {} -f {}'.format(
            self.scratch_org_type, self.config_file)
        self.logger.info(
            'Creating scratch org with command {}'.format(command))
        p = sarge.Command(command, stdout=sarge.Capture(buffer_size=-1))
        p.run()

        org_info = None
        re_obj = re.compile(
            'Successfully created workspace org: (.+), username: (.+)')
        for line in p.stdout:
            match = re_obj.search(line)
            if match:
                self.config['org_id'] = match.group(1)
                self.config['username'] = match.group(2)
            self.logger.info(line)

        if p.returncode:
            # FIXME: raise exception
            raise ConfigError('Failed to create scratch org: {}'.format(
                '\n'.join(p.stdout)))

        # Flag that this org has been created
        self.config['created'] = True
Beispiel #2
0
    def _validate_package_api_format(self):
        api_version = str(self.project__package__api_version)

        if not API_VERSION_RE.match(api_version):
            message = (
                f"Package API Version must be in the form 'XX.0', found: {api_version}"
            )
            raise ConfigError(message)
Beispiel #3
0
 def _validate_key(self):
     if not self.key:
         raise KeychainKeyNotFound(
             "The CUMULUSCI_KEY environment variable is not set.")
     if len(self.key) != 16:
         raise ConfigError(
             "The CUMULUSCI_KEY environment variable must be 16 characters long."
         )
Beispiel #4
0
 def _init_bulk(self):
     version = self.api_version or self.project_config.project__package__api_version
     if not version:
         raise ConfigError("Cannot find Salesforce version")
     return SalesforceBulk(
         host=self.org_config.instance_url.replace("https://", "").rstrip("/"),
         sessionId=self.org_config.access_token,
         API_version=version,
     )
Beispiel #5
0
 def _check_infinite_flows(self, tasks, flows=None):
     if flows == None:
         flows = []
     for task in tasks.values():
         if 'flow' in task:
             flow = task['flow']
             if flow in flows:
                 raise ConfigError('Infinite flows detected')
             flows.append(flow)
             flow_config = self.project_config.get_flow(flow)
             self._check_infinite_flows(flow_config.tasks, flows)
Beispiel #6
0
 def _validate_required_git_info(self, info):
     """Ensures that we have the required git info or throw a ConfigError"""
     validate = {
         # <key>: <env var to manually override>
         "branch": "CUMULUSCI_REPO_BRANCH",
         "commit": "CUMULUSCI_REPO_COMMIT",
         "name": "CUMULUSCI_REPO_URL",
         "owner": "CUMULUSCI_REPO_URL",
         "root": "CUMULUSCI_REPO_ROOT",
         "url": "CUMULUSCI_REPO_URL",
     }
     for key, env_var in list(validate.items()):
         if key not in info or not info[key]:
             message = f"Detected CI on {info['ci']} but could not determine the repo {key}"
             if env_var:
                 message += f". You can manually pass in the {key} "
                 message += f" with the {env_var} environment variable."
             raise ConfigError(message)
Beispiel #7
0
 def _get_tasks_ordered(self):
     if not self.nested:
         self._check_infinite_flows(self.flow_config.tasks)
     tasks = []
     for step_num, config in list(self.flow_config.tasks.items()):
         if 'flow' in config and 'task' in config:
             raise ConfigError('"flow" and "task" in same config item')
         if (('flow' in config and config['flow'] == 'None')
                 or ('task' in config and config['task'] == 'None')):
             # allows skipping flows/tasks using YAML overrides
             continue
         if 'flow' in config:  # nested flow
             task_config = self.project_config.get_flow(config['flow'])
         elif 'task' in config:
             task_config = self.project_config.get_task(config['task'])
         tasks.append((LooseVersion(str(step_num)), {
             'flow_config': config,
             'task_config': task_config,
         }))
     tasks.sort()  # sort by step number
     return tasks
Beispiel #8
0
    def delete_org(self):
        """ Uses heroku force:org:delete to create the org """
        if not self.created:
            self.logger.info(
                'Skipping org deletion: the scratch org has not been created')
            return

        command = 'heroku force:org:delete --force -u {}'.format(self.username)
        self.logger.info(
            'Deleting scratch org with command {}'.format(command))
        p = sarge.Command(command, stdout=sarge.Capture(buffer_size=-1))
        p.run()

        org_info = None
        for line in p.stdout:
            self.logger.info(line)

        if p.returncode:
            # FIXME: raise exception
            raise ConfigError('Failed to delete scratch org')

        # Flag that this org has been created
        self.config['created'] = False
        self.config['username'] = False
Beispiel #9
0
    def repo_info(self):
        if hasattr(self, '_repo_info'):
            return self._repo_info

        # Detect if we are running in a CI environment and get repo info
        # from env vars for the enviornment instead of .git files
        info = {
            'ci': None
        }

        # Make sure that the CUMULUSCI_AUTO_DETECT environment variable is 
        # set before trying to auto-detect anything from the environment
        if not os.environ.get('CUMULUSCI_AUTO_DETECT'):
            self._repo_info = info
            return self._repo_info

        # Heroku CI
        heroku_ci = os.environ.get('HEROKU_TEST_RUN_ID')
        if heroku_ci:
            info = {
                'branch': os.environ.get('HEROKU_TEST_RUN_BRANCH'),
                'commit': os.environ.get('HEROKU_TEST_RUN_COMMIT_VERSION'),
                'ci': 'heroku',
                'root': '/app',
            }

        # Other CI environment implementations can be implemented here...

        # Apply CUMULUSCI_REPO_* environment variables last so they can
        # override and fill in missing values from the CI environment
        repo_branch = os.environ.get('CUMULUSCI_REPO_BRANCH')
        if repo_branch:
            if repo_branch != info.get('branch'):
                self.logger.info(
                    'CUMULUSCI_REPO_BRANCH found, using its value as the branch'
                )
            info['branch'] = repo_branch
        repo_commit = os.environ.get('CUMULUSCI_REPO_COMMIT')
        if repo_commit:
            if repo_commit != info.get('commit'):
                self.logger.info(
                    'CUMULUSCI_REPO_COMMIT found, using its value as the commit'
                )
            info['commit'] = repo_commit
        repo_root = os.environ.get('CUMULUSCI_REPO_ROOT')
        if repo_root:
            if repo_root != info.get('root'):
                self.logger.info(
                    'CUMULUSCI_REPO_ROOT found, using its value as the repo root'
                )
            info['root'] = repo_root
        repo_url = os.environ.get('CUMULUSCI_REPO_URL')
        if repo_url:
            if repo_url != info.get('url'):
                self.logger.info(
                    'CUMULUSCI_REPO_URL found, using its value as the repo url, owner, and name'
                )
            url_info = self._split_repo_url(repo_url)
            info.update(url_info)

        # If running in a CI environment, make sure we have all the needed
        # git info or throw a ConfigError
        if info['ci']:
            validate = OrderedDict((
                # <key>, <env var to manually override>
                ('branch', 'CUMULUSCI_REPO_BRANCH'),
                ('commit', 'CUMULUSCI_REPO_COMMIT'),
                ('name', 'CUMULUSCI_REPO_URL'),
                ('owner', 'CUMULUSCI_REPO_URL'),
                ('root', 'CUMULUSCI_REPO_ROOT'),
                ('url', 'CUMULUSCI_REPO_URL'),
            ))
            for key, env_var in list(validate.items()):
                if key not in info or not info[key]:
                    message = 'Detected CI on {} but could not determine the repo {}'.format(
                        info['ci'],
                        key,
                    )
                    if env_var:
                        message += '. You can manually pass in the {} with'.format(key)
                        message += ' with the {} environment variable.'.format(env_var)
                    raise ConfigError(message)

        # Log any overrides detected through the environment as a warning
        if len(info) > 1:
            self.logger.info('')
            self.logger.warn(
                'Using environment variables to override repo info:'
            )
            keys = list(info.keys())
            keys.sort()
            for key in keys:
                self.logger.warn(
                    '  {}: {}'.format(key, info[key])
                )
            self.logger.info('')

        self._repo_info = info
        return self._repo_info
Beispiel #10
0
    def repo_info(self):
        if self._repo_info is not None:
            return self._repo_info

        # Detect if we are running in a CI environment and get repo info
        # from env vars for the enviornment instead of .git files
        info = {"ci": None}

        # Make sure that the CUMULUSCI_AUTO_DETECT environment variable is
        # set before trying to auto-detect anything from the environment
        if not os.environ.get("CUMULUSCI_AUTO_DETECT"):
            self._repo_info = info
            return self._repo_info

        # Heroku CI
        heroku_ci = os.environ.get("HEROKU_TEST_RUN_ID")
        if heroku_ci:
            info = {
                "branch": os.environ.get("HEROKU_TEST_RUN_BRANCH"),
                "commit": os.environ.get("HEROKU_TEST_RUN_COMMIT_VERSION"),
                "ci": "heroku",
                "root": "/app",
            }

        # Other CI environment implementations can be implemented here...

        # Apply CUMULUSCI_REPO_* environment variables last so they can
        # override and fill in missing values from the CI environment
        repo_branch = os.environ.get("CUMULUSCI_REPO_BRANCH")
        if repo_branch:
            if repo_branch != info.get("branch"):
                self.logger.info(
                    "CUMULUSCI_REPO_BRANCH found, using its value as the branch"
                )
            info["branch"] = repo_branch
        repo_commit = os.environ.get("CUMULUSCI_REPO_COMMIT")
        if repo_commit:
            if repo_commit != info.get("commit"):
                self.logger.info(
                    "CUMULUSCI_REPO_COMMIT found, using its value as the commit"
                )
            info["commit"] = repo_commit
        repo_root = os.environ.get("CUMULUSCI_REPO_ROOT")
        if repo_root:
            if repo_root != info.get("root"):
                self.logger.info(
                    "CUMULUSCI_REPO_ROOT found, using its value as the repo root"
                )
            info["root"] = repo_root
        repo_url = os.environ.get("CUMULUSCI_REPO_URL")
        if repo_url:
            if repo_url != info.get("url"):
                self.logger.info(
                    "CUMULUSCI_REPO_URL found, using its value as the repo url, owner, and name"
                )
            url_info = self._split_repo_url(repo_url)
            info.update(url_info)

        # If running in a CI environment, make sure we have all the needed
        # git info or throw a ConfigError
        if info["ci"]:
            validate = OrderedDict((
                # <key>, <env var to manually override>
                ("branch", "CUMULUSCI_REPO_BRANCH"),
                ("commit", "CUMULUSCI_REPO_COMMIT"),
                ("name", "CUMULUSCI_REPO_URL"),
                ("owner", "CUMULUSCI_REPO_URL"),
                ("root", "CUMULUSCI_REPO_ROOT"),
                ("url", "CUMULUSCI_REPO_URL"),
            ))
            for key, env_var in list(validate.items()):
                if key not in info or not info[key]:
                    message = "Detected CI on {} but could not determine the repo {}".format(
                        info["ci"], key)
                    if env_var:
                        message += ". You can manually pass in the {} with".format(
                            key)
                        message += " with the {} environment variable.".format(
                            env_var)
                    raise ConfigError(message)

        # Log any overrides detected through the environment as a warning
        if len(info) > 1:
            self.logger.info("")
            self.logger.warning(
                "Using environment variables to override repo info:")
            keys = list(info.keys())
            keys.sort()
            for key in keys:
                self.logger.warning("  {}: {}".format(key, info[key]))
            self.logger.info("")

        self._repo_info = info
        return self._repo_info
 def _validate_key(self):
     if not self.key:
         raise KeychainKeyNotFound("The keychain key was not found.")
     if len(self.key) != 16:
         raise ConfigError("The keychain key must be 16 characters long.")
Beispiel #12
0
 def _validate_key(self):
     if not self.key:
         raise ConfigError('CUMULUSCI_KEY not set')
     if len(self.key) != 16:
         raise ConfigError('CUMULUSCI_KEY must be 16 characters long')