-
Notifications
You must be signed in to change notification settings - Fork 4
/
run
78 lines (66 loc) · 1.69 KB
/
run
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
#!/usr/bin/env bash
export COMMIT_HASH=`git rev-parse --short @`
export COMMIT_DATE=`git log -1 --pretty=format:%cI | sed -r -e 's/T.*//' -e 's/-//g'`
export BUILD_DIR="build/"
function PREBUILD {
go get ./...
}
function BUILD {
echo "=== ${FUNCNAME[0]} ==="
echo "GOOS: $GOOS"
echo "GOARCH: $GOARCH"
# If $GOOS or $GOARCH is emtpy, remove dashes
OUT_FILE=`echo "imgops-${GOOS:-_}-${GOARCH:-_}" | sed s/-_//g`
OUT_FILE+=`go env GOEXE`
echo "Filename: $OUT_FILE"
# Use $VERSION if empty use $CI_BUILD_TAG if empty use $CI_BUILD_REF
VERSION=${VERSION:-${CI_BUILD_TAG:-#${CI_BUILD_REF:0:6}}}
echo "Version: ${VERSION:-\$VERSION is empty}"
go build -ldflags "-X main.Version=$VERSION" -o "$BUILD_DIR$OUT_FILE"
}
function TEST {
echo "=== ${FUNCNAME[0]} ==="
TEST_URL="https://encrypted.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"
OUT_FILE="test.png"
if [[ ! -f $OUT_FILE ]]; then
wget -nv $TEST_URL -O $OUT_FILE
fi
go test
}
function BUILDALL {
echo "=== ${FUNCNAME[0]} ==="
OSES="windows linux darwin"
for OS in $OSES; do
export GOOS=$OS
export GOARCH=amd64
BUILD
done
}
function ZIP {
cd `dirname $1`
ZIP_FILE=`basename $1 .exe`.zip
ADD_FILE=`basename $1`
7za a -tzip $ZIP_FILE $ADD_FILE > /dev/null 2>&1
echo SHA1: `sha1sum $ZIP_FILE`
}
function ZIPALL {
export -f ZIP
find $BUILD_DIR -iname "*" ! -iname "*.zip" -type f -exec bash -c 'ZIP "$1"' - {} \;
}
function HELP {
echo -e "ImgOps Build Tool\nCommands: prebuild, build, test, buildall, zipall, help"
}
case $1 in
prebuild)
PREBUILD ;;
build)
BUILD ;;
test)
TEST ;;
buildall)
BUILDALL ;;
zipall)
ZIPALL ;;
*)
HELP ;;
esac