release.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. set -e
  3. # Function to extract version components from version.py using regex
  4. get_version_from_file() {
  5. VERSION_FILE="olmocr/version.py"
  6. if [[ ! -f "$VERSION_FILE" ]]; then
  7. echo "Error: $VERSION_FILE does not exist."
  8. exit 1
  9. fi
  10. # Extract _MAJOR
  11. _MAJOR=$(grep -E '^_MAJOR\s*=\s*"([^"]+)"' "$VERSION_FILE" | sed -E 's/_MAJOR\s*=\s*"([^"]+)"/\1/')
  12. if [[ -z "$_MAJOR" ]]; then
  13. echo "Error: Could not extract _MAJOR from $VERSION_FILE."
  14. exit 1
  15. fi
  16. # Extract _MINOR
  17. _MINOR=$(grep -E '^_MINOR\s*=\s*"([^"]+)"' "$VERSION_FILE" | sed -E 's/_MINOR\s*=\s*"([^"]+)"/\1/')
  18. if [[ -z "$_MINOR" ]]; then
  19. echo "Error: Could not extract _MINOR from $VERSION_FILE."
  20. exit 1
  21. fi
  22. # Extract _PATCH
  23. _PATCH=$(grep -E '^_PATCH\s*=\s*"([^"]+)"' "$VERSION_FILE" | sed -E 's/_PATCH\s*=\s*"([^"]+)"/\1/')
  24. if [[ -z "$_PATCH" ]]; then
  25. echo "Error: Could not extract _PATCH from $VERSION_FILE."
  26. exit 1
  27. fi
  28. # Extract _SUFFIX (optional)
  29. _SUFFIX=$(grep -E '^_SUFFIX\s*=\s*"([^"]*)"' "$VERSION_FILE" | sed -E 's/_SUFFIX\s*=\s*"([^"]*)"/\1/')
  30. if [[ -z "$_SUFFIX" ]]; then
  31. _SUFFIX=""
  32. fi
  33. # Construct VERSION
  34. VERSION_PY="${_MAJOR}.${_MINOR}.${_PATCH}${_SUFFIX}"
  35. echo "$VERSION_PY"
  36. }
  37. TAG=$(python -c 'from olmocr.version import VERSION; print("v" + VERSION)')
  38. # Get the VERSION from version.py
  39. VERSION_PY=$(get_version_from_file)
  40. # Compare the two versions
  41. if [[ "v$VERSION_PY" != "$TAG" ]]; then
  42. echo "Version mismatch detected:"
  43. echo " Python reported version: $TAG"
  44. echo " version.py contains: v$VERSION_PY"
  45. echo
  46. read -p "The versions do not match. Please run 'pip install -e .' to synchronize versions. Do you want to continue? [Y/n] " prompt
  47. if [[ ! "$prompt" =~ ^([yY][eE][sS]|[yY])$ ]]; then
  48. echo "Release process aborted due to version mismatch."
  49. exit 1
  50. else
  51. echo "Proceeding with the release despite the version mismatch."
  52. fi
  53. fi
  54. read -p "Creating new release for $TAG. Do you want to continue? [Y/n] " prompt
  55. if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
  56. python scripts/prepare_changelog.py
  57. git add -A
  58. git commit -m "Bump version to $TAG for release" || true && git push
  59. echo "Creating new git tag $TAG"
  60. git tag "$TAG" -m "$TAG"
  61. git push --tags
  62. else
  63. echo "Cancelled"
  64. exit 1
  65. fi