def test_update_from_same_commit(tmp_path: Path, package_name, branch): """ Run an update twice from the same commit. This is to check the an initial source-git generation and updating an existing source-git repo produces the same result (the same commits and content). """ dist_git_path = tmp_path / "d" / package_name sg_path = tmp_path / "s" / package_name dist_git_path.mkdir(parents=True) sg_path.mkdir(parents=True) clone_package_rpms(package_name, dist_git_path, branch=branch) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{branch}", f"{sg_path}:{branch}" ]) # the source-git repo cannot be dirty after the conversion assert_repo_is_not_dirty(sg_path) sg_repo = git.Repo(path=sg_path) upstream_ref = START_TAG_TEMPLATE.format(branch=branch) first_round_commits = list(sg_repo.iter_commits(f"{upstream_ref}..HEAD")) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{branch}", f"{sg_path}:{branch}" ]) assert_repo_is_not_dirty(sg_path) second_round_commits = list(sg_repo.iter_commits(f"{upstream_ref}..HEAD")) run_packit( ["--debug", "srpm", "."], working_dir=sg_path, # _srcrpmdir rpm macro is set to /, let's CWD then ) srpms = list(sg_path.glob("*.src.rpm")) assert srpms, "No src.rpm found" # Check that patch commits are same assert len(first_round_commits) == len(second_round_commits) # we cannot use git-diff here b/c theu may be additional changes # to tree from %prep after the first conversion for first, second in zip(first_round_commits, second_round_commits): # we could also use first.stats here but it's horribly # inefficient and takes minutes to evaluate for idx, tree in enumerate(first.tree.trees): if tree.path == "autom4te.cache": # cache, which can change continue assert tree == second.tree.trees[idx] assert first.tree.blobs == second.tree.blobs if MOCK_BUILD: subprocess.check_call([ "mock", "--rebuild", "-r", "centos-stream-x86_64", srpms[0], ])
def convert_repo(package_name, dist_git_path, sg_path, branch="c8s"): subprocess.check_call([ "git", "clone", "-b", branch, f"https://git.centos.org/rpms/{package_name}.git", dist_git_path, ]) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{branch}", f"{sg_path}:{branch}" ])
def test_update_from_same_commit(tmp_path: Path, package_name, branch): dist_git_path = tmp_path / "d" / package_name sg_path = tmp_path / "s" / package_name dist_git_path.mkdir(parents=True) sg_path.mkdir(parents=True) subprocess.check_call([ "git", "clone", "-b", branch, f"https://git.centos.org/rpms/{package_name}.git", dist_git_path, ]) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{branch}", f"{sg_path}:{branch}" ]) sg_repo = git.Repo(path=sg_path) first_round_commits = list(sg_repo.iter_commits("sg-start..HEAD")) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{branch}", f"{sg_path}:{branch}" ]) second_round_commits = list(sg_repo.iter_commits("sg-start..HEAD")) run_packit([ "--debug", "srpm", "--output", str(sg_path / f"{package_name}.src.rpm"), str(sg_path), ]) srpm_path = next(sg_path.glob("*.src.rpm")) assert srpm_path.exists() # Check that patch commits are same assert len(first_round_commits) == len(second_round_commits) for first, second in zip(first_round_commits, second_round_commits): assert b"" == subprocess.check_output( ["git", "-C", str(sg_path), "diff", first.hexsha, second.hexsha]) if MOCK_BUILD: subprocess.check_call([ "mock", "--rebuild", "-r", "centos-stream-x86_64", srpm_path, ])
def test_update(tmp_path: Path, package_name, branch): dist_git_path = tmp_path / "d" / package_name sg_path = tmp_path / "s" / package_name dist_git_path.mkdir(parents=True) sg_path.mkdir(parents=True) subprocess.check_call([ "git", "clone", "-b", branch, f"https://git.centos.org/rpms/{package_name}.git", dist_git_path, ]) subprocess.check_call( ["git", "reset", "--hard", "HEAD~1"], cwd=dist_git_path, ) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{branch}", f"{sg_path}:{branch}" ]) subprocess.check_call( ["git", "pull", "origin", branch], cwd=dist_git_path, ) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{branch}", f"{sg_path}:{branch}" ]) run_packit([ "--debug", "srpm", "--output", str(sg_path / f"{package_name}.src.rpm"), str(sg_path), ]) srpm_path = next(sg_path.glob("*.src.rpm")) assert srpm_path.exists() if MOCK_BUILD: subprocess.check_call([ "mock", "--rebuild", "-r", "centos-stream-x86_64", srpm_path, ])
def test_update(tmp_path: Path, package_name, branch): """ perform an update from a previous dist-git commit (HEAD~1) to the last one (HEAD) """ dist_git_path = tmp_path / "d" / package_name sg_path = tmp_path / "s" / package_name dist_git_path.mkdir(parents=True) sg_path.mkdir(parents=True) clone_package_rpms(package_name, dist_git_path, branch=branch) subprocess.check_call( ["git", "reset", "--hard", "HEAD~1"], cwd=dist_git_path, ) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{branch}", f"{sg_path}:{branch}" ]) # the source-git repo cannot be dirty after the conversion assert_repo_is_not_dirty(sg_path) subprocess.check_call( ["git", "pull", "origin", branch], cwd=dist_git_path, ) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{branch}", f"{sg_path}:{branch}" ]) assert_repo_is_not_dirty(sg_path) run_packit( ["--debug", "srpm", "."], working_dir=sg_path, # _srcrpmdir rpm macro is set to /, let's CWD then ) srpms = list(sg_path.glob("*.src.rpm")) assert srpms, "No src.rpm found" if MOCK_BUILD: subprocess.check_call([ "mock", "--rebuild", "-r", "centos-stream-x86_64", srpms[0], ])
def test_update_catch(tmp_path: Path): """ make sure we can update package catch and check the repo is in expected state after the update """ package = "catch" dist_git_path = tmp_path / "d" / package dg_branch = "c8" source_git_path = tmp_path / "s" / package sg_branch = "c8" clone_package_rpms(package, dist_git_path, branch=dg_branch) clone_package_src( package, source_git_path, branch=sg_branch, ) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{dg_branch}", f"{source_git_path}:{sg_branch}", ]) assert_repo_is_not_dirty(source_git_path) run_packit( ["--debug", "srpm", "."], working_dir=source_git_path, ) srpms = list(source_git_path.glob("*.src.rpm")) assert srpms, "No src.rpm found" git_log_out = subprocess.check_output( ["git", "log", "--pretty=format:%s", "origin/c8.."], cwd=source_git_path).decode() # the line below is really fragile # if it breaks, navigate to the source-git repo and check git history assert (git_log_out == """Changes after running %prep Add sources defined in the spec file Add spec-file for the distribution .packit.yaml catch-2.2.1 base Prepare for a new update""")
def test_update_existing(tmp_path: Path, package): """ Jirka found an issue that we cannot update several packages which were created by an old version of d2s, one of them is apr """ dist_git_path = tmp_path / "d" / package dg_branch = "c8s" source_git_path = tmp_path / "s" / package sg_branch = "c8s" clone_package_rpms(package, dist_git_path, branch=dg_branch) clone_package_src(package, source_git_path, branch=sg_branch) run_dist2src([ "-vvv", "convert", f"{dist_git_path}:{dg_branch}", f"{source_git_path}:{sg_branch}", ]) assert_repo_is_not_dirty(source_git_path) run_packit( ["--debug", "srpm", "."], working_dir=source_git_path, ) srpms = list(source_git_path.glob("*.src.rpm")) assert srpms, "No src.rpm found"