Ejemplo n.º 1
0
    def fire_pr(self, pr_num: int,
                dest_slug: str, dest_branch: str,
                origin_slug: str, origin_branch: str):

        build_folder = tempfile.mkdtemp()

        # Clone the repo
        local_repo = GitRepo(build_folder)
        local_repo.clone(self.repos[origin_slug].folder)
        local_repo.checkout(origin_branch)

        # TODO: make the merge with the origin?
        self.increment_build_number(dest_slug)
        env = {"TRAVIS_BRANCH": dest_branch,
               "TRAVIS_PULL_REQUEST": str(pr_num),
               "TRAVIS_PULL_REQUEST_BRANCH": origin_branch,
               "TRAVIS_BUILD_DIR": local_repo.folder,
               "TRAVIS_COMMIT": local_repo.get_commit(),
               "TRAVIS_PULL_REQUEST_SLUG": dest_slug,
               "TRAVIS_REPO_SLUG": origin_slug,
               "TRAVIS_BUILD_NUMBER": str(self.build_counters[dest_slug])}

        env.update(self.env_vars[origin_slug])

        with environment_append(env):
            with chdir(build_folder):
                self.actions[origin_slug]()
Ejemplo n.º 2
0
    def run_conan_commands(self, commands, package_id_mode, folder=None):
        output = ""
        tmp = folder or tempfile.mkdtemp()

        with environment_append({
                "CONAN_USER_HOME": tmp,
                "CONAN_REVISIONS_ENABLED": "1",
                "CONAN_LOGIN_USERNAME": self.arti_user,
                "CONAN_PASSWORD": self.arti_password,
                "CONAN_NON_INTERACTIVE": "1"
        }):
            with chdir(tmp):
                run("conan config set general.default_package_id_mode={}".
                    format(package_id_mode))
                for c in commands:
                    output += run(c)

        return tmp, output
Ejemplo n.º 3
0
    def fire_build(self, slug: str, branch: str, commit_message: str, api_environ: Dict[str, str]):

        build_folder = tempfile.mkdtemp()

        # Clone the repo
        local_repo = GitRepo(build_folder)
        local_repo.clone(self.repos[slug].folder)
        local_repo.checkout(branch)

        self.increment_build_number(slug)
        travis_env = {"TRAVIS_BRANCH": branch,
                      "TRAVIS_COMMIT_MESSAGE": commit_message,
                      "TRAVIS_BUILD_DIR": local_repo.folder,
                      "TRAVIS_COMMIT": local_repo.get_commit(),
                      "TRAVIS_REPO_SLUG": slug,
                      "TRAVIS_BUILD_NUMBER": str(self.build_counters[slug])}

        api_environ.update(travis_env)
        api_environ.update(self.env_vars[slug])

        with environment_append(api_environ):
            with chdir(build_folder):
                self.actions[slug]()
Ejemplo n.º 4
0
    def create_gh_repo(self, tree, ref, upload_recipe=True):
        name, version = ref.split("@")[0].split("/")
        slug = self.get_slug(name)
        if self.github.repos.get(slug):
            return
        rand = uuid.uuid4()
        reqs = tree.get(ref, [])
        reqs_str = ",".join('"{}"'.format(r) for r in reqs)
        reqs_line = 'requires = {}'.format(reqs_str) if reqs else ""
        cf = conanfile.format(name, version, reqs_line, rand)
        files = {
            "conanfile.py": cf,
            "myfile.txt": "Original content: {}".format(ref)
        }

        # Register the repo on Github
        repo = self.github.create_repository(slug, files)

        # Register the repo on travis
        self.travis.register_env_vars(slug, travis_env)

        def main_action():
            """
            This simulates the yml script of a repository of a library
            :return:
            """
            ci_adapter = TravisCIAdapter()
            # ci_caller = TravisAPICallerMultiThreadMock(self.travis)
            token = os.getenv("TRAVIS_TOKEN")
            ci_caller = TravisAPICaller(self.travis, "lasote/build_node",
                                        token)
            main_job = MainJob(ci_adapter, ci_caller)
            with environment_append({"CONAN_USER_HOME": os.getcwd()}):
                main_job.run()

        self.travis.register_repo(slug, repo, main_action)

        tmp = tempfile.mkdtemp()
        for name, contents in files.items():
            path = os.path.join(tmp, name)
            with open(path, "w") as f:
                f.write(contents)

        if upload_recipe:
            with environment_append({
                    "CONAN_USER_HOME":
                    tmp,
                    "CONAN_REVISIONS_ENABLED":
                    "1",
                    "CONAN_LOGIN_USERNAME":
                    travis_env["CONAN_LOGIN_USERNAME"],
                    "CONAN_PASSWORD":
                    travis_env["CONAN_PASSWORD"],
                    "CONAN_NON_INTERACTIVE":
                    "1"
            }):
                with chdir(tmp):
                    run_command("conan remote add develop {}".format(
                        self.repo_develop.url))
                    run_command("conan export . {}".format(ref))
                    run_command(
                        "conan upload {} -r develop -c --all".format(ref))

        for req in reqs:
            self.create_gh_repo(tree, req, upload_recipe=upload_recipe)
Ejemplo n.º 5
0
 def run(self, command: str):
     with chdir(self.folder):
         ret = os.system(command)
         if ret != 0:
             raise Exception("Command failed: {}".format(command))