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.
 
 
 
 
 
 

115 lines
2.8 KiB

  1. #!/usr/bin/env bash
  2. RED='\033[0;31m'
  3. NOCOLOR='\033[0m'
  4. function print_error {
  5. echo -e "${RED}$1${NOCOLOR}"
  6. }
  7. function check_current_directory_is_root {
  8. if [ ! -f README.md ]; then
  9. print_error "You seems to be in the wrong directory"
  10. print_error "Execute this script from the root of lesspass with ./bin/${0##*/}"
  11. exit 1
  12. fi
  13. }
  14. function check_repository_is_clean {
  15. git remote update
  16. git add .
  17. git status
  18. git diff-index --quiet HEAD
  19. if [ $? == 1 ]
  20. then
  21. print_error "Git repository not clean. Aborting."
  22. exit 1
  23. fi
  24. if [ $(git rev-parse HEAD) != $(git rev-parse @{u}) ]
  25. then
  26. print_error "Git branch diverged. Aborting."
  27. exit 1
  28. fi
  29. }
  30. function check_branch_is_master {
  31. BRANCH_NAME=$(git branch | grep \* | cut -d ' ' -f2)
  32. if [ $BRANCH_NAME != "master" ]
  33. then
  34. print_error "Current branch is not master. Aborting."
  35. exit 1
  36. fi
  37. }
  38. function check_bump_type_is_defined {
  39. bump_type="${1}"
  40. if [ "${bump_type}" != "major" ] && [ "${bump_type}" != "minor" ] && [ "${bump_type}" != "patch" ]
  41. then
  42. print_error "Error: No bump type specified (major, minor, patch). Aborting."
  43. exit 1
  44. fi
  45. }
  46. set +o errexit
  47. bump_type="${1:-}"
  48. check_bump_type_is_defined ${bump_type}
  49. check_branch_is_master
  50. check_current_directory_is_root
  51. check_repository_is_clean
  52. set -o errexit
  53. set -o pipefail
  54. set -o nounset
  55. function increment_version {
  56. IFS='.' read -a versions <<< "${1}"
  57. major=${versions[0]}
  58. minor=${versions[1]}
  59. patch=${versions[2]}
  60. case "${2}" in
  61. "major")
  62. major=$((major + 1))
  63. minor=0
  64. patch=0
  65. ;;
  66. "minor")
  67. minor=$((minor + 1))
  68. patch=0
  69. ;;
  70. "patch")
  71. patch=$((patch + 1))
  72. ;;
  73. esac
  74. new_version="$major.$minor.$patch"
  75. echo ${new_version}
  76. }
  77. function build {
  78. cd packages/lesspass-site
  79. yarn install
  80. yarn run build
  81. cd ../../
  82. }
  83. function commit_and_push {
  84. git add .
  85. git commit --message="Auto build for lesspass-site"
  86. git push
  87. }
  88. current_version=$( grep -Po '(?<="version": ")[^"]*' packages/lesspass-site/package.json )
  89. echo "Current lesspass-site version is ${current_version}"
  90. new_version=$( increment_version ${current_version} ${bump_type} )
  91. echo "New lesspass-site version is ${new_version}"
  92. latest_lesspass_pure_version=$( yarn info -s lesspass-pure version )
  93. echo "Latest lesspass-pure version is ${latest_lesspass_pure_version}"
  94. sed -i -E "s/\"lesspass-pure\": \"([0-9]+)\.([0-9]+)\.([0-9]+)\"/\"lesspass-pure\": \"${latest_lesspass_pure_version}\"/g" packages/lesspass-site/package.json
  95. sed -i -E "s/\"version\": \"([0-9]+)\.([0-9]+)\.([0-9]+)\"/\"version\": \"${new_version}\"/g" packages/lesspass-site/package.json
  96. build
  97. commit_and_push