Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
env:
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 890
PYTEST_REQPASS: 891
steps:
- uses: actions/checkout@v4
with:
Expand Down
17 changes: 9 additions & 8 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def get_version_warning() -> str:
with open(cache_file, encoding="utf-8") as f:
data = json.load(f)

if refresh or not data:
if not options.offline and (refresh or not data):
release_url = (
"https://api.github.com/repos/ansible/ansible-lint/releases/latest"
)
Expand All @@ -339,13 +339,14 @@ def get_version_warning() -> str:
)
return ""

html_url = data["html_url"]
new_version = Version(data["tag_name"][1:]) # removing v prefix from tag
if data:
html_url = data["html_url"]
new_version = Version(data["tag_name"][1:]) # removing v prefix from tag

if current_version > new_version:
msg = "[dim]You are using a pre-release version of ansible-lint.[/]"
elif current_version < new_version:
msg = f"""[warning]A new release of ansible-lint is available: [red]{current_version}[/] → [green][link={html_url}]{new_version}[/][/][/]"""
msg += f" Upgrade by running: [info]{pip}[/]"
if current_version > new_version:
msg = "[dim]You are using a pre-release version of ansible-lint.[/]"
elif current_version < new_version:
msg = f"""[warning]A new release of ansible-lint is available: [red]{current_version}[/] → [green][link={html_url}]{new_version}[/][/][/]"""
msg += f" Upgrade by running: [info]{pip}[/]"

return msg
12 changes: 11 additions & 1 deletion test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import shutil
import subprocess
import sys
import tempfile
import time
from http.client import RemoteDisconnected
from pathlib import Path

import pytest
from pytest_mock import MockerFixture

from ansiblelint.config import get_version_warning
from ansiblelint.config import get_version_warning, options
from ansiblelint.constants import RC


Expand Down Expand Up @@ -102,6 +103,15 @@ def test_get_version_warning_remote_disconnect(mocker: MockerFixture) -> None:
pytest.fail("Failed to handle a remote disconnect")


def test_get_version_warning_offline(mocker: MockerFixture) -> None:
"""Test that offline mode does not display any message."""
with tempfile.TemporaryDirectory() as temporary_directory:
# ensures a real cache_file is not loaded
mocker.patch("ansiblelint.config.CACHE_DIR", Path(temporary_directory))
options.offline = True
assert get_version_warning() == ""


@pytest.mark.parametrize(
("lintable"),
(
Expand Down