Skip to content

Commit

Permalink
Adds sorting of the released tags based on semver
Browse files Browse the repository at this point in the history
This is for
#3579

(cherry picked from commit 3b8fb8d)
  • Loading branch information
kushaldas authored and emkll committed Aug 28, 2018
1 parent f461e9f commit 4ab855c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions admin/securedrop_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import prompt_toolkit
from prompt_toolkit.validation import Validator, ValidationError
import yaml
from pkg_resources import parse_version

sdlog = logging.getLogger(__name__)
RELEASE_KEY = '22245C81E3BAEB4138B36061310F561200F4AD77'
Expand Down Expand Up @@ -628,6 +629,9 @@ def check_for_updates(args):
# Do not check out any release candidate tags
all_prod_tags = [x for x in all_tags if 'rc' not in x]

# We want the tags to be sorted based on semver
all_prod_tags.sort(key=parse_version)

latest_tag = all_prod_tags[-1]

if current_tag != latest_tag:
Expand Down
14 changes: 14 additions & 0 deletions admin/tests/test_securedrop-admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ def test_check_for_updates_update_needed(self, tmpdir, caplog):
assert update_status is True
assert tag == '0.6.1'

def test_check_for_updates_higher_version(self, tmpdir, caplog):
git_repo_path = str(tmpdir)
args = argparse.Namespace(root=git_repo_path)
current_tag = "0.6"
tags_available = "0.1\n0.10.0\n0.6.2\n0.6\n0.6-rc1\n0.9.0\n"

with mock.patch('subprocess.check_call'):
with mock.patch('subprocess.check_output',
side_effect=[current_tag, tags_available]):
update_status, tag = securedrop_admin.check_for_updates(args)
assert "Update needed" in caplog.text
assert update_status is True
assert tag == '0.10.0'

def test_check_for_updates_ensure_newline_stripped(self, tmpdir, caplog):
"""Regression test for #3426"""
git_repo_path = str(tmpdir)
Expand Down

0 comments on commit 4ab855c

Please sign in to comment.