Skip to content

Commit 5f347c5

Browse files
committed
✨ - improve release script
1 parent f573fd3 commit 5f347c5

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

release.sh

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,56 @@ if [ $(git rev-parse --abbrev-ref HEAD) != "master" ]; then
1212
exit 1
1313
fi
1414

15-
# update the version in package.json
16-
sed -i '' -e "s/\"version\": \".*\"/\"version\": \"$1\"/" package.json
15+
# ensure master is up to date
16+
git pull
17+
18+
# ensure that there are no uncommitted changes
19+
if [ -n "$(git status --porcelain)" ]; then
20+
echo "There are uncommitted changes, exiting"
21+
exit 1
22+
fi
23+
24+
# ensure that there are no untracked files
25+
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
26+
echo "There are untracked files, exiting"
27+
exit 1
28+
fi
1729

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+
49+
# update the version in package.json
50+
sed -i '' -e "s/\"version\": \".*\"/\"version\": \"$version\"/" package.json
1851

1952
# update the version in cargo.toml
20-
sed -i '' -e "s/^version = \".*\"/version = \"$1\"/" Cargo.toml
53+
sed -i '' -e "s/^version = \".*\"/version = \"$version\"/" Cargo.toml
2154
cargo build
2255

2356
# commit the changes with the version
2457
git add Cargo.toml package.json Cargo.lock
25-
git commit -m ":rocket: - Release v$1"
58+
git commit -m ":rocket: - Release v$version"
2659

2760
# tag current commit with the first argument
28-
git tag -a v$1 -m ":rocket: - Release v$1"
61+
git tag -a v$version -m ":rocket: - Release v$version"
2962

3063
# push the changes
3164
git push origin master
3265

3366
# push the tag
34-
git push origin v$1
67+
git push origin v$version

0 commit comments

Comments
 (0)