aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2020-10-08 17:05:29 -0400
committerMitch Riedstra <mitch@riedstra.us>2020-10-08 17:10:33 -0400
commit046df34dc95c42a8056232116323f807d4c6755a (patch)
treec5deb39b1ef22d84238807b7e01ad76f97e6918d
parentbb8478aba426ac6e6de94141a7bb0286204b2824 (diff)
downloadhook-046df34dc95c42a8056232116323f807d4c6755a.tar.gz
hook-046df34dc95c42a8056232116323f807d4c6755a.tar.xz
Ignore build result 'hook' and update the build script.HEADmaster
-rw-r--r--.gitignore2
-rwxr-xr-xbuild.sh83
2 files changed, 83 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4e12b10
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+build
+hook
diff --git a/build.sh b/build.sh
index 0f5b244..b28ce21 100755
--- a/build.sh
+++ b/build.sh
@@ -1,9 +1,88 @@
#!/bin/sh
set -e
-set -x
+
+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='"$(git log --pretty=format:"%D %h %an %aD" -n 1)"'"' \
+ -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