aboutsummaryrefslogtreecommitdiff
path: root/build.bash
diff options
context:
space:
mode:
Diffstat (limited to 'build.bash')
-rwxr-xr-xbuild.bash55
1 files changed, 55 insertions, 0 deletions
diff --git a/build.bash b/build.bash
new file mode 100755
index 000000000..b7c97d1ec
--- /dev/null
+++ b/build.bash
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+#
+# Caddy build script. Automates proper versioning.
+#
+# Usage:
+#
+# $ ./build.bash [output_filename]
+#
+# Outputs compiled program in current directory.
+# Default file name is 'ecaddy'.
+#
+set -e
+
+output="$1"
+if [ -z "$output" ]; then
+ output="ecaddy"
+fi
+
+pkg=main
+
+# Timestamp of build
+builddate_id=$pkg.buildDate
+builddate=`date -u`
+
+# Current tag, if HEAD is on a tag
+tag_id=$pkg.gitTag
+set +e
+tag=`git describe --exact-match HEAD 2> /dev/null`
+set -e
+
+# Nearest tag on branch
+lasttag_id=$pkg.gitNearestTag
+lasttag=`git describe --abbrev=0 --tags HEAD`
+
+# Commit SHA
+commit_id=$pkg.gitCommit
+commit=`git rev-parse --short HEAD`
+
+# Summary of uncommited changes
+shortstat_id=$pkg.gitShortStat
+shortstat=`git diff-index --shortstat HEAD`
+
+# List of modified files
+files_id=$pkg.gitFilesModified
+files=`git diff-index --name-only HEAD`
+
+
+go build -ldflags "
+ -X \"$builddate_id=$builddate\"
+ -X \"$tag_id=$tag\"
+ -X \"$lasttag_id=$lasttag\"
+ -X \"$commit_id=$commit\"
+ -X \"$shortstat_id=$shortstat\"
+ -X \"$files_id=$files\"
+" -o "$output"