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.

87 lines
2.6 KiB

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