From a297e7c71e0e6c954bce57a22b09fd8b795b1452 Mon Sep 17 00:00:00 2001 From: Vladimir Eremin Date: Fri, 6 Nov 2026 00:40:05 +0300 Subject: [PATCH] fix: allow non-Compose commits on Docker-free hosts [skip ci] --- actions/utils/lint-docker-compose.py | 5 ++-- tests/test_compose_hook.py | 37 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/test_compose_hook.py diff --git a/actions/utils/lint-docker-compose.py b/actions/utils/lint-docker-compose.py index 1933c79..53d992d 100644 --- a/actions/utils/lint-docker-compose.py +++ b/actions/utils/lint-docker-compose.py @@ -12,8 +12,6 @@ def run(ctx, args): log, s = ctx.log, ctx.sys repo = ctx.paths.repo_root rc_ip = _validate_anchor_ips(ctx) - if not shutil.which("docker"): - log.error("docker is not installed or not in PATH."); return rc_ip or 1 files_string, targets = "", ["."] if args.hook: @@ -25,6 +23,9 @@ def run(ctx, args): log.info("No staged docker-compose files to lint."); return rc_ip targets = [f"/workdir/{f}" for f in files_string.splitlines()] + if not shutil.which("docker"): + log.error("docker is not installed or not in PATH."); return rc_ip or 1 + log.info("Running dclint --fix (via docker)...") env_args = [] for k in ("HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy", "NO_PROXY", "no_proxy"): diff --git a/tests/test_compose_hook.py b/tests/test_compose_hook.py new file mode 100644 index 0000000..7bec642 --- /dev/null +++ b/tests/test_compose_hook.py @@ -0,0 +1,37 @@ +import importlib.util +from pathlib import Path +import subprocess +import tempfile +from types import SimpleNamespace +import unittest +from unittest.mock import Mock, patch +from engine.lib.sys import Sys + +spec = importlib.util.spec_from_file_location('compose_lint', Path(__file__).resolve().parents[1] / 'actions/utils/lint-docker-compose.py') +lint = importlib.util.module_from_spec(spec) +spec.loader.exec_module(lint) + + +class HookTests(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.repo = Path(self.tmp.name) + subprocess.run(['git', 'init', '-q', str(self.repo)], check=True) + self.log = Mock() + self.ctx = SimpleNamespace(log=self.log, sys=Sys(self.log), node=None, + paths=SimpleNamespace(repo_root=str(self.repo), compositions=str(self.repo / 'compositions'))) + + def stage(self, name, content): + (self.repo / name).write_text(content) + subprocess.run(['git', '-C', str(self.repo), 'add', name], check=True) + + def test_documentation_commit_does_not_require_docker(self): + self.stage('README.md', 'Documentation\n') + with patch.object(lint.shutil, 'which', return_value=None): + self.assertEqual(lint.run(self.ctx, SimpleNamespace(hook=True)), 0) + + def test_compose_change_still_requires_docker(self): + self.stage('docker-compose.yml', 'services: {}\n') + with patch.object(lint.shutil, 'which', return_value=None): + self.assertNotEqual(lint.run(self.ctx, SimpleNamespace(hook=True)), 0)