Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions .github/workflows/sdk-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,44 @@ jobs:
id: versioning
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
PR_LABELS="${{ toJSON(github.event.pull_request.labels) }}"
labels=$(jq -r '.[].name' <<< "$PR_LABELS")
# Safely extract labels using jq, handling potential JSON parsing issues
labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[].name // empty')
echo "PR labels: $labels"

increment="patch"
if echo "$labels" | grep -q "feature"; then
increment="minor"
elif echo "$labels" | grep -q "bugfix"; then
increment="patch"
fi
echo "increment=$increment" >> $GITHUB_OUTPUT

- name: Get current version
id: get_version
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
branchName="${{ github.ref_name }}"
branchName='${{ github.ref_name }}' # e.g., v1/main
echo "Branch name: $branchName"

# More robust branch name parsing
if [[ $branchName =~ ^v([0-9]+)/main$ ]]; then
majorVersion="${BASH_REMATCH[1]}"
echo "Major version: $majorVersion"

# Fetch all tags and sort them
git fetch --tags

# Find the latest tag for this major version, handling more edge cases
latestTag=$(git tag --list "v$majorVersion.*.*" | sort -V | tail -n1)

if [ -n "$latestTag" ]; then
currentVersion="${latestTag#v}"
else
# If no tags exist, start at the initial version
currentVersion="$majorVersion.0.0"
fi
else
echo "Branch name does not match expected pattern"
exit 1
fi

echo "Current version: $currentVersion"
echo "major=$majorVersion" >> $GITHUB_OUTPUT
echo "currentVersion=$currentVersion" >> $GITHUB_OUTPUT
Expand All @@ -74,13 +80,17 @@ jobs:
id: bump_version
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
increment="${{ steps.versioning.outputs.increment }}"
currentVersion="${{ steps.get_version.outputs.currentVersion }}"
increment='${{ steps.versioning.outputs.increment }}'
currentVersion='${{ steps.get_version.outputs.currentVersion }}'

# More robust version parsing
IFS='.' read -ra versionParts <<< "$currentVersion"
major=${versionParts[0]}
minor=${versionParts[1]}
patch=${versionParts[2]}


# Ensure we have at least 3 parts
major=${versionParts[0]:-0}
minor=${versionParts[1]:-0}
patch=${versionParts[2]:-0}

if [ "$increment" == 'minor' ]; then
minor=$((minor + 1))
patch=0
Expand All @@ -90,11 +100,13 @@ jobs:
echo "Unknown increment type: $increment"
exit 1
fi

newVersion="$major.$minor.$patch"
echo "New version: $newVersion"
echo "newVersion=$newVersion" >> $GITHUB_OUTPUT

# ... rest of the workflow remains the same

- name: Install xmlstarlet
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: sudo apt-get install -y xmlstarlet
Expand Down
Loading