Skip to content

Commit

Permalink
fix(tag_modules): Push tags by batch of 3 (#32983)
Browse files Browse the repository at this point in the history
  • Loading branch information
chouetz authored Jan 15, 2025
1 parent c6d82ad commit 471c162
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
]

BACKPORT_LABEL_COLOR = "5319e7"
TAG_BATCH_SIZE = 3


@task
Expand Down Expand Up @@ -200,7 +201,9 @@ def tag_modules(

if push:
tags_list = ' '.join(tags)
ctx.run(f"git push origin {tags_list}{force_option}")
for idx in range(0, len(tags), TAG_BATCH_SIZE):
batch_tags = tags[idx : idx + TAG_BATCH_SIZE]
ctx.run(f"git push origin {' '.join(batch_tags)}{force_option}")
print(f"Pushed tag {tags_list}")
print(f"Created module tags for version {agent_version}")

Expand Down
53 changes: 53 additions & 0 deletions tasks/unit_tests/release_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,3 +1240,56 @@ def test_update_module_optional_in_agent_7(self):
edit_optional = re.compile(r"pkg/util/optional.*test/new-e2e")
self.assertTrue(any(edit_optional.search(call[0][0]) for call in c.run.call_args_list))
self.assertEqual(c.run.call_count, 2)


class TestTagModules(unittest.TestCase):
@patch('tasks.release.__tag_single_module', new=MagicMock(side_effect=[[str(i)] for i in range(2)]))
@patch('tasks.release.agent_context', new=MagicMock())
def test_2_tags(self):
c = MockContext(run=Result("yolo"))
with patch('tasks.release.get_default_modules') as mock_modules:
mock_dict = MagicMock()
mock_dict.values.return_value = 2 * [GoModule('pkg/one')]
mock_modules.return_value = mock_dict
release.tag_modules(c, version="version")
self.assertEqual(c.run.call_count, 1)
c.run.assert_called_with("git push origin 0 1")

@patch('tasks.release.__tag_single_module', new=MagicMock(side_effect=[[str(i)] for i in range(3)]))
@patch('tasks.release.agent_context', new=MagicMock())
def test_3_tags(self):
c = MockContext(run=Result("yolo"))
with patch('tasks.release.get_default_modules') as mock_modules:
mock_dict = MagicMock()
mock_dict.values.return_value = 3 * [GoModule('pkg/one')]
mock_modules.return_value = mock_dict
release.tag_modules(c, version="version")
self.assertEqual(c.run.call_count, 1)
c.run.assert_called_with("git push origin 0 1 2")

@patch('tasks.release.__tag_single_module', new=MagicMock(side_effect=[[str(i)] for i in range(4)]))
@patch('tasks.release.agent_context', new=MagicMock())
def test_4_tags(self):
c = MockContext(run=Result("yolo"))
with patch('tasks.release.get_default_modules') as mock_modules:
mock_dict = MagicMock()
mock_dict.values.return_value = 4 * [GoModule('pkg/one')]
mock_modules.return_value = mock_dict
release.tag_modules(c, version="version")
self.assertEqual(c.run.call_count, 2)
calls = [
call("git push origin 0 1 2"),
call("git push origin 3"),
]
c.run.assert_has_calls(calls)

@patch('tasks.release.__tag_single_module', new=MagicMock(side_effect=[[str(i)] for i in range(100)]))
@patch('tasks.release.agent_context', new=MagicMock())
def test_100_tags(self):
c = MockContext(run=Result("yolo"))
with patch('tasks.release.get_default_modules') as mock_modules:
mock_dict = MagicMock()
mock_dict.values.return_value = 100 * [GoModule('pkg/one')]
mock_modules.return_value = mock_dict
release.tag_modules(c, version="version")
self.assertEqual(c.run.call_count, 34)

0 comments on commit 471c162

Please sign in to comment.