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