11#! /bin/sh
22
3+ # Check if we're running in patch mode
4+ if [ " $1 " = " patch" ]; then
5+ # Get the current version from package.json
6+ current_version=$( jq -r ' .version' package.json)
7+ # Increment the patch version
8+ version=$( echo $current_version | awk -F. -v OFS=. ' {$NF += 1; print}' )
9+ echo " Creating patch release: $current_version -> $version "
10+ elif [ " $1 " = " minor" ]; then
11+ # Get the current version from package.json
12+ current_version=$( jq -r ' .version' package.json)
13+ # Increment the minor version
14+ version=$( echo $current_version | awk -F. -v OFS=. ' {$2 += 1; $NF = 0; print}' )
15+ echo " Creating minor release: $current_version -> $version "
316# ensure that we have at least one argument conforming to semver
4- if [ $# -ne 1 ] || ! echo $1 | grep -qE " ^[0-9]+\.[0-9]+\.[0-9]+$" ; then
5- echo " Usage: $0 <version>"
17+ elif [ $# -ne 1 ] || ! echo $1 | grep -qE " ^[0-9]+\.[0-9]+\.[0-9]+$" ; then
18+ echo " Usage: $0 <version> or $0 patch or $0 minor "
619 exit 1
20+ else
21+ version=$1
722fi
823
924# ensure we are on the master branch otherwise exit
@@ -27,25 +42,6 @@ if [ -n "$(git ls-files --others --exclude-standard)" ]; then
2742 exit 1
2843fi
2944
30- # if the first argument is not a valid semver, exit
31- if ! echo $1 | grep -qE " ^[0-9]+\.[0-9]+\.[0-9]+$" ; then
32- echo " Invalid semver, exiting"
33- exit 1
34- fi
35-
36- # get the current version from package.json
37- current_version=$( jq -r ' .version' package.json)
38-
39- # take the version from teh virst argument unless it's "patch" or "minor"
40- # don't use the semver tool because it's not installed on the CI
41- if [ " $2 " = " patch" ]; then
42- version=$( echo $current_version | awk -F. -v OFS=. ' {$NF += 1; print}' )
43- elif [ " $2 " = " minor" ]; then
44- version=$( echo $current_version | awk -F. -v OFS=. ' {$2 += 1; $NF = 0; print}' )
45- else
46- version=$1
47- fi
48-
4945# update the version in package.json
5046sed -i ' ' -e " s/\" version\" : \" .*\" /\" version\" : \" $version \" /" package.json
5147
@@ -57,7 +53,7 @@ cargo build
5753git add Cargo.toml package.json Cargo.lock
5854git commit -m " :rocket: - Release v$version "
5955
60- # tag current commit with the first argument
56+ # tag current commit with the version
6157git tag -a v$version -m " :rocket: - Release v$version "
6258
6359# push the changes
0 commit comments