Skip to content

Commit 9fafc9e

Browse files
committed
.claude: add pre-branching plugin
1 parent bd7f225 commit 9fafc9e

10 files changed

+716
-0
lines changed

.claude/.claude-plugin/plugin.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"name": "openshift-branching",
3+
"version": "1.0.0",
4+
"description": "Automates OpenShift release pre-branching tasks",
5+
"author": "TestPlatform Team",
6+
"commands": [
7+
{
8+
"name": "pre-branching",
9+
"description": "Execute pre-branching tasks for OpenShift release X.Y",
10+
"usage": "/pre-branching <x.y>",
11+
"settingsFile": "settings.pre-branching.json",
12+
"examples": [
13+
"/pre-branching 4.21",
14+
"/pre-branching 4.22"
15+
]
16+
}
17+
],
18+
"skills": [
19+
{
20+
"name": "create-pre-branching-branch",
21+
"description": "Create and checkout pre-branching branch in release repository",
22+
"script": "skills/create-pre-branching-branch.sh",
23+
"permissions": [
24+
"Bash(git fetch:*)",
25+
"Bash(git pull:*)",
26+
"Bash(git checkout:*)",
27+
"Bash(git show-ref:*)"
28+
]
29+
},
30+
{
31+
"name": "download-sippy-config",
32+
"description": "Download latest Sippy configuration from GitHub",
33+
"script": "skills/download-sippy-config.sh",
34+
"permissions": [
35+
"Bash(curl :*)",
36+
"Write(/tmp/**)"
37+
]
38+
},
39+
{
40+
"name": "copy-release-controller-configs",
41+
"description": "Copy and update release-controller configurations from old version to new version",
42+
"script": "skills/copy-release-controller-configs.sh",
43+
"permissions": [
44+
"Read(../release/**)",
45+
"Edit(../release/**)",
46+
"Bash(cp :*)",
47+
"Bash(sed :*)",
48+
"Bash(find :*)"
49+
]
50+
},
51+
{
52+
"name": "update-release-gating-jobs",
53+
"description": "Run generated-release-gating-jobs bumper with Sippy config",
54+
"script": "skills/update-release-gating-jobs.sh",
55+
"permissions": [
56+
"Bash(go build:*)",
57+
"Bash(./generated-release-gating-jobs :*)",
58+
"Read(../release/**)",
59+
"Edit(../release/**)"
60+
]
61+
},
62+
{
63+
"name": "regenerate-prow-jobs",
64+
"description": "Regenerate Prow job configurations from CI operator configs",
65+
"script": "skills/regenerate-prow-jobs.sh",
66+
"permissions": [
67+
"Bash(make jobs)",
68+
"Read(../release/**)",
69+
"Write(../release/**)"
70+
]
71+
},
72+
{
73+
"name": "validate-release-controller-config",
74+
"description": "Validate release-controller configurations",
75+
"script": "skills/validate-release-controller-config.sh",
76+
"permissions": [
77+
"Bash(hack/validate-release-controller-config.sh :*)",
78+
"Read(../release/**)"
79+
]
80+
},
81+
{
82+
"name": "bump-analysis-jobs",
83+
"description": "Bump analysis jobs (install, upgrade, overall) from old version to new version",
84+
"script": "skills/bump-analysis-jobs.sh",
85+
"permissions": [
86+
"Bash(python3:*)",
87+
"Read(../release/**)",
88+
"Edit(../release/**)"
89+
]
90+
},
91+
{
92+
"name": "create-pre-branching-commits",
93+
"description": "Create the three standard pre-branching commits",
94+
"script": "skills/create-pre-branching-commits.sh",
95+
"permissions": [
96+
"Bash(git add:*)",
97+
"Bash(git commit:*)",
98+
"Bash(git diff:*)",
99+
"Bash(git log:*)",
100+
"Bash(git ls-files:*)"
101+
]
102+
}
103+
],
104+
"config": {
105+
"RELEASE_REPO": "/home/prucek/work/release",
106+
"CI_TOOLS_REPO": "/home/prucek/work/ci-tools"
107+
}
108+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
OLD_VERSION="${1:-}"
5+
NEW_VERSION="${2:-}"
6+
RELEASE_REPO="${3:-}"
7+
8+
if [ -z "$OLD_VERSION" ] || [ -z "$NEW_VERSION" ] || [ -z "$RELEASE_REPO" ]; then
9+
echo "Usage: $0 <old_version> <new_version> <release_repo>"
10+
echo "Example: $0 4.21 4.22 /path/to/release"
11+
exit 1
12+
fi
13+
14+
echo "=========================================="
15+
echo "Bumping Analysis Jobs"
16+
echo "=========================================="
17+
echo ""
18+
echo "Old version: $OLD_VERSION"
19+
echo "New version: $NEW_VERSION"
20+
echo "Release repo: $RELEASE_REPO"
21+
echo ""
22+
23+
cd "$RELEASE_REPO"
24+
25+
# Export variables for Python script
26+
export OLD_VERSION
27+
export NEW_VERSION
28+
29+
# Python script to extract and bump jobs
30+
python3 << 'PYTHON_EOF'
31+
import re
32+
import sys
33+
import os
34+
35+
old_version = os.environ['OLD_VERSION']
36+
new_version = os.environ['NEW_VERSION']
37+
38+
def bump_analysis_job(job_text, old_ver, new_ver):
39+
"""Replace version numbers in a job definition"""
40+
return job_text.replace(old_ver, new_ver)
41+
42+
def extract_jobs(file_path, job_names):
43+
"""Extract complete job definitions for given job names from a YAML file"""
44+
with open(file_path, 'r') as f:
45+
content = f.read()
46+
47+
jobs = []
48+
for job_name in job_names:
49+
# Find the job by name - match from "- " to the next "- " or end of file
50+
pattern = rf'(\n- .*?\n name: {re.escape(job_name)}\n.*?)(?=\n- |\Z)'
51+
match = re.search(pattern, content, re.DOTALL)
52+
if match:
53+
jobs.append(match.group(1))
54+
print(f" ✓ Found job: {job_name}", file=sys.stderr)
55+
else:
56+
print(f" ✗ Could not find job: {job_name}", file=sys.stderr)
57+
58+
return jobs
59+
60+
def append_bumped_jobs(file_path, job_names, old_ver, new_ver):
61+
"""Extract jobs, bump versions, and append to the file"""
62+
print(f"\nProcessing {file_path}...", file=sys.stderr)
63+
jobs = extract_jobs(file_path, job_names)
64+
65+
if not jobs:
66+
print(f" No jobs found in {file_path}", file=sys.stderr)
67+
return False
68+
69+
# Read the current file
70+
with open(file_path, 'r') as f:
71+
content = f.read()
72+
73+
# Bump versions in the extracted jobs
74+
bumped_jobs = [bump_analysis_job(job, old_ver, new_ver) for job in jobs]
75+
76+
# Append the bumped jobs to the file
77+
new_content = content.rstrip() + '\n' + '\n'.join(bumped_jobs) + '\n'
78+
79+
with open(file_path, 'w') as f:
80+
f.write(new_content)
81+
82+
print(f" ✓ Added {len(bumped_jobs)} bumped jobs", file=sys.stderr)
83+
return True
84+
85+
# Bump multiarch jobs
86+
multiarch_file = 'ci-operator/jobs/openshift/multiarch/openshift-multiarch-master-periodics.yaml'
87+
multiarch_jobs = [
88+
f'periodic-ci-openshift-multiarch-master-nightly-{old_version}-install-analysis-all-multi-p-p',
89+
f'periodic-ci-openshift-multiarch-master-nightly-{old_version}-install-analysis-all-ppc64le',
90+
f'periodic-ci-openshift-multiarch-master-nightly-{old_version}-install-analysis-all-s390x',
91+
]
92+
93+
print("\n=== Multiarch Analysis Jobs ===", file=sys.stderr)
94+
append_bumped_jobs(multiarch_file, multiarch_jobs, old_version, new_version)
95+
96+
# Bump release jobs
97+
release_file = 'ci-operator/jobs/openshift/release/openshift-release-master-periodics.yaml'
98+
release_jobs = [
99+
f'periodic-ci-openshift-release-master-nightly-{old_version}-install-analysis-all',
100+
f'periodic-ci-openshift-release-master-nightly-{old_version}-upgrade-analysis-all',
101+
f'periodic-ci-openshift-release-master-nightly-{old_version}-overall-analysis-all',
102+
]
103+
104+
print("\n=== Release Analysis Jobs ===", file=sys.stderr)
105+
append_bumped_jobs(release_file, release_jobs, old_version, new_version)
106+
107+
print("\n✓ All analysis jobs bumped successfully", file=sys.stderr)
108+
109+
PYTHON_EOF
110+
111+
echo ""
112+
echo "=========================================="
113+
echo "✓ Analysis jobs bumped!"
114+
echo "=========================================="
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# Skill: copy-release-controller-configs
3+
# Description: Copy and update release-controller configurations from old version to new version
4+
# Usage: copy-release-controller-configs.sh <old_version> <new_version> <release_repo_path>
5+
6+
set -euo pipefail
7+
8+
if [ $# -ne 3 ]; then
9+
echo "Usage: $0 <old_version> <new_version> <release_repo_path>"
10+
echo "Example: $0 4.21 4.22 /home/prucek/work/release"
11+
exit 1
12+
fi
13+
14+
OLD_VERSION="$1"
15+
NEW_VERSION="$2"
16+
RELEASE_REPO="$3"
17+
RELEASES_DIR="${RELEASE_REPO}/core-services/release-controller/_releases"
18+
19+
echo "Bumping release controller configs: ${OLD_VERSION}${NEW_VERSION}"
20+
21+
# Escape dots for sed patterns
22+
OLD_ESCAPED="${OLD_VERSION//./\\.}"
23+
24+
# Calculate previous version for nested references
25+
PREV_MINOR=$((${OLD_VERSION##*.} - 1))
26+
PREV_VERSION="${OLD_VERSION%.*}.${PREV_MINOR}"
27+
PREV_ESCAPED="${PREV_VERSION//./\\.}"
28+
CURR_MINOR=$((${NEW_VERSION##*.} - 1))
29+
CURR_VERSION="${NEW_VERSION%.*}.${CURR_MINOR}"
30+
31+
# Find all files with old_version in their name and bump them
32+
find "$RELEASES_DIR" -type f -name "*${OLD_VERSION}*.json" 2>/dev/null | while read -r src_file; do
33+
# Skip if already processed/destination exists
34+
dst_file="${src_file//${OLD_VERSION}/${NEW_VERSION}}"
35+
[ -f "$dst_file" ] && continue
36+
37+
echo " $(basename "$src_file")$(basename "$dst_file")"
38+
cp "$src_file" "$dst_file"
39+
40+
# Bump version strings inside the file
41+
sed -i "s/${OLD_ESCAPED}/${NEW_VERSION}/g" "$dst_file"
42+
sed -i "s/${PREV_ESCAPED}/${CURR_VERSION}/g" "$dst_file"
43+
done
44+
45+
echo "Done!"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# Skill: create-pre-branching-branch
3+
# Description: Create and checkout pre-branching branch in release repository
4+
# Usage: create-pre-branching-branch.sh <old_version> <new_version> <release_repo_path>
5+
6+
set -euo pipefail
7+
8+
if [ $# -ne 3 ]; then
9+
echo "Usage: $0 <old_version> <new_version> <release_repo_path>"
10+
echo "Example: $0 4.21 4.22 /home/prucek/work/release"
11+
exit 1
12+
fi
13+
14+
OLD_VERSION="$1"
15+
NEW_VERSION="$2"
16+
RELEASE_REPO="$3"
17+
18+
echo "=========================================="
19+
echo "Creating Pre-Branching Branch"
20+
echo "=========================================="
21+
echo ""
22+
23+
cd "${RELEASE_REPO}"
24+
25+
# Fetch latest changes
26+
echo "Fetching latest changes from origin..."
27+
git fetch origin
28+
git pull origin master
29+
30+
# Create branch name
31+
BRANCH_NAME="pre-branching-${OLD_VERSION}-to-${NEW_VERSION}"
32+
33+
# Check if branch already exists
34+
if git show-ref --verify --quiet "refs/heads/${BRANCH_NAME}"; then
35+
echo ""
36+
echo "Branch '${BRANCH_NAME}' already exists locally."
37+
echo "Switching to existing branch..."
38+
git checkout "${BRANCH_NAME}"
39+
else
40+
echo ""
41+
echo "Creating new branch: ${BRANCH_NAME}"
42+
git checkout -b "${BRANCH_NAME}" origin/master
43+
fi
44+
45+
echo ""
46+
echo "=========================================="
47+
echo "✓ On branch: ${BRANCH_NAME}"
48+
echo "=========================================="

0 commit comments

Comments
 (0)