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]()
def action(): """ This simulates the yml script of a repository of a library :return: """ main_job = BuildPackageJob() with environment_append({"CONAN_USER_HOME": os.getcwd()}): main_job.run()
def main_action(): """ This simulates the yml script of a repository of a library :return: """ ci_adapter = TravisCIAdapter() ci_caller = TravisAPICallerMultiThreadMock(self.travis) main_job = MainJob(ci_adapter, ci_caller) with environment_append({"CONAN_USER_HOME": os.getcwd()}): main_job.run()
def run(self): # Home at the current dir with environment_append({"CONAN_USER_HOME": cur_folder()}): print( "\n\n\n------------------------------------------------------") print("BUILDING '{}' AT '{}'".format(self.ref, cur_folder())) build_folder = cur_folder() try: run_command('conan remote remove conan-center') except Exception: pass _add_remotes_and_login(self.repo_upload.url, self.repo_read.url) # Download the lock file to the install folder self.repo_meta.download_node_lock(self.project_lock_remote_path, build_folder) run_command("conan graph clean-modified {}".format(build_folder)) run_command('conan remove "*" -f') # Build the ref using the lockfile print( "\n\n****************** INSTALL OUTPUT {} ************************" .format(self.ref)) try: print("CONAN USER HOME: {}".format( os.getenv("CONAN_USER_HOME"))) output = run_command_output( "conan install {} --install-folder {} " "--use-lock --build {}".format(self.ref, build_folder, self.ref)) except Exception as exc: self.repo_meta.store_install_log(self.results_remote_path, str(exc)) self.repo_meta.store_failure(self.results_remote_path) raise exc print(output) print( "************************************************************\n\n" ) self.repo_meta.store_install_log(self.results_remote_path, output) # Upload the packages run_command('conan upload {} --all -r upload_remote'.format( self.ref)) # Upload the modified lockfile to the right location self.repo_meta.store_node_lock(build_folder, self.results_remote_path) print( "\n\n\n------------------------------------------------------") self.repo_meta.store_success(self.results_remote_path)
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()
def run(self): # Home at the current dir with environment_append({"CONAN_USER_HOME": cur_folder()}): try: self.ci_adapter.get_key("pr_number") except KeyError: message = self.ci_adapter.get_key("commit_message") pr_number = get_pull_request_from_message(message) if pr_number: self.run_merge(pr_number) else: self.run_job() else: self.run_pr()
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
def main_action(): """ This simulates the yml script of a repository of a library :return: """ ci_adapter = TravisCIAdapter() # TravisAPICallerMock(self.travis) ci_caller = TravisAPICallerMultiThreadMock(self.travis) art = Artifactory(os.getenv("ARTIFACTORY_URL"), os.getenv("ARTIFACTORY_USER"), os.getenv("ARTIFACTORY_PASSWORD")) repos = ReposBuild(art.get_repo(self.develop_repo_name), art.get_repo(self.pre_develop_repo_name), art.get_repo(self.meta_repo_name).as_meta()) main_job = CoordinatorJob(ci_adapter, ci_caller, self.logger, repos) with environment_append({"CONAN_USER_HOME": os.getcwd()}): main_job.run()
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]()
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)
def run(self): # Home at the current dir with environment_append({"CONAN_USER_HOME": cur_folder()}): conan_home = os.path.join(cur_folder(), ".conan") os.makedirs(conan_home) with open(os.path.join(conan_home, "artifacts.properties"), "w") as fh: fh.write("artifact_property_build.name={}\n" "artifact_property_build.number={}\n" "artifact_property_build.timestamp={}".format(self.info.build.name, self.info.build.number, time.time())) print("\n------------------------------------------------------") print(" CREATE JOB: '{}' AT '{}'".format(self.info.node_info.ref, cur_folder())) print("-----------------------------------------------------\n") build_folder = cur_folder() # Download the lock file to the install folder self.info.repos.meta.download_project_lock(build_folder, self.info.build, self.info.build_conf) docker_image = self.get_docker_image_from_lockfile(build_folder) rcm = docker_runner(docker_image, [build_folder]) if docker_image else regular_runner() # DEBUG CONAN CODE # rcm = regular_runner() with rcm as runner: if False and docker_image: # FIXME: Issue locally runner.run("git clone https://github.com/conan-io/conan.git") try: runner.run("pip uninstall -y conan-package-tools") except: pass runner.run("cd conan && git checkout develop") runner.run("cd conan && pip install -e .") try: runner.run('conan remote remove conan-center') except Exception: pass runner.run('conan --version') runner.run('conan config set general.default_package_id_mode=package_revision_mode') runner.run('conan remote add upload_remote {}'.format(self.info.repos.write.url)) runner.run('conan user -r upload_remote -p') if self.info.repos.write.url != self.info.repos.read.url: runner.run('conan remote add central_remote {}'.format(self.info.repos.read.url)) runner.run('conan user -r central_remote -p') runner.run('conan remove "*" -f') # Build the ref using the lockfile cmd = "conan install {} --lockfile={} " \ "--build {} --install-folder={}".format(self.info.node_info.ref, build_folder, self.info.node_info.ref, build_folder) try: output = runner.run(cmd) print("Package built at: {}".format(build_folder)) print(output) except Exception as exc: self.info.repos.meta.store_install_log(str(exc), self.info.build, self.info.build_conf, self.info.node_info) self.info.repos.meta.store_failure(self.info.build, self.info.build_conf, self.info.node_info) raise exc self.info.repos.meta.store_install_log(output, self.info.build, self.info.build_conf, self.info.node_info) print("******************* BUILD NODE!!!: {}******************".format(self.info.node_info.ref)) node_info = self.get_built_node_id(build_folder) self.info.logger.add_node_stopped_building(node_info) print("******************* BUILD NODE LLAMADO!!!: {}******************".format(self.info.node_info)) # Upload the packages runner.run('conan upload {} --all -r ' 'upload_remote --force'.format(self.info.node_info.ref)) # Upload the modified lockfile to the right location # Here the location for the current node will have "modified": "Build" self.info.repos.meta.store_node_lock(build_folder, self.info.build, self.info.build_conf, self.info.node_info) self.info.repos.meta.store_success(self.info.build, self.info.build_conf, self.info.node_info)