github.com/status-im/status-go@v1.1.0/_assets/scripts/tag_version.sh (about) 1 #!/usr/bin/env bash 2 3 set -euo pipefail 4 5 source _assets/scripts/parse_commits.sh 6 source _assets/scripts/colors.sh 7 8 get_latest_tag() { 9 # Get the latest tag on develop 10 latest_tag=$(git describe --tags --abbrev=0 develop) 11 echo "$latest_tag" 12 } 13 14 bump_version() { 15 local tag=$1 16 local is_breaking_change=$2 17 IFS='v.' read -r _ major minor patch <<< "$tag" 18 19 # Bump the version based on the type of change 20 if [[ "$is_breaking_change" = true ]]; then 21 ((major++)) 22 ((minor=0)) 23 ((patch=0)) 24 else 25 ((minor++)) 26 ((patch=0)) 27 fi 28 29 new_version="$major.$minor.$patch" 30 echo "v$new_version" 31 } 32 33 calculate_new_version() { 34 target_commit=$1 35 latest_tag=$2 36 37 # Parse commits to determine if there are breaking changes 38 output=$(parse_commits "$latest_tag" "$target_commit") 39 exit_code=$? 40 echo "$output" | sed '$d' >&2 # Skip the last line, it contains the breaking change flag 41 42 is_breaking_change=$(echo "$output" | tail -n 1) 43 44 if [[ $is_breaking_change == 'true' ]]; then 45 echo -e "${YLW}Breaking change detected${RST}" >&2 46 fi 47 48 if [[ $exit_code -ne 0 && $is_breaking_change != true ]]; then 49 echo -e "${YLW}Some commits are ill-formed, can not to auto-calculate new version${RST}" >&2 50 read -p "Any of the commits above have a breaking change? (y/n): " yn 51 case $yn in 52 [Yy]* ) is_breaking_change=true;; 53 [Nn]* ) is_breaking_change=false;; 54 * ) echo "Please answer yes or no."; exit 1;; 55 esac 56 fi 57 58 # Bump version accordingly 59 bump_version "$latest_tag" "$is_breaking_change" 60 } 61 62 latest_tag=$(get_latest_tag) 63 echo -e "${GRN}Latest tag found:${RST} $latest_tag" >&2 64 65 target_commit=${1:-HEAD} 66 echo -e "${GRN}Calculating new version for:${RST} $target_commit" >&2 67 68 new_version=$(calculate_new_version "$target_commit" "$latest_tag") 69 echo -e "${GRN}Calculated new version:${RST} $new_version" >&2 70 71 git tag -a "$new_version" "$target_commit" -m "release $new_version"