-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pz2
committed
May 26, 2024
1 parent
956ed05
commit e57b24e
Showing
8 changed files
with
193 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
PyYAML~=6.0.1 | ||
GitPython~=3.1.40 | ||
python-gitlab~=4.2.0 | ||
requests~=2.31.0 | ||
python-gitlab~=4.5.0 | ||
requests~=2.32.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from valhalla.version.release_command import get_version_to_release_from_command | ||
from valhalla.version.version_to_release import ReleaseKind | ||
|
||
|
||
class ReleaseCommandTest(unittest.TestCase): | ||
|
||
@patch('os.environ.get') | ||
def test_release_command(self, mock_env_get): | ||
# given: | ||
mock_env_get.return_value = 'release-1.0.0' | ||
release_kinds = [ReleaseKind("valhalla.yml", "", ".")] | ||
|
||
# when: | ||
result = get_version_to_release_from_command(release_kinds) | ||
|
||
# then: | ||
self.assertEqual(result.version_number_to_release, '1.0.0') | ||
self.assertEqual(result.release_kind.filename, "valhalla.yml") | ||
self.assertEqual(result.get_config_file_path(), "./valhalla.yml") | ||
|
||
@patch('os.environ.get') | ||
@patch('valhalla.version.release_command.exit') | ||
def test_wrong_release_command(self, mock_exit, mock_env_get): | ||
# given: | ||
mock_env_get.return_value = 'some-value' | ||
release_kinds = [ReleaseKind("valhalla.yml", "", ".")] | ||
|
||
# when: | ||
result = get_version_to_release_from_command(release_kinds) | ||
|
||
# then: | ||
self.assertIsNone(result) | ||
mock_exit.assert_called_with(-1) | ||
|
||
@patch('os.environ.get') | ||
def test_no_release_command(self, mock_env_get): | ||
# given: | ||
mock_env_get.return_value = None | ||
release_kinds = [ReleaseKind("valhalla.yml", "", ".")] | ||
|
||
# when: | ||
result = get_version_to_release_from_command(release_kinds) | ||
|
||
# then: | ||
self.assertIsNone(result) | ||
|
||
@patch('os.environ.get') | ||
def test_release_hotfix_command(self, mock_env_get): | ||
# given: | ||
mock_env_get.return_value = 'release-hotfix-1.2.3' | ||
release_kinds = [ReleaseKind("valhalla.yml", "", "."), | ||
ReleaseKind("valhalla-hotfix.yml", "-hotfix", ".")] | ||
|
||
# when: | ||
result = get_version_to_release_from_command(release_kinds) | ||
|
||
# then: | ||
self.assertEqual(result.version_number_to_release, '1.2.3') | ||
self.assertEqual(result.release_kind.filename, "valhalla-hotfix.yml") | ||
self.assertEqual(result.get_config_file_path(), "./valhalla-hotfix.yml") | ||
|
||
@patch('os.environ.get') | ||
@patch('valhalla.version.version_to_release.exit') | ||
def test_no_matching_valhalla_command(self, mock_exit, mock_env_get): | ||
# given: | ||
mock_env_get.return_value = 'release-1.2.3' | ||
release_kinds = [ReleaseKind("valhalla-hotfix.yml", "-hotfix", ".")] | ||
|
||
# when: | ||
result = get_version_to_release_from_command(release_kinds) | ||
|
||
# then: | ||
self.assertIsNone(result) | ||
mock_exit.assert_called_with(-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
from typing import List | ||
|
||
from valhalla.common.logger import info, error | ||
from valhalla.version.version_to_release import ReleaseKind, VersionToRelease, BASE_PREFIX, \ | ||
get_version_to_release_from_str | ||
|
||
|
||
def get_version_to_release_from_command(release_kinds: List[ReleaseKind]) -> VersionToRelease | None: | ||
command = os.environ.get('VALHALLA_RELEASE_CMD') | ||
|
||
if command: | ||
info(f'Value of VALHALLA_RELEASE_CMD is: {command}') | ||
|
||
if command.startswith(BASE_PREFIX): | ||
return get_version_to_release_from_str(command, release_kinds) | ||
else: | ||
error( | ||
'This is not a correct release command! VALHALLA_RELEASE_CMD should start from release- prefix, f.e. release-1.2.3') | ||
exit(-1) | ||
else: | ||
info("Cloud not find VALHALLA_RELEASE_CMD environment variable, skipping and going to check branch name") | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters