version.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # Version validation regex pattern
  3. VALID_VERSION_REGEX='^v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\.]+)?$'
  4. # Prompt for version input
  5. while true; do
  6. read -p "Enter version number: " VERSION
  7. # Remove 'v' prefix for validation
  8. if [[ "${VERSION#v}" =~ $VALID_VERSION_REGEX ]]; then
  9. # Show confirmation prompt with original input
  10. echo "You entered version: ${VERSION}"
  11. read -p "Is this correct? [Y/n] " confirm
  12. case ${confirm,,} in
  13. y|yes|"") break ;;
  14. n|no)
  15. echo "Restarting version input..."
  16. continue
  17. ;;
  18. *)
  19. echo "Invalid input, please answer Y/n"
  20. continue
  21. ;;
  22. esac
  23. else
  24. echo "Error: Invalid version format. Please use semantic versioning (e.g. 2.0.0, v2.0.1-beta.1)"
  25. fi
  26. done
  27. # Cross-platform compatible sed command
  28. if [[ "$OSTYPE" == "darwin"* ]]; then
  29. sed -i '' "s/\"version\": \".*\"/\"version\": \"${VERSION#v}\"/" app/package.json
  30. else
  31. sed -i "s/\"version\": \".*\"/\"version\": \"${VERSION#v}\"/" app/package.json
  32. fi
  33. echo "Updated package.json to version ${VERSION#v}"
  34. # Build app
  35. echo "Building app..."
  36. cd app && pnpm build
  37. if [ $? -ne 0 ]; then
  38. echo "Error: Build failed"
  39. exit 1
  40. fi
  41. cd ..
  42. # Run go generate
  43. echo "Generating Go code..."
  44. go generate
  45. if [ $? -ne 0 ]; then
  46. echo "Error: go generate failed"
  47. exit 1
  48. fi
  49. echo "Version update and generation completed successfully"