forked from section-io/prometheus_varnish_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·66 lines (52 loc) · 2.01 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
60
61
62
63
64
65
66
#!/bin/bash
set -e
if [ ! -e main.go ] ; then
echo "Error: Script can only be ran on the root of the source tree"
exit 1
fi
rm -rf bin
mkdir -p bin/build bin/release
VERSION=$1
VERSION_HASH="$(git rev-parse --short HEAD)"
VERSION_DATE="$(date -u '+%d.%m.%Y %H:%M:%S')"
echo -e "\nVERSION=$VERSION"
echo "VERSION_HASH=$VERSION_HASH"
echo "VERSION_DATE=$VERSION_DATE"
if [ -z "$VERSION" ]; then
echo "Error: First argument must be release version"
exit 1
fi
tar -cvzf ./bin/release/dashboards-$VERSION.tar.gz dashboards/* > /dev/null 2>&1
for goos in linux darwin windows freebsd openbsd netbsd ; do
for goarch in amd64 386; do
# path
file_versioned="prometheus_varnish_exporter-$VERSION.$goos-$goarch"
outdir="bin/build/$file_versioned"
path="$outdir/prometheus_varnish_exporter"
if [ $goos = windows ] ; then
path=$path.exe
fi
mkdir -p $outdir
cp LICENSE CHANGELOG.md README.md $outdir/
# build
echo -e "\nBuilding $goos/$goarch"
GOOS=$goos GOARCH=$goarch go build -o $path -ldflags "-X 'main.Version=$VERSION' -X 'main.VersionHash=$VERSION_HASH' -X 'main.VersionDate=$VERSION_DATE'"
echo " > `du -hc $path | awk 'NR==1{print $1;}'` `file $path`"
# compress (for unique filenames to github release files)
tar -C ./bin/build -cvzf ./bin/release/$file_versioned.tar.gz $file_versioned > /dev/null 2>&1
done
done
go env > .goenv
source .goenv
rm .goenv
echo -e "\nRelease done: $(./bin/build/prometheus_varnish_exporter-$VERSION.$GOOS-$GOARCH/prometheus_varnish_exporter --version)"
for goos in linux darwin windows freebsd openbsd netbsd ; do
for goarch in amd64 386; do
file_versioned="prometheus_varnish_exporter-$VERSION.$goos-$goarch"
path=bin/release/$file_versioned.tar.gz
echo " > `du -hc $path | awk 'NR==1{print $1;}'` $path"
done
done
cd ./bin/release
shasum --algorithm 256 --binary ./* | sed -En "s/\*\.\/(.*)$/\1/p" > sha256sums.txt
cd ../..