aboutsummaryrefslogtreecommitdiff
path: root/build.sh
blob: b28ce21d3e3aca11fa9a547b80bbf4aedd4865ba (plain) (blame)
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
#!/bin/sh
set -e

outdir="build"
compress="gzip"
compress_suffix="gz"
compress_flags="-3"

build_dest="riedstra.dev:/var/www/builds.riedstra.dev/hook/"

tag="$(git describe --tags)"

LICENSE="$(cat LICENSE)"

version="$(git log --format="%h %d" -1)
Commit Author: $(git log --format="%an" -1)
Commit date: $(git log --format="%aD" -1)
Build Date: $(date)
Source code can be found here:
https://git.riedstra.dev/mitch/hook

$LICENSE"

if ! git diff-index --quiet HEAD ; then
	version="dirty: $version"
fi

export CGO_ENABLED=0

pairs="linux:amd64
linux:386
linux:arm64
openbsd:amd64
freebsd:amd64
darwin:amd64
windows:amd64
windows:386"

build() {
go build \
	-o hook \
	-ldflags "-X 'main.versionString=$version'" \
	main.go
}

fullBuild() {
if ! [ -d "$outdir" ] ; then
		mkdir "$outdir"
fi

for value in $pairs ; do
	export GOOS="$(echo "$value" | awk -F: '{print $1}')"
	export GOARCH="$(echo "$value" | awk -F: '{print $2}')"

	output="$outdir/hook-${tag}-$GOOS-$GOARCH.$compress_suffix"

	if [ -e "$output" ] ; then continue ; fi

	build
	$compress $compress_flags < hook > "$output"
	rm hook
done
}

publish() {
	fullBuild
	rsync -avP build/ "$build_dest/"
}

help() {
cat <<EOF
Usage: $0 [command]
where command is one of:
	build ( default )
	fulLBuild
		build for many platforms and place compressed results in builds/
	publish 
		run fullBuild and then rsync to the publication server
EOF
}

while [ $# -gt 0 ] ; do case $1 in
		fullBuild) fullBuild ; exit ;;
		publish) publish ; exit ;;
		*) help ; exit 2 ;;
esac; done

build