aboutsummaryrefslogtreecommitdiff
path: root/build.bash
blob: b7c97d1ecddd59f5cb3b3302b55b996591694ecd (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
#!/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"