Skip to content

Commit

Permalink
update sdk-release
Browse files Browse the repository at this point in the history
  • Loading branch information
eneshoxha committed Dec 10, 2024
1 parent 9211053 commit f404852
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions .github/workflows/sdk-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ jobs:
id: versioning
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
PR_LABELS="${{ toJSON(github.event.pull_request.labels) }}"
# Parse PR labels using jq
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"
Expand All @@ -49,22 +47,31 @@ jobs:
id: get_version
if: ${{ steps.check_merge.outputs.merged == 'true' }}
run: |
branchName="${{ github.ref_name }}" # e.g., v1/main
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 @@ -73,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 @@ -89,7 +100,7 @@ jobs:
echo "Unknown increment type: $increment"
exit 1
fi
newVersion="$major.$minor.$patch"
echo "New version: $newVersion"
echo "newVersion=$newVersion" >> $GITHUB_OUTPUT
Expand Down

0 comments on commit f404852

Please sign in to comment.