-
Notifications
You must be signed in to change notification settings - Fork 398
/
release
executable file
·129 lines (100 loc) · 3.26 KB
/
release
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
FROM_BRANCH=master
TO_BRANCH=dist
ORIGIN_REMOTE=origin
set -eo pipefail
cd "$(dirname $0)"
function usage() {
echo -e "Usage:"
echo -e " ./release <action> <version>"
echo -e "\nArguments:"
echo -e " <action>\tbuild, push or publish"
echo -e " <version>\tversion passed to mversion"
echo -e "\nTo release a new version to npm you have to:"
echo -e " ./release build v5.0.0\t\tbuilds a new version in dist branch"
echo -e " ./release push v5.0.0\t\tpushes repo to github"
echo -e " ./release publish v5.0.0\tpublishes version using npm"
exit 1
}
if [[ -n "$(git status --porcelain)" ]]; then
echo "Working tree/index must be clean before proceeding"
exit 1
fi
if [ $# -lt 2 ]; then
usage
fi
action=$1; shift
given_version=$1; shift
export PATH="./node_modules/.bin:$PATH"
function echoinfo() {
echo -e "\n$(tput bold)$(tput setaf 7)-- $*$(tput sgr0)\n"
}
if [[ $action = "push" ]]; then
git push --tags $ORIGIN_REMOTE $FROM_BRANCH $TO_BRANCH
echoinfo "Remember to publish to npm:\n\n$0 publish $given_version"
exit
fi
if [[ $action = "publish" ]]; then
if [[ -z $given_version ]]; then
echo "fatal: make sure you provide a version number: v0.5.0."
exit 1
elif ! git ls-remote --exit-code --tags origin $given_version; then
echo "fatal: make sure you $0 push before publishing."
exit 1
fi
git checkout $TO_BRANCH
if [[ $given_version == *"beta"* ]]; then
npm publish . --tag beta
else
npm publish .
fi
git checkout $FROM_BRANCH
exit
fi
if [[ $action = "build" ]]; then
if ! command -v mversion >/dev/null; then
echo "mversion command not found. Please run 'npm install'."
exit 1
fi
git fetch $ORIGIN_REMOTE
if git show-ref --verify --quiet refs/remotes/$ORIGIN_REMOTE/$TO_BRANCH; then
# A dist branch exists on origin
if ! git show-ref --verify --quiet refs/heads/$TO_BRANCH; then
# Create it locally if we don't have it
git branch --track $TO_BRANCH $ORIGIN_REMOTE/$TO_BRANCH
fi
else
# There's no dist branch; set it up for the first time
git branch $TO_BRANCH $FROM_BRANCH
git push $ORIGIN_REMOTE $TO_BRANCH:refs/heads/$TO_BRANCH
git branch --set-upstream-to=$ORIGIN_REMOTE/$TO_BRANCH $TO_BRANCH
fi
git checkout $FROM_BRANCH
[[ -d build ]] && rm -r build
echoinfo "Current version: $(mversion)"
echoinfo "Updating version"
new_version=$(mversion $given_version | awk -F': ' '/^Updated to new version/{print $2}')
if [[ -z $new_version ]]; then
echo "fatal: couldn't find new version in output of mversion. It's been updated and broken this script."
echo 1
fi
git add --all :/
git commit -m "Bumped to $new_version
[ci skip]"
echoinfo "Switching to dist branch and merging"
git checkout $TO_BRANCH
git reset --hard refs/remotes/$ORIGIN_REMOTE/$TO_BRANCH
git merge --no-commit $FROM_BRANCH
echoinfo "Building distribution files"
npm run dist
# mv -f build/* .
# rm -r build/
git add --all :/
git commit -m "Added distribution files for $new_version
[ci skip]"
git tag -a "$new_version" -m "Tagged ${new_version}"
echoinfo "Check the commit worked and then push:\n\n$0 push $new_version"
git checkout --quiet -
exit
fi
usage