-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.sh
73 lines (56 loc) · 2.09 KB
/
archive.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env sh
set -e
# use master as default
git checkout master
# stash local changes
STASH_RESULT=`git stash`
if [ "No local changes to save" != "$STASH_RESULT" ]; then
echo "Notice: please run 'git stash pop' to restore your changes after archive."
fi
git pull origin master
VERSION=`npx select-version-cli` # get version from prompt
RECOMMEND_DATE=`date +'%Y%m%d'`
read -p "Use $RECOMMEND_DATE as archive date? [Y/N]" SHOULD_USE_RECOMMEND_DATE
if [ "N" == "$SHOULD_USE_RECOMMEND_DATE" ]; then
read -p "Please enter an archive date likes '$RECOMMEND_DATE' format: " ARCHIVE_DATE
elif [ "Y" == "$SHOULD_USE_RECOMMEND_DATE" ]; then
ARCHIVE_DATE=$RECOMMEND_DATE
else
echo "Invalid input, exit."
exit 1
fi
# update build.autobuild.js if exists
if [ -f ./build.autobuild.js ]; then
echo "Update build.autobuild.js"
# mac/linux
# sed -i '' -e "s/[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*/$VERSION/g" ./build.autobuild.js
# window
sed -i -e "s/[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*/$VERSION/g" ./build.autobuild.js
git add ./build.autobuild.js
fi
# update package.json if exists
if [ -f ./package.json ]; then
echo "Update package.json"
# mac/linux
# sed -i '' -e "s/\"version\"\: *\"[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\"/\"version\": \"$VERSION\"/g" ./package.json
# window 更通用的写法
sed -i -e "s/\"version\": *\"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\": \"$VERSION\"/g" package.json
# "version": "1.65.0"
git add ./package.json
fi
# update package-lock.json if exists
if [ -f ./package-lock.json ]; then
echo "Update package-lock.json"
# mac/linux
# sed -i '' -e "1,5s/\"version\"\: *\"[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\"/\"version\": \"$VERSION\"/g" ./package-lock.json
# window
sed -i -e "1,5s/\"version\"\: *\"[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\"/\"version\": \"$VERSION\"/g" ./package-lock.json
git add ./package-lock.json
fi
git commit -m "refactor: 版本 v$VERSION 发布"
TAG_NAME="tag-$ARCHIVE_DATE-v$VERSION"
echo "Archive $TAG_NAME"
# create tag
git tag -a $TAG_NAME -m "归档"
# push
git push origin master && git push origin -f --tags