-
Notifications
You must be signed in to change notification settings - Fork 11
/
release.sh
executable file
·96 lines (75 loc) · 1.95 KB
/
release.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
[[ "$TRACE" ]] && set -x
pushd `dirname "$0"` > /dev/null
trap __EXIT EXIT
colorful=false
tput setaf 7 > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
colorful=true
fi
function __EXIT() {
popd > /dev/null
}
function printError() {
$colorful && tput setaf 1
>&2 echo "Error: $@"
$colorful && tput setaf 7
}
function printImportantMessage() {
$colorful && tput setaf 3
>&2 echo "$@"
$colorful && tput setaf 7
}
function printUsage() {
$colorful && tput setaf 3
>&2 echo "$@"
$colorful && tput setaf 7
}
if [[ $# != 1 ]]; then
printUsage "Usage: ./`basename $0` version"
exit 1
fi
if ! [[ `echo "$1" | ag '^v\d+\.\d+\.\d+$'` ]]; then
printError "Invalid version format: $1"
exit 1
fi
if [[ `git tag | ag -Q "$1"` ]]; then
printError "tag '$1' already exists"
exit 1
fi
[[ -d release ]] && rm -rf release
function buildTools() {
echo "Building for $1..."
binaryFile="archivist"
cd cli/archivist
GOOS="$1" GOARCH=amd64 go build -o "$2/$binaryFile$3"
[[ $? -ne 0 ]] && exit 1
cd ../..
binaryFile="easyjson"
GOOS="$1" GOARCH=amd64 go build -o "$2/$binaryFile$3" github.com/edwingeng/easyjson-alt/easyjson
[[ $? -ne 0 ]] && exit 1
cp -r cli/script "$2/script"
[[ $? -ne 0 ]] && exit 1
git log --date=iso head~1..head > "$2/commit"
[[ $? -ne 0 ]] && exit 1
cd release
zip -r -m "$4".zip `basename $2`
[[ $? -ne 0 ]] && exit 1
cd ..
echo
}
goos=darwin
outputDir="`pwd`/release/archivist-$goos-$1"
buildTools "$goos" "$outputDir" "" "archivist-mac-$1"
goos=linux
outputDir="`pwd`/release/archivist-$goos-$1"
buildTools "$goos" "$outputDir" "" "archivist-$goos-$1"
goos=windows
outputDir="`pwd`/release/archivist-$goos-$1"
buildTools "$goos" "$outputDir" ".exe" "archivist-$goos-$1"
git tag "$1"
[[ $? -ne 0 ]] && exit 1
gitTag=`git tag | ag -Q "$1" | xargs echo "tag:"`
printImportantMessage "$gitTag"
echo ''
echo '====== done! ======'