diff --git a/.github/workflows/sdk-release.yml b/.github/workflows/sdk-release.yml index 4875dd0..efe5675 100644 --- a/.github/workflows/sdk-release.yml +++ b/.github/workflows/sdk-release.yml @@ -34,44 +34,40 @@ jobs: id: versioning if: ${{ steps.check_merge.outputs.merged == 'true' }} run: | - # Safely extract labels using jq, handling potential JSON parsing issues - labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[].name // empty') + PR_LABELS=${{ toJSON(github.event.pull_request.labels) }} + labels=$(echo "${PR_LABELS}" | jq -r '.[].name' 2>/dev/null || true) + 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 + + echo "increment=$increment" >> "$GITHUB_OUTPUT" - name: Get current version id: get_version if: ${{ steps.check_merge.outputs.merged == 'true' }} run: | - branchName='${{ github.ref_name }}' # e.g., v1/main + branchName="${{ github.ref_name }}" 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 @@ -80,17 +76,13 @@ jobs: id: bump_version if: ${{ steps.check_merge.outputs.merged == 'true' }} run: | - increment='${{ steps.versioning.outputs.increment }}' - currentVersion='${{ steps.get_version.outputs.currentVersion }}' - - # More robust version parsing + increment="${{ steps.versioning.outputs.increment }}" + currentVersion="${{ steps.get_version.outputs.currentVersion }}" IFS='.' read -ra versionParts <<< "$currentVersion" - - # Ensure we have at least 3 parts - major=${versionParts[0]:-0} - minor=${versionParts[1]:-0} - patch=${versionParts[2]:-0} - + major=${versionParts[0]} + minor=${versionParts[1]} + patch=${versionParts[2]} + if [ "$increment" == 'minor' ]; then minor=$((minor + 1)) patch=0 @@ -100,13 +92,11 @@ 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