confirm-cargo-version-numbers-before-bump.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. set -e
  3. usage() {
  4. cat <<EOF
  5. usage: $0 branch tag
  6. Checks that the tag matches the branch (unless branch is master) and the Cargo.toml versions match the tag.
  7. EOF
  8. exit 0
  9. }
  10. branch="$1"
  11. tag="$2"
  12. [[ -n $tag ]] || usage
  13. echo "branch: $branch tag: $tag"
  14. # The tag is expected to be the branch name plus a patch number (unless branch is master). eg:
  15. # tag: v1.2.3
  16. # branch: v1.2
  17. if [[ "$tag" != "$branch"* && $branch != "master" ]]; then
  18. >&2 echo "Tag must start with the branch name (unless branch is master). Tag: $tag Branch: $branch"
  19. exit 1
  20. fi
  21. here="$(dirname "$0")"
  22. cd "$here"/..
  23. source scripts/read-cargo-variable.sh
  24. ignores=(
  25. .cache
  26. .cargo
  27. target
  28. node_modules
  29. )
  30. not_paths=()
  31. for ignore in "${ignores[@]}"; do
  32. not_paths+=(-not -path "*/$ignore/*")
  33. done
  34. # shellcheck disable=2207
  35. Cargo_tomls=($(find . -mindepth 2 -name Cargo.toml "${not_paths[@]}"))
  36. for Cargo_toml in "${Cargo_tomls[@]}"; do
  37. manifest_version="$(readCargoVariable version "${Cargo_toml}")"
  38. if ! [[ "v$manifest_version" == "$tag" ]]; then
  39. >&2 echo "Tag must match the crate version in the manifest files. Mismatch found in $Cargo_toml. Tag: $tag Manifest version: $manifest_version"
  40. exit 1
  41. else
  42. echo "tag matches manifest: $Cargo_toml $manifest_version $tag"
  43. fi
  44. done