tag_release.sh 905 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. # abort if we get any error
  3. set -e
  4. _tag=$1
  5. _branch="$(git rev-parse --abbrev-ref HEAD)"
  6. if [ "${_tag}" == "" ]; then
  7. echo "Missing version param. ex './scripts/tag_release.sh v5.1.1'"
  8. exit 1
  9. fi
  10. if [ "${_branch}" == "master" ]; then
  11. echo "you cannot tag releases from the master branch"
  12. echo "please checkout the release branch"
  13. echo "ex 'git checkout v5.1.x'"
  14. exit 1
  15. fi
  16. # always make sure to pull latest changes from origin
  17. echo "pulling latest changes from ${_branch}"
  18. git pull origin "${_branch}"
  19. # create signed tag for latest commit
  20. git tag -s "${_tag}" -m "release ${_tag}"
  21. # verify the signed tag
  22. git tag -v "${_tag}"
  23. echo "Make sure the tag is signed as expected"
  24. echo "press [y] to push the tags"
  25. read -n -r 1 confirm
  26. if [ "${confirm}" == "y" ]; then
  27. git push origin "${_branch}" --tags
  28. else
  29. git tag -d "${_tag}"
  30. echo "Abort! "
  31. fi