release.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. file_has_changed () {
  3. if [ ! -f $1 ]; then
  4. return 1
  5. fi
  6. for f in `git ls-files --modified`; do
  7. [[ "$f" == "$1" ]] && return 0
  8. done
  9. return 1
  10. }
  11. version_is_unique () {
  12. for v in `git tag -l`; do
  13. [[ "$v" == "v$1" ]] && return 1
  14. done
  15. return 0
  16. }
  17. on_master_branch () {
  18. [[ $(git symbolic-ref --short -q HEAD) == "master" ]] && return 0
  19. return 1
  20. }
  21. version=$(cat VERSION)
  22. previous_version=$(git describe --abbrev=0)
  23. if ! on_master_branch; then
  24. echo -e "\033[0;31mRefusing to release from non master branch.\033[0m"
  25. exit 1
  26. fi
  27. if ! file_has_changed "VERSION"; then
  28. echo -e "\033[0;31mRefusing to release because VERSION has not changed.\033[0m"
  29. exit 1
  30. fi
  31. if ! file_has_changed "CHANGELOG.mdown"; then
  32. echo -e "\033[0;31mRefusing to release because CHANGELOG.mdown has not been updated.\033[0m"
  33. exit 1
  34. fi
  35. if ! file_has_changed "package.json"; then
  36. echo -e "\033[0;31mRefusing to release because package.json has not been updated.\033[0m"
  37. exit 1
  38. fi
  39. if ! version_is_unique $version; then
  40. echo -e "\033[0;31mRefusing to release because VERSION is not unique.\033[0m"
  41. exit 1
  42. fi
  43. echo -e "\033[1mAbout to release v$version with the following changes:\033[0m"
  44. git log --date=short --pretty=format:"%ad %h%x09%an%x09%s" $previous_version..HEAD
  45. echo
  46. echo -e "\033[1mThe following files will be part of the release commit:\033[0m"
  47. git ls-files --modified
  48. echo
  49. read -e -p "Are you sure you want to release? " -n 1 -r
  50. echo
  51. if [[ $REPLY =~ ^[Yy]$ ]]; then
  52. echo -e "\033[0;32mReleasing...\033[0m"
  53. echo
  54. git commit -a -m "Build version $version"
  55. git tag -a v$version -m "Version $version"
  56. git push origin master
  57. git push --tags
  58. npm publish
  59. else
  60. echo -e "\033[0;31mCancelling...\033[0m"
  61. fi