version-align.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. set -e
  3. # Step 1: Read the version from Cargo.toml
  4. version=$(grep '^version = ' Cargo.toml | head -n 1 | sed 's/version = "\(.*\)"/\1/')
  5. if [ -z "$version" ]; then
  6. echo "Version not found in Cargo.toml"
  7. exit 1
  8. fi
  9. echo "Aligning for version: $version"
  10. # GNU/BSD compat
  11. sedi=(-i'')
  12. case "$(uname)" in
  13. # For macOS, use two parameters
  14. Darwin*) sedi=(-i '')
  15. esac
  16. # Update the version for all crates in the Cargo.toml workspace.dependencies section
  17. sed "${sedi[@]}" "/\[workspace.dependencies\]/,/\## External crates/s/version = \"=.*\"/version = \"=$version\"/" Cargo.toml
  18. # Update the version in clients/bolt-sdk/package.json
  19. jq --arg version "$version" '.version = $version' clients/bolt-sdk/package.json > temp.json && mv temp.json clients/bolt-sdk/package.json
  20. # Update the version in crates/bolt-cli/npm-package/package.json.tmpl
  21. jq --arg version "$version" '.version = $version' crates/bolt-cli/npm-package/package.json.tmpl > temp.json && mv temp.json crates/bolt-cli/npm-package/package.json.tmpl
  22. # Update the main package version and all optionalDependencies versions in crates/bolt-cli/npm-package/package.json
  23. jq --arg version "$version" '(.version = $version) | (.optionalDependencies[] = $version)' crates/bolt-cli/npm-package/package.json > temp.json && mv temp.json crates/bolt-cli/npm-package/package.json
  24. # Potential for collisions in Cargo.lock, use cargo update to update it
  25. cargo update --workspace
  26. # Generate CHANGELOG.md
  27. git-cliff -c Cliff.toml -o docs/CHANGELOG.md -t $version
  28. # Check if the any changes have been made to the specified files, if running with --check
  29. if [[ "$1" == "--check" ]]; then
  30. files_to_check=(
  31. "clients/bolt-sdk/package.json"
  32. "crates/bolt-cli/npm-package/package.json.tmpl"
  33. "crates/bolt-cli/npm-package/package.json"
  34. "Cargo.toml"
  35. "CHANGELOG.toml"
  36. )
  37. for file in "${files_to_check[@]}"; do
  38. # Check if the file has changed from the previous commit
  39. if git diff --name-only | grep -q "$file"; then
  40. echo "Error: version not aligned for $file. Align the version, commit and try again."
  41. exit 1
  42. fi
  43. done
  44. exit 0
  45. fi