Pin a local-source install's locally built packages so updates keep them
This commit is contained in:
1 parent
8d069b0c03
commit
947a69ba91
5 files changed
+121
No files matched your search
@@ -0,0 +1,78 @@
|
||||
"""Local-source installs pin the packages the ISO built from the checkouts."""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import types
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT / "configs/airootfs/usr/share/omarchy-iso"))
|
||||
sys.modules.setdefault(
|
||||
"orchestrator.archinstall_adapter",
|
||||
types.ModuleType("orchestrator.archinstall_adapter"),
|
||||
)
|
||||
from orchestrator import phases_impl # noqa: E402
|
||||
|
||||
LINE = "IgnorePkg = omarchy-dev omarchy-settings-dev rime-ice-installer"
|
||||
CONF = "[options]\nHoldPkg = pacman glibc\n\n[core]\nInclude = /etc/pacman.d/mirrorlist\n"
|
||||
|
||||
|
||||
class PinLocalPackagesTest(unittest.TestCase):
|
||||
def run_pin(self, root: Path, *, pinned: bool, defer: bool = False):
|
||||
(root / "etc").mkdir()
|
||||
(root / "etc/pacman.conf").write_text(CONF)
|
||||
pinned_file = root / "pinned-packages"
|
||||
if pinned:
|
||||
pinned_file.write_text("omarchy-dev\nomarchy-settings-dev\nrime-ice-installer\n")
|
||||
ctx = types.SimpleNamespace(target=root, username="test", defer_provisioning=defer)
|
||||
with mock.patch.object(phases_impl, "PINNED_PACKAGES", pinned_file), \
|
||||
mock.patch.object(phases_impl.subprocess, "run") as run:
|
||||
phases_impl.pin_local_packages(ctx)
|
||||
phases_impl.pin_local_packages(ctx)
|
||||
return run
|
||||
|
||||
def test_pins_once_and_installs_refresh_hook(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
run = self.run_pin(root, pinned=True)
|
||||
self.assertEqual((root / "etc/pacman.conf").read_text(), CONF.replace("[options]\n", f"[options]\n{LINE}\n"))
|
||||
hook = root / "home/test/.config/omarchy/hooks/pre-refresh-pacman.d/pin-local-packages"
|
||||
self.assertIn(f'line="{LINE}"', hook.read_text())
|
||||
self.assertTrue(hook.stat().st_mode & 0o111)
|
||||
run.assert_called_with(
|
||||
["arch-chroot", str(root), "chown", "-R", "test:test", "/home/test/.config/omarchy/hooks"],
|
||||
check=True,
|
||||
)
|
||||
|
||||
def test_hook_restores_the_pin_after_a_refresh(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
self.run_pin(root, pinned=True)
|
||||
hook = root / "home/test/.config/omarchy/hooks/pre-refresh-pacman.d/pin-local-packages"
|
||||
conf = root / "pacman.conf"
|
||||
conf.write_text(CONF)
|
||||
script = hook.read_text().replace("/etc/pacman.conf", str(conf)).replace("sudo ", "")
|
||||
for _ in range(2):
|
||||
subprocess.run(["bash", "-c", script], check=True)
|
||||
self.assertEqual(conf.read_text(), CONF.replace("[options]\n", f"[options]\n{LINE}\n"))
|
||||
|
||||
def test_deferred_install_pins_without_a_user_hook(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
run = self.run_pin(root, pinned=True, defer=True)
|
||||
self.assertIn(LINE, (root / "etc/pacman.conf").read_text())
|
||||
self.assertFalse((root / "home").exists())
|
||||
run.assert_not_called()
|
||||
|
||||
def test_published_builds_stay_unpinned(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
self.run_pin(root, pinned=False)
|
||||
self.assertEqual((root / "etc/pacman.conf").read_text(), CONF)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user