mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-06-16 11:36:16 +08:00
fix(updater): use resolved ref for tag updates
This commit is contained in:
parent
cb64103161
commit
1dd0a37541
84
.github/workflows/dependencies/test_updater_ref_selection.py
vendored
Normal file
84
.github/workflows/dependencies/test_updater_ref_selection.py
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
import importlib.util
|
||||
import pathlib
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
|
||||
UPDATER_PATH = pathlib.Path(__file__).with_name("updater.py")
|
||||
|
||||
|
||||
def load_updater_module():
|
||||
spec = importlib.util.spec_from_file_location("omz_dependencies_updater", UPDATER_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
class UpdateRefSelectionTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.updater = load_updater_module()
|
||||
|
||||
def _run_update(self, values, status):
|
||||
dependency = self.updater.Dependency("plugins/example", values)
|
||||
|
||||
with mock.patch.object(
|
||||
self.updater.GitHub, "check_newer_tag", return_value=status
|
||||
) as check_newer_tag, mock.patch.object(
|
||||
self.updater.GitHub, "check_updates", return_value=status
|
||||
) as check_updates, mock.patch.object(
|
||||
self.updater.Git, "checkout_or_create_branch", return_value="branch"
|
||||
), mock.patch.object(
|
||||
self.updater.Git, "repo_is_clean", return_value=True
|
||||
), mock.patch.object(
|
||||
self.updater.Git, "clean_repo"
|
||||
), mock.patch.object(
|
||||
dependency, "_Dependency__apply_upstream_changes"
|
||||
) as apply_changes:
|
||||
dependency.update_or_notify()
|
||||
|
||||
return apply_changes, check_newer_tag, check_updates
|
||||
|
||||
def test_should_use_resolved_tag_if_dependency_tracks_tag_versions(self):
|
||||
values = {
|
||||
"repo": "ohmyzsh/example",
|
||||
"branch": "master",
|
||||
"version": "tag:v1.0.0",
|
||||
}
|
||||
status = {
|
||||
"has_updates": True,
|
||||
"version": "v1.2.0",
|
||||
"compare_url": "https://example.com/compare",
|
||||
"head_ref": "abcdef1234567890",
|
||||
"head_url": "https://example.com/releases/v1.2.0",
|
||||
}
|
||||
|
||||
apply_changes, check_newer_tag, check_updates = self._run_update(values, status)
|
||||
|
||||
apply_changes.assert_called_once_with("v1.2.0")
|
||||
check_newer_tag.assert_called_once_with("ohmyzsh/example", "v1.0.0")
|
||||
check_updates.assert_not_called()
|
||||
|
||||
def test_should_keep_using_configured_branch_if_dependency_tracks_branch_head(self):
|
||||
values = {
|
||||
"repo": "ohmyzsh/example",
|
||||
"branch": "master",
|
||||
"version": "abcdef12",
|
||||
}
|
||||
status = {
|
||||
"has_updates": True,
|
||||
"version": "fedcba9876543210",
|
||||
"compare_url": "https://example.com/compare",
|
||||
"head_ref": "fedcba9876543210",
|
||||
"head_url": "https://example.com/commit/fedcba98",
|
||||
}
|
||||
|
||||
apply_changes, check_newer_tag, check_updates = self._run_update(values, status)
|
||||
|
||||
apply_changes.assert_called_once_with("master")
|
||||
check_updates.assert_called_once_with("ohmyzsh/example", "master", "abcdef12")
|
||||
check_newer_tag.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
8
.github/workflows/dependencies/updater.py
vendored
8
.github/workflows/dependencies/updater.py
vendored
@ -219,6 +219,7 @@ class Dependency:
|
||||
if status["has_updates"] is True:
|
||||
short_sha = status["head_ref"][:8]
|
||||
new_version = status["version"] if is_tag else short_sha
|
||||
source_ref = new_version if is_tag else remote_branch
|
||||
|
||||
try:
|
||||
branch_name = f"update/{self.path}/{new_version}"
|
||||
@ -227,7 +228,7 @@ class Dependency:
|
||||
branch = Git.checkout_or_create_branch(branch_name)
|
||||
|
||||
# Update dependency files
|
||||
self.__apply_upstream_changes()
|
||||
self.__apply_upstream_changes(source_ref)
|
||||
|
||||
if not Git.repo_is_clean():
|
||||
# Update dependencies.yml file
|
||||
@ -297,7 +298,7 @@ Check out the [list of changes]({status["compare_url"]}).
|
||||
dep_yaml = DependencyStore.update_dependency_version(self.path, new_version)
|
||||
DependencyStore.write_store(DEPS_YAML_FILE, dep_yaml)
|
||||
|
||||
def __apply_upstream_changes(self) -> None:
|
||||
def __apply_upstream_changes(self, ref: str) -> None:
|
||||
# Patterns to ignore in copying files from upstream repo
|
||||
GLOBAL_IGNORE = [".git", ".github", ".gitignore"]
|
||||
|
||||
@ -306,12 +307,11 @@ Check out the [list of changes]({status["compare_url"]}).
|
||||
postcopy = self.values.get("postcopy")
|
||||
|
||||
repo = self.values["repo"]
|
||||
branch = self.values["branch"]
|
||||
remote_url = f"https://github.com/{repo}.git"
|
||||
repo_dir = os.path.join(TMP_DIR, repo)
|
||||
|
||||
# Clone repository
|
||||
Git.clone(remote_url, branch, repo_dir, reclone=True)
|
||||
Git.clone(remote_url, ref, repo_dir, reclone=True)
|
||||
|
||||
# Run precopy on tmp repo
|
||||
if precopy is not None:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user