Skip to content

Commit c634e63

Browse files
committed
refactor($release): add validation for release option's reply
1 parent ff1e1e5 commit c634e63

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

scripts/release.sh

+37-31
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,51 @@
11
#!/bin/bash
22

3-
echo "Select a version to release (input number):"
3+
echo "Select a option to release (input a serial number):"
44
echo
55

66
select VERSION in patch minor major "Specific Version"
77
do
88
echo
9-
if [[ $REPLY == 4 ]]; then
10-
read -p "Enter a specific version: " -r VERSION
11-
echo
12-
if [[ -z $REPLY ]]; then
13-
VERSION=$REPLY
9+
if [[ $REPLY =~ ^[1-4]$ ]]; then
10+
if [[ $REPLY == 4 ]]; then
11+
read -p "Enter a specific version: " -r VERSION
12+
echo
13+
if [[ -z $REPLY ]]; then
14+
VERSION=$REPLY
15+
fi
1416
fi
15-
fi
1617

17-
read -p "Releasing @$VERSION version - are you sure? (y/n) " -n 1 -r
18-
echo
18+
read -p "Release $VERSION - are you sure? (y/n) " -n 1 -r
19+
echo
1920

20-
if [[ $REPLY =~ ^[Yy]$ ]]; then
21-
# pre release task
22-
npm run lint
23-
npm run test
24-
25-
# bump version
26-
npm version $VERSION
27-
NEW_VERSION=$(node -p "require('./package.json').version")
28-
echo Releasing ${NEW_VERSION} ...
29-
30-
# npm release
31-
npm publish
32-
echo "✅ released to npm"
33-
34-
# github release
35-
git add CHANGELOG.md
36-
git commit -m "chore: changelog"
37-
git push
38-
git push origin refs/tags/v${NEW_VERSION}
39-
echo "✅ released to Github"
21+
if [[ $REPLY =~ ^[Yy]$ ]]; then
22+
# pre release task
23+
npm run lint
24+
npm run test
25+
26+
# bump version
27+
npm version $VERSION
28+
NEW_VERSION=$(node -p "require('./package.json').version")
29+
echo Releasing ${NEW_VERSION} ...
30+
31+
# npm release
32+
npm publish
33+
echo "✅ Released to npm."
34+
35+
# github release
36+
git add CHANGELOG.md
37+
git commit -m "chore: changelog"
38+
git push
39+
git push origin refs/tags/v${NEW_VERSION}
40+
echo "✅ Released to Github."
41+
else
42+
echo Cancelled
43+
fi
44+
break
4045
else
41-
echo Cancelled
46+
echo Invalid \"${REPLY}\"
47+
echo "To continue, please input a serial number(1-4) of an option."
48+
echo
4249
fi
43-
break
4450
done
4551

0 commit comments

Comments
 (0)