Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BL-143 | Version warning #299

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
13 changes: 11 additions & 2 deletions leverage/leverage.py
Original file line number Diff line number Diff line change
@@ -2,11 +2,12 @@
Binbash Leverage Command-line tool.
"""

from packaging.version import Version

import click

from leverage import __version__
from leverage import __version__, conf
from leverage._internals import pass_state

from leverage.modules.aws import aws
from leverage.modules.credentials import credentials
from leverage.modules import run, project, terraform, tfautomv, kubectl, shell
@@ -25,6 +26,14 @@ def leverage(context, state, verbose):
# leverage called with no subcommand
click.echo(context.get_help())

# if there is a version restriction set, make sure we satisfy it
config = conf.load()
minimum_version = config.get("LEVERAGE_CLI_VERSION")
if minimum_version and Version(__version__) < Version(minimum_version):
click.echo(
f"\033[91mWARNING\033[0m\tYour current version ({__version__}) is lower than the required minimum ({minimum_version})."
)


# Add modules to leverage
leverage.add_command(run)
17 changes: 16 additions & 1 deletion tests/test_conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from unittest import mock

import pytest
from click.testing import CliRunner

from leverage import leverage
from leverage.conf import load


ROOT_ENV_FILE = """
# Project settings
PROJECT=foobar
@@ -52,3 +55,15 @@ def test_load_config(monkeypatch, click_context, tmp_path, write_files, expected
loaded_values = load()

assert dict(loaded_values) == expected_values


def test_version_validation():
"""
Test that we get a warning if we are working with a version lower than the required by the project.
"""
runner = CliRunner()
with mock.patch("leverage.conf.load", return_value={"LEVERAGE_CLI_VERSION": "99.9.9"}):
result = runner.invoke(leverage)

assert "is lower than the required minimum (99.9.9)" in result.output
assert result.exit_code == 0