next-dev-version.sh (877B)
1 #!/bin/bash 2 3 set -e 4 5 FILE=$1 6 [ ! -w "$FILE" ] && echo first argument should be a writtable file && exit 1 7 jq -e . $FILE >/dev/null 2>&1 || (echo $FILE should be a json file && exit 1) 8 jq -e .version $FILE >/dev/null 2>&1 || (echo $FILE does not have a version field to increment && exit 1) 9 10 # looks for [string]-dev.[number] 11 # if not present returns [first].[second].[third+1]-dev.1 12 # else returns [string]-dev.[version+1] 13 inc_version() { 14 jq '. + {"version": (if .version | contains("-dev") then [.version | match("^(.*)-dev.([0-9]*)$").captures[].string] | .[0] + "-dev." + (.[1]|tonumber|.+1|tostring) else [.version | match("^([0-9]*)\\.([0-9]*)\\.([0-9]*)$").captures[].string] | .[0] + "." + .[1] + "." + (.[2]|tonumber|.+1|tostring) + "-dev.1" end)}' 15 } 16 17 # read file 18 # replace version 19 # save to buffer 20 # write the same file 21 cat <<< $(cat $FILE | inc_version) > $FILE