-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·59 lines (51 loc) · 1.49 KB
/
build.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
#!/usr/bin/env bash
package=$1
ARTIFACTS_DIR=artifacts
VERSION=$CI_COMMIT_TAG
BUILDTIME=$(date +"%Y.%m.%d.%H%M%S")
REVISION=$(git log --pretty=format:"%h" -n 1)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -z "$VERSION" ]; then
VERSION=$BRANCH'-'$REVISION
fi
if [[ -z "$package" ]]; then
echo "Usage: $0 <package-name>"
exit 1
fi
package_split=(${package//\// })
package_name=${package_split[-1]}
echo "Package name: ${package_name}"
platforms=("windows/amd64" "linux/amd64" "windows/386")
for platform in "${platforms[@]}"; do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name
archive_name=$package_name'-'$GOOS'-'$GOARCH'-'$VERSION
if [ $GOOS = "windows" ]; then
output_name+='.exe'
archive_name+='.zip'
else
archive_name+='.tgz'
fi
# env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $package
env GOOS=$GOOS GOARCH=$GOARCH go build \
-ldflags "-extldflags '-static' \
-X gospl/cmd.VERSION=$VERSION \
-X gospl/cmd.BUILT=$BUILDTIME \
-X gospl/cmd.REVISION=$REVISION \
-X gospl/cmd.BRANCH=$BRANCH \
" \
-o ./$ARTIFACTS_DIR/$output_name $package_name
if [ $? -ne 0 ]; then
echo 'Error occured'
exit 1
fi
echo "Output name: ${output_name}"
if [ $GOOS = "windows" ]; then
zip -m -j ./$ARTIFACTS_DIR/$archive_name ./$ARTIFACTS_DIR/$output_name
else
tar zcf ./$ARTIFACTS_DIR/$archive_name -C ./$ARTIFACTS_DIR $output_name
rm ./$ARTIFACTS_DIR/$output_name
fi
done