def init(self, pre_develop_repo_name, develop_repo_name, meta_repo_name, slug_prefix="company", arti_url=None, arti_user=None, arti_password=None): self.slug_prefix = slug_prefix self.arti_url = arti_url or "http://localhost:8090/artifactory" self.arti_user = arti_user or "admin" self.arti_password = arti_password or "password" self.art = Artifactory(self.arti_url, self.arti_user, self.arti_password) self.develop_repo_name = develop_repo_name self.pre_develop_repo_name = pre_develop_repo_name self.meta_repo_name = meta_repo_name self.travis = TravisMock() self.github = GithubMock(self.travis) self.repo_develop = self.art.create_repo(develop_repo_name) self.repo_pre_develop = self.art.create_repo(pre_develop_repo_name) try: self.repo_meta = self.art.create_repo(meta_repo_name).as_meta() except: meta = self.art.get_repo(meta_repo_name) meta.remove() self.repo_meta = self.art.create_repo(meta_repo_name).as_meta() self.logger = JsonLogger() # Register a repo in travis that will be the one building single jobs self.register_build_repo()
def setUp(self): self.art = Artifactory(travis_env["ARTIFACTORY_URL"], travis_env["ARTIFACTORY_USER"], travis_env["ARTIFACTORY_PASSWORD"]) try: self.repo_develop = self.art.create_repo("develop") except: pass self.travis = TravisMock() self.github = GithubMock(self.travis)
def __init__(self): art_url = os.environ["ARTIFACTORY_URL"] art_user = os.environ["ARTIFACTORY_USER"] art_password = os.environ["ARTIFACTORY_PASSWORD"] art = Artifactory(art_url, art_user, art_password) self.repo_read = art.get_repo(os.environ["CONAN_CI_READ_REMOTE_NAME"]) self.repo_upload = art.get_repo( os.environ["CONAN_CI_UPLOAD_REMOTE_NAME"]) self.results_remote_path = os.environ["CONAN_CI_REMOTE_RESULTS_PATH"] self.project_lock_remote_path = os.environ[ "CONAN_CI_PROJECT_LOCK_PATH"] self.repo_meta = art.get_meta() self.ref = os.environ["CONAN_CI_REFERENCE"]
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 __init__(self): art_url = os.environ["ARTIFACTORY_URL"] art_user = os.environ["ARTIFACTORY_USER"] art_password = os.environ["ARTIFACTORY_PASSWORD"] art = Artifactory(art_url, art_user, art_password) data = json.loads(os.environ["CONAN_CI_BUILD_JSON"]) self.info = BuildCreateInfo.loads(art, data)
def __init__(self, ci_adapter, ci_caller): self.ci_adapter = ci_adapter self.ci_caller = ci_caller art_url = os.getenv("ARTIFACTORY_URL") art_user = os.getenv("ARTIFACTORY_USER") art_password = os.getenv("ARTIFACTORY_PASSWORD") self.art = Artifactory(art_url, art_user, art_password)
# This node has been created module = {"id": get_module_id(pref), "artifacts": self._get_artifacts(pref), "dependencies": []} bi_modules[module["id"]] = module # Second iteration, build the dependencies for node_id, node in data["graph_lock"]["nodes"].items(): if not node.get("modified"): pref = node["pref"] for require_ref in node.get("requires", []): module_id = get_module_id(require_ref) if module_id in bi_modules: bi_modules[module_id]["dependencies"] = self._get_artifacts(pref) self._merge_modules(bi_modules) if __name__ == "__main__": arti_url = "http://localhost:8090/artifactory" arti_user = "******" arti_password = "******" art = Artifactory(arti_url, arti_user, arti_password) builder = BuildInfoBuilder(art) builder.process_lockfile("ss") builder.process_lockfile("ss") builder.process_lockfile("ss") bi = builder.get_build_info(Build("My_build", "23")) print(bi)
def setUp(self): self.art = Artifactory(travis_env["ARTIFACTORY_URL"], travis_env["ARTIFACTORY_USER"], travis_env["ARTIFACTORY_PASSWORD"]) self.travis = TravisMock() self.github = GithubMock(self.travis)
class TestBasic(unittest.TestCase): def setUp(self): self.art = Artifactory(travis_env["ARTIFACTORY_URL"], travis_env["ARTIFACTORY_USER"], travis_env["ARTIFACTORY_PASSWORD"]) self.repo_develop = self.art.create_repo("develop") self.travis = TravisMock() self.github = GithubMock(self.travis) try: self.repo_meta = self.art.create_repo("meta") except: meta = self.art.get_repo("meta") meta.remove() self.repo_meta = self.art.create_repo("meta") def tearDown(self): self.repo_develop.remove() repos = self.art.list_repos() for r in repos: if r.name.startswith("company_"): r.remove() def _store_meta(self, profiles, project_refs): for name, contents in profiles.items(): self.repo_meta.deploy_contents("profiles/{}".format(name), contents) p_json = {"projects": project_refs} self.repo_meta.deploy_contents("projects.json", json.dumps(p_json)) @staticmethod def _complete_ref(name): if "/" not in name: return "{}/1.0@conan/stable".format(name) return name def _complete_refs(self, tree): new_tree = {} for ref, reqs in tree.items(): new_tree[self._complete_ref(ref)] = [ self._complete_ref(r) for r in reqs ] return new_tree def get_slug(self, name): slug = "company/{}".format(name) return 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) 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 register_build_repo(self): slug = "company/build_node" repo = self.github.create_repository(slug, {"foo": "bar"}) repo.checkout_copy("master") # By default the mock creates develop 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() self.travis.register_env_vars(slug, travis_env) self.travis.register_repo(slug, repo, action) def test_basic(self): projects = ["P1", "P2"] profiles = { "linux_gcc7_64": linux_gcc7_64, "linux_gcc7_32": linux_gcc7_32 } tree = { "P1": ["FF", "CC", "DD"], "P2": ["FF"], "CC": ["BB"], "DD": ["BB"], "BB": ["AA"], "FF": ["AA"], "AA": [] } """tree = {"P1": ["AA"], "P2": ["AA"]}""" tree = self._complete_refs(tree) projects = [self._complete_ref(p) for p in projects] self._store_meta(profiles, projects) for p in projects: self.create_gh_repo(tree, p, upload_recipe=True) # Register a repo in travis that will be the one building single jobs self.register_build_repo() # Create a branch on AA an open pull request repo = self.github.repos[self.get_slug("AA")] repo.checkout_copy("feature/cool1") message_commit = "Here we go!" repo.commit_files({"myfile.txt": "Modified myfile: pepe"}, message_commit) # Generate binary for EE merging the PR # pr_number = self.github.open_pull_request("lasote/EE", "company/EE") # self.github.merge_pull_request(pr_number) # We don't use forks because the env vars wouldn't be available pr_number = self.github.open_pull_request("company/AA", "develop", "company/AA", "feature/cool1") self.github.merge_pull_request(pr_number) # TODO: asserts print("Breakpoint")
def loads(art: Artifactory, data): return ReposBuild(art.get_repo(data["read"]), art.get_repo(data["write"]), art.get_repo(data["meta"]).as_meta())
class BaseTest(unittest.TestCase): repo_meta: MetaRepo def init(self, pre_develop_repo_name, develop_repo_name, meta_repo_name, slug_prefix="company", arti_url=None, arti_user=None, arti_password=None): self.slug_prefix = slug_prefix self.arti_url = arti_url or "http://*****:*****@")[0].split("/")[0] return "{}/{}".format(self.slug_prefix, name) def tearDown(self): self.repo_develop.remove() self.repo_pre_develop.remove() repos = self.art.list_repos() for r in repos: if r.name.startswith("{}_".format(self.slug_prefix)): r.remove() def get_travis_env(self): travis_env = { "CONAN_LOGIN_USERNAME": self.arti_user, "CONAN_PASSWORD": self.arti_password, "ARTIFACTORY_URL": self.arti_url, "ARTIFACTORY_USER": self.arti_user, "ARTIFACTORY_PASSWORD": os.getenv("ARTIFACTORY_PASSWORD", "password"), "CONAN_REVISIONS_ENABLED": os.getenv("CONAN_REVISIONS_ENABLED", "1") } return travis_env def populate_meta_repo(self, profiles, project_refs): for name, contents in profiles.items(): self.repo_meta.deploy_contents("profiles/{}".format(name), contents) p_json = { "projects": project_refs, "repos_branches": { "develop": self.develop_repo_name } } self.repo_meta.deploy_contents("config.json", json.dumps(p_json)) @staticmethod def _complete_ref(name): if "/" not in name: return "{}/1.0@conan/stable".format(name) return name def _complete_refs(self, tree): new_tree = {} for ref, reqs in tree.items(): new_tree[self._complete_ref(ref)] = [ self._complete_ref(r) for r in reqs ] return new_tree def register_build_repo(self): slug = "company/build_node" repo = self.github.create_repository(slug, {"foo": "bar"}) repo.checkout_copy("master") # By default the mock creates develop def action(): """ This simulates the yml script of a repository of a library :return: """ main_job = ConanCreateJob() with environment_append({"CONAN_USER_HOME": os.getcwd()}): main_job.run() self.travis.register_env_vars(slug, self.get_travis_env()) self.travis.register_repo(slug, repo, action) def create_gh_repo(self, slug, files): if self.github.repos.get(slug): return # Register the repo on Github repo = self.github.create_repository(slug, files) # Register the repo on travis self.travis.register_env_vars(slug, self.get_travis_env()) 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() 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) return tmp 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