diff --git a/.github/workflows/sdk-release.yml b/.github/workflows/sdk-release.yml index f45c28f..4875dd0 100644 --- a/.github/workflows/sdk-release.yml +++ b/.github/workflows/sdk-release.yml @@ -34,15 +34,12 @@ 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 @@ -50,22 +47,31 @@ jobs: 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 @@ -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 @@ -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