version-bump.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. set -e
  3. if [ $# -eq 0 ]; then
  4. echo "Usage $0 VERSION"
  5. exit 1
  6. fi
  7. echo "Bumping versions to $1"
  8. # GNU/BSD compat
  9. sedi=(-i)
  10. case "$(uname)" in
  11. # For macOS, use two parameters
  12. Darwin*) sedi=(-i "")
  13. esac
  14. git grep -l $(cat VERSION) -- ':!**/yarn.lock' ':!CHANGELOG.md' ':!Cargo.lock' ':!package.json' | \
  15. xargs sed "${sedi[@]}" \
  16. -e "s/$(cat VERSION)/$1/g"
  17. # Potential for collisions in package.json files, handle those separately
  18. # Replace only matching "version": "x.xx.x" and "@project-serum/anchor": "x.xx.x"
  19. git grep -l $(cat VERSION) -- '**/package.json' | \
  20. xargs sed "${sedi[@]}" \
  21. -e "s/@project-serum\/anchor\": \"$(cat VERSION)\"/@project-serum\/anchor\": \"$1\"/g" \
  22. -e "s/\"version\": \"$(cat VERSION)\"/\"version\": \"$1\"/g"
  23. # Potential for collisions in Cargo.lock, use cargo update to update it
  24. cargo update --workspace
  25. # Insert version number into CHANGELOG.md
  26. sed "${sedi[@]}" -e "s/## \[Unreleased\]/## [Unreleased]\n\n## [$1] - $(date '+%Y-%m-%d')/g" CHANGELOG.md
  27. echo $1 > VERSION
  28. echo "$(git diff --stat | tail -n1) files modified"
  29. echo " $(cat VERSION) changeset generated, commit and tag"