-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease
executable file
·145 lines (108 loc) · 3.04 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
die () {
echo >&2 "$@
"
echo "Rolling back..."
git reset --hard $revision > /dev/null
echo "done."
exit 1
}
## Check for parameter input
[ "$#" -eq 1 ] || die "
Usage:
build x.y.z
Where x.y.z is the new version number
"
## Check for uncommited changes
if ! git diff-index --quiet HEAD -- ;then
echo "
You have uncommitted changes. Please sort that out and try again.
"
exit 1
fi
## Check for untracked files
if [ "$(git ls-files --other --exclude-standard)" != "" ];then
echo "
You have untracked files. Please sort that out and try again.
"
exit 1
fi
## Check that we're on master branch
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
[ $branch == "master" ] || die "
Currently on branch $branch. Please switch to master to release.
"
## Store git revision number for rollback
revision=$(git rev-parse HEAD)
## Check the version number format
echo $1 | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+$' || die "The version number must be in the format x.y.z
"
## Extract parts of new version number
newBreaking=$(echo $1 | cut -d . -f 1)
newFeature=$(echo $1 | cut -d . -f 2)
newPatch=$(echo $1 | cut -d . -f 3)
## Read package version
oldVersion=$(cat package.json | grep -E '"version": "([0-9]+\.[0-9]+\.[0-9]+)"' | cut -d \" -f 4)
## Extract parts of old version number
oldBreaking=$(echo $oldVersion | cut -d . -f 1)
oldFeature=$(echo $oldVersion | cut -d . -f 2)
oldPatch=$(echo $oldVersion | cut -d . -f 3)
## check that this version is greater
if [ $newBreaking -gt $oldBreaking ];then
die "
Cannot release breaking changes with this script. Please do it manually to make sure that is your intention.
"
fi
greater=0
if [[ $newBreaking -gt $oldBreaking ]];then
greater=1
fi
if [[ $newBreaking -eq $oldBreaking ]];then
if [[ $newFeature -gt $oldFeature ]] ||
[[ $newFeature -eq $oldFeature && $newPatch -gt $oldPatch ]];then
greater=1
fi
fi
if [ $greater -ne 1 ];then
die "
New version number ($1) must be greater than the old one ($oldVersion). Aborting.
"
fi
## From here on there are changes made to files etc.
## Update package version
sed -i '' -e "s/\"version\": \"$oldVersion\"/\"version\": \"$1\"/g" package.json
## Test
echo 'Testing un-minified... '
./test | grep -E -q 'FAILED' && die "Aborting due to un-minified version failing tests.
"
echo 'passed.'
## Package with r.js
echo 'Building minified version... '
./build | grep -E -q 'done.' || die "Aborting due to unsuccessful build."
echo 'done.'
## Test build
echo 'Testing minified... '
./testMin | grep -E -q 'FAILED' && die "Aborting due to minified version failing tests.
"
echo 'passed.'
## Commit
echo 'Committing... '
git commit -am "Updated to version $1" || die "
Error committing changes...
"
echo 'done.'
## Tag
echo "Tagging as version $1... "
git tag -am "Version $1" v$1 || die "
Error tagging...
"
echo 'done.'
## Push
echo 'Pushing to origin... '
git push origin master || die "
Error pushing to origin...
"
git push origin --tags || die "
Error pushing tags to origin...
"
echo 'done.'