Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions docker/tag_latest_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ git_show_ref () {
get_latest_tag_list () {
if [[ "$TEST_ENV" == "true" ]]
then
echo "(tag: 2.1.0, apache/2.1test)"
echo "${TEST_LATEST_TAG_LIST:-(tag: 2.1.0, apache/2.1test)}"
else
result=$(git show-ref --tags --dereference latest | awk '{print $2}' | xargs git show --pretty=tformat:%d -s | grep tag:)
echo "${result}"
Expand Down Expand Up @@ -140,7 +140,7 @@ TAGS=($(split_string "$LATEST_TAGS" " "))
compare_result=""

# Iterate through the tags of the latest release
for tag in $TAGS
for tag in "${TAGS[@]}"
do
if [[ $tag == "latest" ]]; then
continue
Expand Down
4 changes: 2 additions & 2 deletions scripts/tag_latest_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ git_show_ref () {
get_latest_tag_list () {
if [[ "$TEST_ENV" == "true" ]]
then
echo "(tag: 2.1.0, apache/2.1test)"
echo "${TEST_LATEST_TAG_LIST:-(tag: 2.1.0, apache/2.1test)}"
else
result=$(git show-ref --tags --dereference latest | awk '{print $2}' | xargs git show --pretty=tformat:%d -s | grep tag:)
echo "${result}"
Expand Down Expand Up @@ -140,7 +140,7 @@ TAGS=($(split_string "$LATEST_TAGS" " "))
compare_result=""

# Iterate through the tags of the latest release
for tag in $TAGS
for tag in "${TAGS[@]}"
Comment thread
Dhairya-007 marked this conversation as resolved.
Resolved
do
if [[ $tag == "latest" ]]; then
continue
Expand Down
9 changes: 7 additions & 2 deletions tests/unit_tests/fixtures/bash_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@

class BashMock:
@staticmethod
def tag_latest_release(tag):
def tag_latest_release(tag, latest_tag_list=None):
bash_command = f"./scripts/tag_latest_release.sh {tag} --dry-run"
env = {"TEST_ENV": "true"}
if latest_tag_list is not None:
# Overrides the mocked `git show --pretty=%d` decoration that the
# script reads for the commit currently tagged `latest`.
env["TEST_LATEST_TAG_LIST"] = latest_tag_list
result = subprocess.run( # noqa: S602
bash_command,
shell=True,
capture_output=True,
text=True,
env={"TEST_ENV": "true"},
env=env,
)
return result
21 changes: 21 additions & 0 deletions tests/unit_tests/scripts/tag_latest_release_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,24 @@ def test_tag_latest_release(tag, expected_output):
)

assert expected_output in result.stdout


@pytest.mark.parametrize(
"tag, expected_output",
[
("2.1.1", "This release tag 2.1.1 is newer than the latest."),
("1.0.0", "This release tag 1.0.0 is older than the latest."),
("2.1.0", "Versions are equal"),
],
)
def test_tag_latest_release_reads_every_decoration(tag, expected_output):
"""
`git show --pretty=%d` decorates a commit with branches as well as tags, so
the version tag is not necessarily the first entry in the list. Every entry
has to be considered, not just the first one.
"""
result = BashMock.tag_latest_release(
tag, latest_tag_list="(HEAD -> master, tag: 2.1.0, tag: latest)"
)

assert expected_output in result.stdout
Comment thread
Dhairya-007 marked this conversation as resolved.
Resolved