Skip to content

Commit c01623a

Browse files
updating version of helm
1 parent af92ce5 commit c01623a

File tree

3 files changed

+309
-1
lines changed

3 files changed

+309
-1
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Prepare Operator Release
2+
3+
permissions:
4+
contents: write
5+
pull-requests: write
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
operator_version:
11+
description: 'Operator version (e.g., 2.1.1-0-rc.0 for RC, 2.1.1-0 for final)'
12+
required: true
13+
type: string
14+
15+
defaults:
16+
run:
17+
shell: bash
18+
19+
jobs:
20+
prepare-release:
21+
runs-on: ubuntu-22.04
22+
23+
outputs:
24+
pr_number: ${{ steps.create_pr.outputs.result }}
25+
release_type: ${{ steps.update.outputs.release_type }}
26+
27+
steps:
28+
- name: Checkout Repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Setup Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.11'
37+
38+
- name: Install Dependencies
39+
run: pip install pyyaml
40+
41+
- name: Create Release Branch
42+
id: branch
43+
run: |
44+
VERSION="${{ inputs.operator_version }}"
45+
46+
if [[ "${VERSION}" =~ [-\.]rc[\.\-][0-9]+$ ]]; then
47+
BASE_VERSION=$(echo "${VERSION}" | sed -E 's/[-\.]rc\.[0-9]+$//')
48+
BRANCH="prepare-release-v${BASE_VERSION}"
49+
else
50+
BRANCH="prepare-release-v${VERSION}"
51+
fi
52+
53+
git config user.name "github-actions[bot]"
54+
git config user.email "github-actions[bot]@users.noreply.github.com"
55+
56+
if git ls-remote --heads origin "${BRANCH}" | grep -q "${BRANCH}"; then
57+
git fetch origin "${BRANCH}"
58+
git checkout "${BRANCH}"
59+
git pull origin "${BRANCH}"
60+
else
61+
git checkout -b "${BRANCH}"
62+
fi
63+
64+
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
65+
66+
- name: Update Version in Files
67+
id: update
68+
run: |
69+
python3 scripts/update_operator_version.py \
70+
--operator-version "${{ inputs.operator_version }}" \
71+
--operator-repo-dir ./
72+
73+
- name: Commit and Push
74+
run: |
75+
VERSION="${{ inputs.operator_version }}"
76+
RELEASE_TYPE="${{ steps.update.outputs.release_type }}"
77+
78+
git add bundle/manifests/operator.clusterserviceversion.yaml
79+
git add Makefile
80+
git add bundle.yaml
81+
git add config/manager/kustomization.yaml
82+
git add tests/deploy_helm_operator.sh
83+
84+
if ! git diff --cached --quiet; then
85+
[ "${RELEASE_TYPE}" = "rc" ] && MSG="chore: prepare release ${VERSION} (RC)" || MSG="chore: prepare release ${VERSION}"
86+
git commit -m "${MSG}"
87+
git push -u origin "${{ steps.branch.outputs.branch }}"
88+
fi
89+
90+
- name: Create Pull Request
91+
id: create_pr
92+
uses: actions/github-script@v7
93+
with:
94+
script: |
95+
const version = '${{ inputs.operator_version }}';
96+
const releaseType = '${{ steps.update.outputs.release_type }}';
97+
const previousVersion = '${{ steps.update.outputs.previous_version }}';
98+
const isRC = releaseType === 'rc';
99+
100+
const { data: pr } = await github.rest.pulls.create({
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
title: `chore: prepare release ${version}${isRC ? ' (RC)' : ''}`,
104+
head: '${{ steps.branch.outputs.branch }}',
105+
base: 'main',
106+
body: `## Prepare Operator Release ${version}
107+
108+
**Type:** ${isRC ? 'Release Candidate' : 'Final Release'}
109+
**Replaces:** v${previousVersion}
110+
111+
### Changes
112+
- Updated operator version to ${version}
113+
- Updated image references to Red Hat registry
114+
- Updated kustomization
115+
116+
### Next Steps
117+
1. Review and merge this PR
118+
2. Run Phase 5 to build and certify
119+
120+
---`
121+
});
122+
return pr.number;
123+
124+
- name: Output Summary
125+
run: |
126+
echo "## ✅ Complete" >> $GITHUB_STEP_SUMMARY
127+
echo "" >> $GITHUB_STEP_SUMMARY
128+
echo "**PR:** [#${{ steps.create_pr.outputs.result }}](https://github.com/${{ github.repository }}/pull/${{ steps.create_pr.outputs.result }})" >> $GITHUB_STEP_SUMMARY
129+
echo "**Version:** ${{ inputs.operator_version }}" >> $GITHUB_STEP_SUMMARY
130+
echo "**Type:** ${{ steps.update.outputs.release_type }}" >> $GITHUB_STEP_SUMMARY

.github/workflows/update_operator_images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Phase 3 - Update Operator with SHA256 Digests
1+
name: Update Operator with SHA256 Digests
22

33
permissions:
44
contents: write

scripts/update_operator_version.py

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/usr/bin/env python3
2+
"""Updates operator version in all necessary files for a new release."""
3+
4+
import argparse
5+
import re
6+
import sys
7+
from datetime import datetime
8+
from pathlib import Path
9+
10+
import yaml
11+
12+
13+
def detect_release_type(version):
14+
"""Detect if version is RC or final."""
15+
return 'rc' if re.search(r'[-\.]rc[\.\-]\d+$', version) else 'final'
16+
17+
18+
def get_previous_version_from_csv(csv_file):
19+
"""Get current version from CSV file."""
20+
try:
21+
with open(csv_file, 'r') as f:
22+
csv_data = yaml.safe_load(f)
23+
current_version = csv_data.get('spec', {}).get('version', '')
24+
if current_version:
25+
return current_version
26+
except Exception as e:
27+
print(f"Error reading CSV: {e}")
28+
sys.exit(1)
29+
30+
print("Cannot find version in CSV file")
31+
sys.exit(1)
32+
33+
34+
def validate_version_format(version, release_type):
35+
"""Validate version format."""
36+
if release_type == 'rc':
37+
if not re.match(r'^\d+\.\d+\.\d+-\d+[-\.]rc\.\d+$', version):
38+
print(f"RC version must match format: X.Y.Z-N-rc.M (got: {version})")
39+
sys.exit(1)
40+
else:
41+
if not re.match(r'^\d+\.\d+\.\d+-\d+$', version):
42+
print(f"Final version must match format: X.Y.Z-N (got: {version})")
43+
sys.exit(1)
44+
if 'rc' in version.lower():
45+
print("Final version should not contain 'rc'")
46+
sys.exit(1)
47+
48+
49+
def update_csv(csv_file, version, previous_version, operator_name):
50+
"""Update ClusterServiceVersion file."""
51+
with open(csv_file, 'r') as f:
52+
csv_data = yaml.safe_load(f)
53+
54+
csv_data['spec']['version'] = version
55+
csv_data['metadata']['name'] = f"{operator_name}.v{version}"
56+
csv_data['metadata']['annotations']['createdAt'] = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
57+
58+
operator_image = f"registry.connect.redhat.com/sumologic/{operator_name}:{version}"
59+
csv_data['metadata']['annotations']['containerImage'] = operator_image
60+
61+
for deployment in csv_data['spec']['install']['spec']['deployments']:
62+
if deployment['name'] == operator_name:
63+
for container in deployment['spec']['template']['spec']['containers']:
64+
if container['name'] == 'manager':
65+
container['image'] = operator_image
66+
67+
if 'relatedImages' in csv_data['spec']:
68+
for img in csv_data['spec']['relatedImages']:
69+
if img.get('name') == operator_name:
70+
img['image'] = operator_image
71+
break
72+
73+
with open(csv_file, 'w') as f:
74+
yaml.dump(csv_data, f, default_flow_style=False, sort_keys=False)
75+
76+
77+
def update_makefile(makefile_path, version, operator_name):
78+
"""Update IMG in Makefile."""
79+
if not Path(makefile_path).exists():
80+
return
81+
82+
with open(makefile_path, 'r') as f:
83+
content = f.read()
84+
85+
img_value = f"registry.connect.redhat.com/sumologic/{operator_name}:{version}"
86+
content = re.sub(r'^IMG\s*\?=\s*.*$', f'IMG ?= {img_value}', content, flags=re.MULTILINE)
87+
88+
with open(makefile_path, 'w') as f:
89+
f.write(content)
90+
91+
92+
def update_kustomization(kustomize_file, version):
93+
"""Update config/manager/kustomization.yaml."""
94+
if not Path(kustomize_file).exists():
95+
return
96+
97+
with open(kustomize_file, 'r') as f:
98+
kustomize_data = yaml.safe_load(f)
99+
100+
if 'images' in kustomize_data:
101+
for image in kustomize_data['images']:
102+
if image.get('name') == 'controller':
103+
image['newTag'] = version
104+
break
105+
106+
with open(kustomize_file, 'w') as f:
107+
yaml.dump(kustomize_data, f, default_flow_style=False, sort_keys=False)
108+
109+
110+
def update_deploy_test_script(script_file, version, operator_name):
111+
"""Update tests/deploy_helm_operator.sh."""
112+
if not Path(script_file).exists():
113+
return
114+
115+
with open(script_file, 'r') as f:
116+
content = f.read()
117+
118+
new_image = f"registry.connect.redhat.com/sumologic/{operator_name}:{version}"
119+
pattern = r'registry\.connect\.redhat\.com/sumologic/' + re.escape(operator_name) + r':[\d\.]+-[\d\.]+(?:[-\.]rc\.[\d]+)?'
120+
121+
content = re.sub(
122+
r'readonly IMG="\$\{IMG:=' + pattern + r'\}"',
123+
f'readonly IMG="${{IMG:={new_image}}}"',
124+
content
125+
)
126+
127+
content = re.sub(
128+
r'sed -i\.bak "s#' + pattern + r'#',
129+
f'sed -i.bak "s#{new_image}#',
130+
content
131+
)
132+
133+
with open(script_file, 'w') as f:
134+
f.write(content)
135+
136+
def update_bundle_yaml(bundle_file, version, operator_name):
137+
"""Update bundle.yaml file."""
138+
if not Path(bundle_file).exists():
139+
return
140+
141+
with open(bundle_file, 'r') as f:
142+
content = f.read()
143+
144+
pattern = r'(image:\s+registry\.connect\.redhat\.com/sumologic/' + re.escape(operator_name) + r'):[\d\.]+-[\d\.]+(?:[-\.]rc\.[\d]+)?'
145+
content = re.sub(pattern, f'\\1:{version}', content)
146+
147+
with open(bundle_file, 'w') as f:
148+
f.write(content)
149+
150+
def main():
151+
parser = argparse.ArgumentParser(description='Update operator version')
152+
parser.add_argument('--operator-version', required=True, help='Operator version')
153+
parser.add_argument('--operator-repo-dir', default='./', help='Repository directory')
154+
155+
args = parser.parse_args()
156+
157+
version = args.operator_version
158+
repo_dir = Path(args.operator_repo_dir)
159+
160+
operator_name = "sumologic-kubernetes-collection-helm-operator"
161+
csv_file = repo_dir / "bundle/manifests/operator.clusterserviceversion.yaml"
162+
163+
release_type = detect_release_type(version)
164+
validate_version_format(version, release_type)
165+
previous_version = get_previous_version_from_csv(csv_file)
166+
167+
update_csv(csv_file, version, previous_version, operator_name)
168+
update_makefile(repo_dir / "Makefile", version, operator_name)
169+
update_bundle_yaml(repo_dir / "bundle.yaml", version, operator_name)
170+
update_kustomization(repo_dir / "config/manager/kustomization.yaml", version)
171+
update_deploy_test_script(repo_dir / "tests/deploy_helm_operator.sh", version, operator_name)
172+
173+
print(f"::set-output name=release_type::{release_type}")
174+
print(f"::set-output name=previous_version::{previous_version}")
175+
176+
177+
if __name__ == '__main__':
178+
main()

0 commit comments

Comments
 (0)