Skip to content

Commit

Permalink
Allow passing versions as list for sync_release
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarcziova committed May 29, 2024
1 parent 1268842 commit 415f98c
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 57 deletions.
42 changes: 25 additions & 17 deletions packit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def check_version_distance(
current,
proposed,
target_branch,
) -> None:
) -> bool:
"""Following this guidelines:
https://docs.fedoraproject.org/en-US/fesco/Updates_Policy/#philosophy
we want to avoid major updates of packages within a **stable** release.
Expand All @@ -771,14 +771,12 @@ def check_version_distance(
and masked_proposed
and masked_current.group(0) != masked_proposed.group(0)
):
raise ReleaseSkippedPackitException(
f"The upstream released version {current} does not match "
f"specfile version {proposed} at branch {target_branch} "
f"using the version_update_mask "
f'"{self.package_config.version_update_mask}".'
"\nYou can change the version_update_mask with an empty string "
"to skip this check.",
logger.debug(
f"Masked {current} and {proposed} ({masked_current} and {masked_proposed}) "
f"do not match.",
)
return False
return True

@staticmethod
def get_upstream_release_monitoring_bug(
Expand Down Expand Up @@ -830,7 +828,7 @@ def get_upstream_release_monitoring_bug(
def sync_release(
self,
dist_git_branch: Optional[str] = None,
version: Optional[str] = None,
versions: Optional[list[str]] = None,
tag: Optional[str] = None,
use_local_content=False,
add_new_sources=True,
Expand All @@ -857,7 +855,7 @@ def sync_release(
def sync_release(
self,
dist_git_branch: Optional[str] = None,
version: Optional[str] = None,
versions: Optional[list[str]] = None,
tag: Optional[str] = None,
use_local_content=False,
add_new_sources=True,
Expand All @@ -883,7 +881,7 @@ def sync_release(
def sync_release(
self,
dist_git_branch: Optional[str] = None,
version: Optional[str] = None,
versions: Optional[list[str]] = None,
tag: Optional[str] = None,
use_local_content=False,
add_new_sources=True,
Expand All @@ -910,7 +908,7 @@ def sync_release(
Args:
dist_git_branch: Branch in dist-git, defaults to repo's default branch.
use_local_content: Don't check out anything.
version: Upstream version to update in dist-git.
versions: List of new upstream versions.
tag: Upstream git tag.
add_new_sources: Download and upload source archives.
force_new_sources: Download/upload the archive even if it's
Expand Down Expand Up @@ -952,13 +950,15 @@ def sync_release(
dist_git_branch = (
dist_git_branch or self.dg.local_project.git_project.default_branch
)
# process version and tag parameters
if version and tag:
version = None
# process versions and tag parameters
if versions and tag:
raise PackitException(
"Function parameters version and tag are mutually exclusive.",
"Function parameters versions and tag are mutually exclusive.",
)
if not tag:
version = version or self.up.get_latest_released_version()
# [FIXME] for now let's just pick the first one
version = versions[0] if versions else self.up.get_latest_released_version()
if not version:
raise PackitException(
"Could not figure out version of latest upstream release. "
Expand Down Expand Up @@ -1054,7 +1054,15 @@ def sync_release(
if compare_versions(version, spec_ver) > 0:
logger.warning(f"Version {spec_ver!r} in spec file is outdated.")

self.check_version_distance(version, spec_ver, dist_git_branch)
if not self.check_version_distance(version, spec_ver, dist_git_branch):
raise ReleaseSkippedPackitException(
f"The upstream released version {version} does not match "
f"specfile version {spec_ver} at branch {dist_git_branch} "
f"using the version_update_mask "
f'"{self.package_config.version_update_mask}".'
"\nYou can change the version_update_mask with an empty string "
"to skip this check.",
)

self.dg.check_last_commit()

Expand Down
6 changes: 3 additions & 3 deletions packit/cli/propose_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def sync_release(
api.sync_release(
dist_git_branch=branch,
use_local_content=local_content,
version=version,
versions=[version],
force_new_sources=force_new_sources,
upstream_ref=upstream_ref,
create_pr=pr,
Expand Down Expand Up @@ -202,7 +202,7 @@ def propose_downstream(
force_new_sources=force_new_sources,
pr=pr,
path_or_url=path_or_url,
version=version,
versions=[version],
force=force,
local_content=local_content,
upstream_ref=upstream_ref,
Expand Down Expand Up @@ -247,7 +247,7 @@ def pull_from_upstream(
force_new_sources=force_new_sources,
pr=pr,
path_or_url=path_or_url,
version=version,
versions=[version],
force=force,
local_content=False,
upstream_ref=None,
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_source_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_basic_local_update_without_patching(

api_instance_source_git.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
upstream_ref="0.1.0",
mark_commit_origin=True,
)
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_basic_local_update_empty_patch(
mock_spec_download_remote_s(distgit)
api_instance_source_git.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
upstream_ref=ref,
)

Expand Down Expand Up @@ -176,7 +176,7 @@ def test_basic_local_update_patch_content(

api_instance_source_git.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
upstream_ref="0.1.0",
mark_commit_origin=False,
)
Expand Down Expand Up @@ -322,7 +322,7 @@ def test_basic_local_update_patch_content_with_metadata(

api_instance_source_git.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
upstream_ref="0.1.0",
)

Expand Down Expand Up @@ -371,7 +371,7 @@ def test_basic_local_update_patch_content_with_metadata_and_patch_ignored(

api_instance_source_git.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
upstream_ref="0.1.0",
)

Expand Down Expand Up @@ -411,7 +411,7 @@ def test_basic_local_update_patch_content_with_downstream_patch(

api_instance_source_git.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
upstream_ref="0.1.0",
)

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_source_git_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def check_ready_api_dg_first(
mock_spec_download_remote_s(distgit)
api_instance_update_source_git.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
upstream_ref="0.1.0",
mark_commit_origin=True,
)
Expand Down Expand Up @@ -52,7 +52,7 @@ def check_ready_api_sg_first(
mock_spec_download_remote_s(distgit)
api_instance_update_source_git.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
upstream_ref="0.1.0",
mark_commit_origin=True,
)
Expand Down
49 changes: 35 additions & 14 deletions tests/integration/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_basic_local_update(
flexmock(api).should_receive("init_kerberos_ticket").at_least().once()
flexmock(Specfile).should_call("reload").once()

api.sync_release(dist_git_branch="main", version="0.1.0")
api.sync_release(dist_git_branch="main", versions=["0.1.0"])

assert (d / TARBALL_NAME).is_file()
spec = Specfile(d / "beer.spec")
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_basic_local_update_no_upload_to_lookaside(
).once()

api.package_config.upload_sources = False
api.sync_release(dist_git_branch="main", version="0.1.0")
api.sync_release(dist_git_branch="main", versions=["0.1.0"])

assert (d / TARBALL_NAME).is_file()
spec = Specfile(d / "beer.spec")
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_basic_local_update_use_downstream_specfile(

api.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
use_downstream_specfile=True,
)

Expand All @@ -131,7 +131,7 @@ def test_basic_local_update_use_downstream_specfile(
# do this second time to see whether the specfile is updated correctly
api.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
use_downstream_specfile=True,
)

Expand Down Expand Up @@ -175,7 +175,10 @@ def test_basic_local_update_with_multiple_sources(
offline=False,
)

api.sync_release(dist_git_branch="main", version="0.1.0")
api.sync_release(
dist_git_branch="main",
versions=["0.1.0"],
)

assert dist_git_first_source.is_file()
assert dist_git_second_source.is_file()
Expand Down Expand Up @@ -224,7 +227,10 @@ def test_basic_local_update_with_adding_second_source(
offline=False,
)

api.sync_release(dist_git_branch="main", version="0.1.0")
api.sync_release(
dist_git_branch="main",
versions=["0.1.0"],
)

assert dist_git_first_source.is_file()
assert dist_git_second_source.is_file()
Expand Down Expand Up @@ -272,7 +278,10 @@ def test_basic_local_update_with_adding_second_local_source(
offline=False,
)

api.sync_release(dist_git_branch="main", version="0.1.0")
api.sync_release(
dist_git_branch="main",
versions=["0.1.0"],
)

assert dist_git_first_source.is_file()
assert dist_git_second_source.is_file()
Expand Down Expand Up @@ -318,7 +327,10 @@ def test_basic_local_update_with_adding_second_local_source_tracked_by_git(
offline=False,
)

api.sync_release(dist_git_branch="main", version="0.1.0")
api.sync_release(
dist_git_branch="main",
versions=["0.1.0"],
)

assert dist_git_first_source.is_file()
assert dist_git_second_source.is_file()
Expand Down Expand Up @@ -359,7 +371,10 @@ def test_basic_local_update_with_removing_second_source(
offline=False,
)

api.sync_release(dist_git_branch="main", version="0.1.0")
api.sync_release(
dist_git_branch="main",
versions=["0.1.0"],
)

assert dist_git_first_source.is_file()
assert not dist_git_second_source.is_file()
Expand Down Expand Up @@ -447,7 +462,10 @@ def test_basic_local_update_copy_upstream_release_description(
get_release=lambda name, tag_name: release,
)
api.package_config.copy_upstream_release_description = True
api.sync_release(dist_git_branch="main", version="0.1.0")
api.sync_release(
dist_git_branch="main",
versions=["0.1.0"],
)

assert (d / TARBALL_NAME).is_file()
spec = Specfile(d / "beer.spec")
Expand Down Expand Up @@ -477,7 +495,10 @@ def test_basic_local_update_using_distgit(
u, d, api = api_instance
mock_spec_download_remote_s(d)

api.sync_release(dist_git_branch="main", version="0.1.0")
api.sync_release(
dist_git_branch="main",
versions=["0.1.0"],
)

assert (d / TARBALL_NAME).is_file()
spec = Specfile(d / "beer.spec")
Expand Down Expand Up @@ -511,7 +532,7 @@ def test_basic_local_update_direct_push(
_, distgit_remote = distgit_and_remote
mock_spec_download_remote_s(d)

api.sync_release(dist_git_branch="main", version="0.1.0", create_pr=False)
api.sync_release(dist_git_branch="main", versions=["0.1.0"], create_pr=False)

remote_dir_clone = Path(f"{distgit_remote}-clone")
subprocess.check_call(
Expand All @@ -538,7 +559,7 @@ def test_update_downstream_changelog_even_if_has_autochangelog(
api.package_config.sync_changelog = True
api.sync_release(
dist_git_branch="main",
version="0.1.0",
versions=["0.1.0"],
create_pr=False,
add_new_sources=False,
)
Expand Down Expand Up @@ -566,7 +587,7 @@ def test_basic_local_update_direct_push_no_dg_spec(
_, distgit_remote = distgit_and_remote
mock_spec_download_remote_s(d)

api.sync_release(dist_git_branch="main", version="0.1.0", create_pr=False)
api.sync_release(dist_git_branch="main", versions=["0.1.0"], create_pr=False)

remote_dir_clone = Path(f"{distgit_remote}-clone")
subprocess.check_call(
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_using_cockpit.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def mocked_new_sources(sources=None):
api.sync_release(
dist_git_branch="main",
use_local_content=False,
version="179",
versions=["179"],
force_new_sources=False,
create_pr=True,
)
Expand Down Expand Up @@ -119,7 +119,7 @@ def mocked_new_sources(sources=None):
assert pr == api.sync_release(
dist_git_branch="main",
use_local_content=False,
version="179",
versions=["179"],
force_new_sources=False,
create_pr=True,
)
Expand Down
Loading

0 comments on commit 415f98c

Please sign in to comment.