Skip to content

Commit a564fb3

Browse files
yanmxaclaude
andcommitted
fix: quote shell variables to resolve SonarCloud warnings
Fixed shellcheck issues in create-release.sh script: - Quote all variable expansions to prevent word splitting - Quote command substitutions properly - Quote git refs and branch names - Quote GitHub URLs in gh commands This resolves the 5 SonarCloud issues reported in PR stolostron#2082. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4254f23 commit a564fb3

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

.claude/skills/globalhub-release/scripts/create-release.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ LATEST_RELEASE=$(git branch -r | grep -E 'origin/release-[0-9]+\.[0-9]+$' | sed
3434
echo " Latest release: $LATEST_RELEASE"
3535

3636
if [ "$RELEASE_NAME" = "next" ]; then
37-
MAJOR_MINOR=$(echo $LATEST_RELEASE | sed 's/release-//')
38-
MAJOR=$(echo $MAJOR_MINOR | cut -d. -f1)
39-
MINOR=$(echo $MAJOR_MINOR | cut -d. -f2)
37+
MAJOR_MINOR=$(echo "$LATEST_RELEASE" | sed 's/release-//')
38+
MAJOR=$(echo "$MAJOR_MINOR" | cut -d. -f1)
39+
MINOR=$(echo "$MAJOR_MINOR" | cut -d. -f2)
4040
NEXT_MINOR=$((MINOR + 1))
4141
NEXT_RELEASE="release-${MAJOR}.${NEXT_MINOR}"
4242
else
@@ -45,13 +45,13 @@ fi
4545
echo " Next release: $NEXT_RELEASE"
4646

4747
# Calculate versions
48-
VERSION=$(echo $NEXT_RELEASE | sed 's/release-//')
49-
PREV_VERSION=$(echo $LATEST_RELEASE | sed 's/release-//')
50-
VERSION_SHORT=$(echo $VERSION | tr -d '.')
51-
PREV_VERSION_SHORT=$(echo $PREV_VERSION | tr -d '.')
48+
VERSION=$(echo "$NEXT_RELEASE" | sed 's/release-//')
49+
PREV_VERSION=$(echo "$LATEST_RELEASE" | sed 's/release-//')
50+
VERSION_SHORT=$(echo "$VERSION" | tr -d '.')
51+
PREV_VERSION_SHORT=$(echo "$PREV_VERSION" | tr -d '.')
5252

5353
# Calculate Global Hub version
54-
MINOR=$(echo $VERSION | cut -d. -f2)
54+
MINOR=$(echo "$VERSION" | cut -d. -f2)
5555
GH_MINOR=$((MINOR - 9))
5656
GH_VERSION="v1.${GH_MINOR}.0"
5757

@@ -63,17 +63,17 @@ echo " Job Prefix: release-${VERSION_SHORT}"
6363
echo ""
6464
echo "📍 Step 2: Creating new release branch in Global Hub repository..."
6565
git fetch origin main:refs/remotes/origin/main >/dev/null 2>&1
66-
if git show-ref --verify --quiet refs/heads/$NEXT_RELEASE; then
66+
if git show-ref --verify --quiet "refs/heads/$NEXT_RELEASE"; then
6767
echo " ⚠️ Branch $NEXT_RELEASE already exists locally"
6868
else
69-
git branch $NEXT_RELEASE origin/main
69+
git branch "$NEXT_RELEASE" origin/main
7070
echo " ✅ Created branch $NEXT_RELEASE"
7171
fi
7272

73-
if git ls-remote --heads origin $NEXT_RELEASE | grep -q $NEXT_RELEASE; then
73+
if git ls-remote --heads origin "$NEXT_RELEASE" | grep -q "$NEXT_RELEASE"; then
7474
echo " ⚠️ Branch $NEXT_RELEASE already exists on remote"
7575
else
76-
git push origin $NEXT_RELEASE
76+
git push origin "$NEXT_RELEASE"
7777
echo " ✅ Pushed branch $NEXT_RELEASE to remote"
7878
fi
7979

@@ -86,7 +86,7 @@ GITHUB_USER=$(git remote -v | grep origin | head -1 | sed -E 's|.*github.com[:/]
8686
echo " GitHub user: $GITHUB_USER"
8787

8888
# Check if already forked
89-
if gh repo view $GITHUB_USER/release --json name >/dev/null 2>&1; then
89+
if gh repo view "$GITHUB_USER/release" --json name >/dev/null 2>&1; then
9090
echo " ✅ Fork already exists, skipping fork step"
9191
else
9292
echo " ⚠️ Fork not found. Please fork https://github.com/openshift/release to your account first."
@@ -106,19 +106,19 @@ else
106106
PARENT_DIR=$(dirname "$OPENSHIFT_RELEASE_PATH")
107107
REPO_NAME=$(basename "$OPENSHIFT_RELEASE_PATH")
108108
cd "$PARENT_DIR"
109-
git clone --depth 1 https://github.com/$GITHUB_USER/release.git "$REPO_NAME"
109+
git clone --depth 1 "https://github.com/$GITHUB_USER/release.git" "$REPO_NAME"
110110
cd "$REPO_NAME"
111111
git remote add upstream https://github.com/openshift/release.git
112112
git fetch --depth 1 upstream master
113113
fi
114114

115115
# Create working branch
116116
BRANCH_NAME="${NEXT_RELEASE}-config"
117-
if git show-ref --verify --quiet refs/heads/$BRANCH_NAME; then
118-
git checkout $BRANCH_NAME
117+
if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
118+
git checkout "$BRANCH_NAME"
119119
echo " ✅ Switched to existing branch $BRANCH_NAME"
120120
else
121-
git checkout -b $BRANCH_NAME upstream/master
121+
git checkout -b "$BRANCH_NAME" upstream/master
122122
echo " ✅ Created branch $BRANCH_NAME"
123123
fi
124124

@@ -220,11 +220,11 @@ git commit -m "Add ${NEXT_RELEASE} configuration for multicluster-global-hub
220220
echo " ✅ Changes committed"
221221

222222
# Push
223-
git push -u origin $BRANCH_NAME
223+
git push -u origin "$BRANCH_NAME"
224224
echo " ✅ Pushed to fork"
225225

226226
# Create PR
227-
PR_URL=$(gh pr create --base master --head $GITHUB_USER:$BRANCH_NAME \
227+
PR_URL=$(gh pr create --base master --head "$GITHUB_USER:$BRANCH_NAME" \
228228
--title "Add ${NEXT_RELEASE} configuration for multicluster-global-hub" \
229229
--body "This PR adds ${NEXT_RELEASE} configuration for the multicluster-global-hub project.
230230

0 commit comments

Comments
 (0)