diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml index 4943b7e5..fc260401 100644 --- a/.github/workflows/run.yml +++ b/.github/workflows/run.yml @@ -38,6 +38,8 @@ jobs: - name: Run example working-directory: ./example + env: + CI: 'false' run: | dfetch update dfetch update diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 47e3376c..bb32eb6e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +Release 0.11.0 (unreleased) +==================================== + +* Don't show animation when running in CI (#702) + Release 0.10.0 (released 2025-03-12) ==================================== diff --git a/dfetch/project/vcs.py b/dfetch/project/vcs.py index 73c946ce..7c2b0da6 100644 --- a/dfetch/project/vcs.py +++ b/dfetch/project/vcs.py @@ -35,6 +35,14 @@ def __init__(self, project: dfetch.manifest.project.ProjectEntry) -> None: self.__project = project self.__metadata = Metadata.from_project_entry(self.__project) + self._show_animations = not self._running_in_ci() + + @staticmethod + def _running_in_ci() -> bool: + """Are we running in CI.""" + ci_env_var = os.getenv("CI", "") + return bool(ci_env_var) and ci_env_var[0].lower() in ("t", "1", "y") + def check_wanted_with_local(self) -> Tuple[Optional[Version], Optional[Version]]: """Given the project entry in the manifest, get the relevant version from disk. @@ -109,6 +117,7 @@ def update(self, force: bool = False) -> None: text=f"Fetching {self.__project.name} {to_fetch}", spinner="dots", text_color="green", + enabled=self._show_animations, ): actually_fetched = self._fetch_impl(to_fetch) self._log_project(f"Fetched {actually_fetched}") @@ -148,6 +157,7 @@ def check_for_update(self, reporters: Sequence[AbstractCheckReporter]) -> None: text=f"Checking {self.__project.name}", spinner="dots", text_color="green", + enabled=self._show_animations, ): latest_version = self._check_for_newer_version() diff --git a/tests/test_vcs.py b/tests/test_vcs.py index 6a3b9cfe..bd138f0c 100644 --- a/tests/test_vcs.py +++ b/tests/test_vcs.py @@ -3,7 +3,8 @@ # mypy: ignore-errors # flake8: noqa -from unittest.mock import MagicMock, Mock, patch +from typing import Optional +from unittest.mock import patch import pytest @@ -95,7 +96,11 @@ def get_default_branch(self): ], ) def test_check_wanted_with_local( - name, given_on_disk, given_wanted, expect_wanted, expect_have + name: str, + given_on_disk: Version | None, + given_wanted: Version, + expect_wanted: Version, + expect_have: Version | None, ): with patch("dfetch.project.vcs.os.path.exists") as mocked_path_exists: with patch("dfetch.project.vcs.Metadata.from_file") as mocked_metadata: @@ -120,7 +125,9 @@ def test_check_wanted_with_local( ("same-hash", "1234", "1234", False), ], ) -def test_are_there_local_changes(name, hash_in_metadata, current_hash, expectation): +def test_are_there_local_changes( + name: str, hash_in_metadata: str, current_hash: str, expectation: bool +): with patch("dfetch.project.vcs.hash_directory") as mocked_hash_directory: with patch("dfetch.project.vcs.VCS._on_disk_hash") as mocked_on_disk_hash: vcs = ConcreteVCS(ProjectEntry({"name": "proj1"})) @@ -129,3 +136,28 @@ def test_are_there_local_changes(name, hash_in_metadata, current_hash, expectati mocked_hash_directory.return_value = current_hash assert expectation == vcs._are_there_local_changes() + + +@pytest.mark.parametrize( + "ci_env_value, expected_result", + [ + ("true", True), + ("1", True), + ("True", True), + ("yes", True), + ("YES", True), + ("false", False), + (None, False), + (0, False), + ("other", False), + ], +) +def test_ci_enabled( + monkeypatch: pytest.MonkeyPatch, ci_env_value: Optional[str], expected_result: bool +): + if ci_env_value is None: + monkeypatch.delenv("CI", raising=False) + else: + monkeypatch.setenv("CI", ci_env_value) + + assert ConcreteVCS._running_in_ci() == expected_result