Skip to content

Commit 764d396

Browse files
committed
update sdk-release
1 parent 6540689 commit 764d396

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

.github/workflows/sdk-release.yml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,44 @@ jobs:
3434
id: versioning
3535
if: ${{ steps.check_merge.outputs.merged == 'true' }}
3636
run: |
37-
PR_LABELS="${{ toJSON(github.event.pull_request.labels) }}"
38-
labels=$(jq -r '.[].name' <<< "$PR_LABELS")
37+
# Safely extract labels using jq, handling potential JSON parsing issues
38+
labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[].name // empty')
3939
echo "PR labels: $labels"
40-
4140
increment="patch"
4241
if echo "$labels" | grep -q "feature"; then
4342
increment="minor"
44-
elif echo "$labels" | grep -q "bugfix"; then
45-
increment="patch"
4643
fi
4744
echo "increment=$increment" >> $GITHUB_OUTPUT
4845
4946
- name: Get current version
5047
id: get_version
5148
if: ${{ steps.check_merge.outputs.merged == 'true' }}
5249
run: |
53-
branchName="${{ github.ref_name }}"
50+
branchName='${{ github.ref_name }}' # e.g., v1/main
5451
echo "Branch name: $branchName"
52+
53+
# More robust branch name parsing
5554
if [[ $branchName =~ ^v([0-9]+)/main$ ]]; then
5655
majorVersion="${BASH_REMATCH[1]}"
5756
echo "Major version: $majorVersion"
57+
58+
# Fetch all tags and sort them
5859
git fetch --tags
60+
61+
# Find the latest tag for this major version, handling more edge cases
5962
latestTag=$(git tag --list "v$majorVersion.*.*" | sort -V | tail -n1)
63+
6064
if [ -n "$latestTag" ]; then
6165
currentVersion="${latestTag#v}"
6266
else
67+
# If no tags exist, start at the initial version
6368
currentVersion="$majorVersion.0.0"
6469
fi
6570
else
6671
echo "Branch name does not match expected pattern"
6772
exit 1
6873
fi
74+
6975
echo "Current version: $currentVersion"
7076
echo "major=$majorVersion" >> $GITHUB_OUTPUT
7177
echo "currentVersion=$currentVersion" >> $GITHUB_OUTPUT
@@ -74,13 +80,17 @@ jobs:
7480
id: bump_version
7581
if: ${{ steps.check_merge.outputs.merged == 'true' }}
7682
run: |
77-
increment="${{ steps.versioning.outputs.increment }}"
78-
currentVersion="${{ steps.get_version.outputs.currentVersion }}"
83+
increment='${{ steps.versioning.outputs.increment }}'
84+
currentVersion='${{ steps.get_version.outputs.currentVersion }}'
85+
86+
# More robust version parsing
7987
IFS='.' read -ra versionParts <<< "$currentVersion"
80-
major=${versionParts[0]}
81-
minor=${versionParts[1]}
82-
patch=${versionParts[2]}
83-
88+
89+
# Ensure we have at least 3 parts
90+
major=${versionParts[0]:-0}
91+
minor=${versionParts[1]:-0}
92+
patch=${versionParts[2]:-0}
93+
8494
if [ "$increment" == 'minor' ]; then
8595
minor=$((minor + 1))
8696
patch=0
@@ -90,11 +100,13 @@ jobs:
90100
echo "Unknown increment type: $increment"
91101
exit 1
92102
fi
93-
103+
94104
newVersion="$major.$minor.$patch"
95105
echo "New version: $newVersion"
96106
echo "newVersion=$newVersion" >> $GITHUB_OUTPUT
97107
108+
# ... rest of the workflow remains the same
109+
98110
- name: Install xmlstarlet
99111
if: ${{ steps.check_merge.outputs.merged == 'true' }}
100112
run: sudo apt-get install -y xmlstarlet

0 commit comments

Comments
 (0)