new-patch-version.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. # Get the current version from package.json
  3. PREV_VERSION=$(jq -r '.version' package.json)
  4. echo "Prev Patch Version $PREV_VERSION"
  5. # Split the version number into major, minor, and patch components
  6. IFS='.' read -a VERSION_ARRAY <<< "$PREV_VERSION"
  7. echo "SPLITTING COMPLETED"
  8. major="${VERSION_ARRAY[0]}"
  9. minor="${VERSION_ARRAY[1]}"
  10. patch="${VERSION_ARRAY[2]}"
  11. echo "CURRENT PATCH VERSION $patch"
  12. # Increment the patch version
  13. patch=$((patch + 1))
  14. echo "UPDATED PATCH VERSION $patch"
  15. # Form the new version string
  16. VERSION="$major.$minor.$patch"
  17. # Split the new version number into major, minor, and patch components to validate
  18. IFS='.' read -a VERSION_ARRAY_2 <<< "$VERSION"
  19. if [[ ${#VERSION_ARRAY_2[@]} -lt 3 ]]; then
  20. echo "Error: Invalid new version format"
  21. exit 1
  22. fi
  23. # Set the branch name if it's not the master branch
  24. if [ "$BRANCH" != "refs/heads/master" ]; then
  25. BRANCH="${VERSION_ARRAY[0]}.${VERSION_ARRAY[1]}.x"
  26. fi
  27. echo "Version $VERSION"
  28. # Export the new version to the GitHub Actions environment
  29. echo "VERSION=$VERSION" >> "$GITHUB_ENV"