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