Пример #1
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)
Пример #2
0
    def test_empty_repo(self):
        tempdir = tempfile.mkdtemp()
        repo = git.Repo.init(tempdir)
        self.assertTrue(scm.is_empty(repo))

        self.assertIsNone(scm.get_sha(repo))
        self.assertIsNone(scm.get_branch(repo))
        self.assertIsNone(scm.get_tag(repo))

        repo = self.mk_repo()
        self.assertFalse(scm.is_empty(repo))
Пример #3
0
    def test_get_branch_in_detached_head_state(self):
        repo = self.mk_repo()

        repo.git.checkout("HEAD~1")

        os.environ["TRAVIS_BRANCH"] = "travis"
        self.assertEqual("travis", scm.get_branch(repo))
        os.environ.pop("TRAVIS_BRANCH")

        os.environ["GIT_BRANCH"] = "jenkins"
        self.assertEqual("jenkins", scm.get_branch(repo))
        os.environ.pop("GIT_BRANCH")

        os.environ["CIRCLE_BRANCH"] = "circle"
        self.assertEqual("circle", scm.get_branch(repo))
        os.environ.pop("CIRCLE_BRANCH")

        os.environ["CI_COMMIT_REF_NAME"] = "gitlab"
        self.assertEqual("gitlab", scm.get_branch(repo))
        os.environ.pop("CI_COMMIT_REF_NAME")

        self.assertEqual(scm.get_sha(repo), scm.get_branch(repo))

        # None given as arg
        self.assertIsNone(scm.get_sha(None))
        self.assertIsNone(scm.get_sha(None, short=8))
        self.assertIsNone(scm.get_branch(None))