Beispiel #1
0
 def test_get_remote_url(self):
     url = scm.get_remote_url()
     if self.with_git:
         self.assertEqual(url,
                          'https://github.com/cplee/github-actions-demo')
     else:
         self.assertEqual(url, '')
Beispiel #2
0
    def load(
        engine_name=None,
        resman_name=None,
        config_file=None,
        workspace_dir=os.getcwd(),
        reuse=False,
        dry_run=False,
        quiet=False,
        skip_pull=False,
        skip_clone=False,
        pty=False,
        allow_undefined_secrets_in_ci=False,
    ):
        """Loads and creates a configuration, represented by a frozen Box
        """
        workspace_dir = os.path.realpath(workspace_dir)
        repo = scm.new_repo(workspace_dir)

        # path to cache
        if os.environ.get("POPPER_CACHE_DIR", None):
            cache_dir = os.environ["POPPER_CACHE_DIR"]
        else:
            cache_dir_default = os.path.join(os.environ["HOME"], ".cache")
            cache_dir = os.environ.get("XDG_CACHE_HOME", cache_dir_default)
            cache_dir = os.path.join(cache_dir, "popper")

        from_file = ConfigLoader.__load_config_from_file(
            config_file, engine_name, resman_name
        )

        pp_config = {
            "workspace_dir": workspace_dir,
            "reuse": reuse,
            "dry_run": dry_run,
            "quiet": quiet,
            "skip_pull": skip_pull,
            "skip_clone": skip_clone,
            "pty": pty,
            "allow_undefined_secrets_in_ci": allow_undefined_secrets_in_ci,
            # if no git repository exists in workspace_dir or its parents, the repo
            # variable is None and all git_* variables are assigned to 'na'
            "repo": repo,
            "git_commit": scm.get_sha(repo),
            "git_sha_short": scm.get_sha(repo, short=7),
            "git_branch": scm.get_branch(repo),
            "git_tag": scm.get_tag(repo),
            "git_remote_origin_url": scm.get_remote_url(repo),
            # wid is used to associate a unique id to this workspace. This is then
            # used by runners to name resources in a way that there is no name
            # clash between concurrent workflows being executed
            "wid": shake_256(workspace_dir.encode("utf-8")).hexdigest(4),
            "cache_dir": cache_dir,
            "engine_name": from_file["engine_name"],
            "resman_name": from_file["resman_name"],
            "engine_opts": from_file["engine_opts"],
            "resman_opts": from_file["resman_opts"],
        }

        return Box(pp_config, default_box=True, frozen_box=True)
Beispiel #3
0
    def test_without_git(self):
        shutil.move(self.gitdir, self.gotdor)

        # root folder
        root_folder = scm.get_project_root_folder(None)
        self.assertEqual(os.path.realpath(root_folder),
                         os.path.realpath(os.path.join(self.tempdir, 'bin')))

        # get_remote_url
        self.assertEqual(scm.get_remote_url(None), '')

        # get sha
        sha = scm.get_sha(None)
        self.assertEqual(sha, 'na')
Beispiel #4
0
    def test_with_git(self):

        if not os.path.exists(self.gitdir):
            shutil.move(self.gotdor, self.gitdir)

        # root folder
        root_folder = scm.get_project_root_folder(self.repo)
        self.assertEqual(os.path.realpath(root_folder),
                         os.path.realpath(os.path.join(self.tempdir, 'bin')))

        # get_remote_url
        url = scm.get_remote_url(self.repo)
        auth_token = os.getenv('GITHUB_API_TOKEN')
        if not auth_token:
            self.assertEqual(url, 'https://github.com/popperized/bin')
        else:
            self.assertTrue('github.com/popperized/bin' in url)

        # get sha
        sha = scm.get_sha(self.repo)
        expected = self.repo.git.rev_parse(self.repo.head.object.hexsha,
                                           short=True)
        self.assertEqual(sha, expected)
Beispiel #5
0
    def test_get_remote_url(self):
        repo = self.mk_repo()
        url = scm.get_remote_url(repo)
        self.assertEqual(url, "https://github.com/my/repo")

        self.assertEqual(scm.get_remote_url(None), "")