branch-commit-push.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. GREEN='\033[0;32m'
  3. RED='\033[0;31m'
  4. WHITE='\033[0;37m'
  5. RESET='\033[0m'
  6. function validateVersion()
  7. {
  8. echo ""
  9. passedVersion=$1
  10. echo -e "${WHITE}-- Validating tag '$passedVersion'...${RESET}"
  11. # Todo: validate the version here using a regex; if fail, just exit
  12. # ... expect 8.75.0, with no v in front of it
  13. if [[ $passedVersion == '' ]]; then
  14. echo -e "\n-- Invalid tag. Tags should be structured without v; e.g. 8.57.0"
  15. exit
  16. fi
  17. echo -e "${WHITE}-- Tag valid.${RESET}"
  18. echo ""
  19. }
  20. # Exit script if any command fails (e.g. phpunit)
  21. set -e
  22. # Require confirmation it's set up corrctly
  23. echo
  24. echo -e "${WHITE}-- This script is meant to be run after running upgrade.sh, BEFORE committing to Git.${RESET}"
  25. while true; do
  26. echo -e "${GREEN}-- Is that the current state of your local project?${RESET}"
  27. read -p "-- (y/n) " yn
  28. case $yn in
  29. [Yy]* ) break;;
  30. [Nn]* ) exit;;
  31. * ) echo "Please answer y or n.";;
  32. esac
  33. done
  34. # Get the version and exit if not valid
  35. validateVersion $1
  36. # Create official v prefaced version
  37. version="v$1"
  38. # Run tests (and bail if they fail)
  39. phpunit
  40. echo -e "\n${WHITE}-- Tests succeeded.${RESET}"
  41. # Branch
  42. echo -e "\n${WHITE}-- Creating a Git branch '$version-changes'...${RESET}\n"
  43. git checkout -b $version-changes
  44. # Add and commit, with "v8.57.0 changes" as the commit name
  45. git add -A
  46. git commit -m "$version changes"
  47. echo
  48. echo -e "${WHITE}-- Git committed.${RESET}"
  49. # Push
  50. git push -u origin $version-changes