You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.8 KiB

  1. #!/bin/bash
  2. REMOTE_REPOSITORY='origin'
  3. REMOTE_BRANCH='master'
  4. PATH_LIB='/lib/Image'
  5. PROJECTS=( "/var/www/10ballov" "/var/www/predelanet" "/var/www/zelenoemore" "/var/www/d753_common" "/var/www/d753_predelanet" "/var/www/d753_10ballov" )
  6. if [ ! -f "CHANGELOG.md" ]
  7. then
  8. echo "CHANGELOG.md not exists\n"
  9. exit 1
  10. fi
  11. test -n "`tail CHANGELOG.md`"
  12. CHANGELOG_EMPTY=`echo $?`
  13. if [ $CHANGELOG_EMPTY == 1 ]
  14. then
  15. echo -e "CHANGELOG.md is empty\n"
  16. exit 1
  17. fi
  18. git diff-index --quiet HEAD --
  19. REPO_CHANGED=`echo $?`
  20. if [ $REPO_CHANGED == 1 ]
  21. then
  22. echo -e "Please commit all changes in repository\n"
  23. exit 1
  24. fi
  25. VERSION_PREVIOUS=`sed -n '4,4p' CHANGELOG.md | cut -d "(" -f1 | tr -d ' '`
  26. if [ `git rev-parse ${VERSION_PREVIOUS}` != `git rev-parse HEAD` ]
  27. then
  28. VERSION=`echo ${VERSION_PREVIOUS} | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'`
  29. git tag "$VERSION" &&
  30. gitchangelog > CHANGELOG.md &&
  31. {
  32. git add CHANGELOG.md >/dev/null &&
  33. git commit -m "Update CHANGELOG.md" > /dev/null &&
  34. git tag -d "$VERSION" >/dev/null &&
  35. git tag "$VERSION" >/dev/null &&
  36. git push "${REMOTE_REPOSITORY}" --tags >/dev/null 2>/dev/null
  37. } || {
  38. echo -e "Cannot push released tag into remote repository\n"
  39. exit 1
  40. }
  41. else
  42. VERSION=$VERSION_PREVIOUS
  43. fi
  44. git push "${REMOTE_REPOSITORY}" HEAD:"${REMOTE_BRANCH}" >/dev/null || exit 1
  45. MESSAGE="Update ${PATH_LIB} on ${VERSION}"
  46. CURRENT_DIR=`pwd`
  47. for project in "${PROJECTS[@]}"
  48. do
  49. echo -e "Update lib for ${project}...\n"
  50. {
  51. cd "${project}${PATH_LIB}" &&
  52. git fetch "${REMOTE_REPOSITORY}" >/dev/null 2>/dev/null &&
  53. git checkout "$VERSION" 2>/dev/null;
  54. } || {
  55. echo -e "Failed to checkout lib on tag ${VERSION}\n" &&
  56. exit 1;
  57. }
  58. # cd "${project}"
  59. # LIB_DIR=`echo ${PATH_LIB#'/'}`
  60. # git diff-index --quiet HEAD "$LIB_DIR"
  61. # LIB_NEW_COMMITS=`echo $?`
  62. # if [ $LIB_NEW_COMMITS == 1 ]
  63. # then
  64. # {
  65. # git reset >/dev/null &&
  66. # git add "$LIB_DIR" >/dev/null &&
  67. # git commit -m "$MESSAGE" >/dev/null
  68. # } || {
  69. # echo -e "Failed to update lib for ${project}\n"
  70. # exit 1
  71. # }
  72. # if [ $project == "/var/www/d753_common" ]
  73. # then
  74. # {
  75. # git push origin master > /dev/null &&
  76. # cd /var/www/d753_predelanet/ && ./merge-from-master.sh > /dev/null
  77. # cd /var/www/d753_10ballov/ && ./merge-from-master.sh > /dev/null
  78. # } || {
  79. # echo -e "Failed to update dependency d753 branches... Please resolve that problem by hand\n"
  80. # exit 1
  81. # }
  82. # fi
  83. # else
  84. # echo -e "Already update\n"
  85. # fi
  86. done
  87. echo -e "All operations succeed\n"
  88. exit 0