Skip to content

Commit c8886b7

Browse files
authored
Merge pull request #481 from redis/fix_git_ls_remote_8.4
Release automation fixes from downstream branches
2 parents 6c5502d + 08ae191 commit c8886b7

File tree

5 files changed

+73
-7
lines changed

5 files changed

+73
-7
lines changed

.github/workflows/pre-merge.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ on:
1111
description: 'Release tag to build'
1212
required: true
1313
type: string
14+
publish_image:
15+
description: 'Publish Docker image to GHCR'
16+
required: false
17+
type: boolean
18+
default: false
1419
outputs:
1520
docker_image_urls:
1621
description: 'Array of Docker image URLs that were published'
@@ -60,7 +65,7 @@ jobs:
6065
platform: ${{ matrix.platform }}
6166
registry_username: ${{ github.actor }}
6267
registry_password: ${{ secrets.GITHUB_TOKEN }}
63-
publish_image: ${{ vars.PUBLISH_IMAGE }}
68+
publish_image: ${{ inputs.publish_image || vars.PUBLISH_IMAGE }}
6469
registry_repository: ${{ format('ghcr.io/{0}', github.repository) }}
6570
release_tag: ${{ inputs.release_tag }}
6671

.github/workflows/release_build_and_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
secrets: inherit
5858
with:
5959
release_tag: ${{ github.event.inputs.release_tag }}
60+
publish_image: true
6061

6162
merge-back-to-release-branch:
6263
needs: [prepare-release, build-and-test]

.github/workflows/release_publish.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
workflow_uuid:
1212
description: 'Optional UUID to identify this workflow run'
1313
required: false
14+
pr_to_official_library:
15+
default: false
1416

1517
env:
1618
TARGET_OFFICIAL_IMAGES_REPO: docker-library/official-images
@@ -76,7 +78,7 @@ jobs:
7678
uses: actions/checkout@v4
7779
with:
7880
path: official-images
79-
repository: ${{ env.TARGET_OFFICIAL_IMAGES_REPO }}
81+
repository: ${{ github.event.inputs.pr_to_official_library == 'true' && env.TARGET_OFFICIAL_IMAGES_REPO || env.FORKED_OFFICIAL_IMAGES_REPO }}
8082

8183
- name: Generate stackbrew library content
8284
env:
@@ -102,7 +104,7 @@ jobs:
102104
with:
103105
token: ${{ secrets.GH_TOKEN_FOR_PR }}
104106
draft: true
105-
push-to-fork: ${{ env.FORKED_OFFICIAL_IMAGES_REPO }}
107+
push-to-fork: ${{ github.event.inputs.pr_to_official_library == 'true' && env.FORKED_OFFICIAL_IMAGES_REPO || '' }}
106108
path: official-images
107109
branch: redis-${{ steps.parse-release.outputs.release_version }}
108110
commit-message: "Redis: Update to ${{ steps.parse-release.outputs.release_version }}"
@@ -158,4 +160,4 @@ jobs:
158160
. ${GITHUB_WORKSPACE}/.github/actions/common/func.sh
159161
160162
slack_format_failure_message "Docker PR failed for Redis: ${{ steps.parse-release.outputs.release_version || 'unknown'}}" "$workflow_url" "$footer" \
161-
| curl -s --fail-with-body -d@- "${{ secrets.SLACK_WEB_HOOK_URL }}"
163+
| curl -s --fail-with-body -d@- "${{ secrets.SLACK_WEB_HOOK_URL }}"

release-automation/src/stackbrew_generator/git_operations.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def list_remote_tags(self, major_version: int) -> List[Tuple[str, str]]:
6767
console.print(f"[dim]Listing remote tags for v{major_version}.*[/dim]")
6868

6969
cmd = [
70-
"git", "ls-remote", "--refs", "--tags",
70+
"git", "ls-remote", "--tags",
7171
self.remote, f"refs/tags/v{major_version}.*"
7272
]
7373

@@ -76,11 +76,28 @@ def list_remote_tags(self, major_version: int) -> List[Tuple[str, str]]:
7676
if not result.stdout.strip():
7777
raise GitOperationError(f"No tags found for major version {major_version}")
7878

79-
tags = []
79+
tag_commits = {}
80+
81+
# always use peeled commits for annotated tags
82+
# for annotated tags git ls-remote prints tag object hash, then actual commit hash with ^{} suffix
83+
# https://stackoverflow.com/a/25996877
8084
for line in result.stdout.strip().split('\n'):
8185
if line:
8286
commit, ref = line.split('\t', 1)
83-
tags.append((commit, ref))
87+
if ref.endswith('^{}'):
88+
# This is a peeled ref - extract the tag name
89+
# always rewrite tag commits with peeled ref commits
90+
tag_name = ref[:-3] # Remove '^{}'
91+
tag_commits[tag_name] = commit
92+
else:
93+
# This is a regular tag
94+
# rewrite only if not yet exists
95+
if ref not in tag_commits:
96+
tag_commits[ref] = commit
97+
98+
tags = []
99+
for tag_ref, commit in tag_commits.items():
100+
tags.append((commit, tag_ref))
84101

85102
console.print(f"[dim]Found {len(tags)} tags[/dim]")
86103
return tags
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Tests for git operations."""
2+
3+
from unittest.mock import Mock, patch
4+
5+
from stackbrew_generator.git_operations import GitClient
6+
7+
8+
class TestGitClient:
9+
"""Tests for GitClient class."""
10+
11+
@patch('stackbrew_generator.git_operations.console')
12+
@patch.object(GitClient, '_run_command')
13+
def test_list_remote_tags(self, mock_run_command, mock_console):
14+
"""
15+
Test that list_remote_tags returns the expected format for peeled refs.
16+
17+
For tags with ^{} suffix, use the commit hash from that line.
18+
For tags without ^{} suffix, use the commit hash from the tag line.
19+
"""
20+
mock_result = Mock()
21+
mock_result.stdout = """101262a8cf05b98137d88bc17e77db90c24cc783\trefs/tags/v8.0.3
22+
2277e5ead99f0caacbd90e0d04693adb27ebfaa6\trefs/tags/v8.0.4^{}
23+
c0125f5be8786d556a9d3edd70f51974fe045c1a\trefs/tags/v8.0.4
24+
f76d8a1cc979be6202aed93efddd2a0ebbfa0209\trefs/tags/v8.2.2
25+
c5846c13383c8b284897ff171e0c946868ed4c8c\trefs/tags/v8.2.2^{}"""
26+
mock_run_command.return_value = mock_result
27+
28+
client = GitClient()
29+
result = client.list_remote_tags(8)
30+
31+
# Expected behavior:
32+
# - v8.0.3 has no peeled ref, so use the tag commit
33+
# - v8.0.4 has a peeled ref, so use the peeled commit (2277e5ead99f0caacbd90e0d04693adb27ebfaa6)
34+
# - v8.2.2 has a peeled ref, so use the peeled commit (c5846c13383c8b284897ff171e0c946868ed4c8c)
35+
expected_result = [
36+
("101262a8cf05b98137d88bc17e77db90c24cc783", "refs/tags/v8.0.3"), # No peeled ref
37+
("2277e5ead99f0caacbd90e0d04693adb27ebfaa6", "refs/tags/v8.0.4"), # Use peeled ref
38+
("c5846c13383c8b284897ff171e0c946868ed4c8c", "refs/tags/v8.2.2") # Use peeled ref
39+
]
40+
41+
assert result == expected_result

0 commit comments

Comments
 (0)