/
Makefile
63 lines (48 loc) · 1.88 KB
/
Makefile
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
# Borrowed from:
# https://github.com/silven/go-example/blob/master/Makefile
# https://vic.demuzere.be/articles/golang-makefile-crosscompile/
BINARY = biblescholar
VET_REPORT = vet.report
TEST_REPORT = tests.xml
GOARCH = amd64
COMMIT=$(shell git rev-parse HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
GITHUB_USERNAME=turtlemonvh
# Core path variables
BINARY_BUILD_DIR=./command
ARTIFACT_DIR=./artifacts
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS = -ldflags "-X main.buildCommit=${COMMIT} -X main.buildBranch=${BRANCH}"
# Build the project
all: clean test vet linux darwin windows elbzip
artifactdir:
mkdir -p ${ARTIFACT_DIR}
linux: artifactdir
GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-linux-${GOARCH} ./command
mv ${BINARY}-linux-${GOARCH} ${ARTIFACT_DIR}/
darwin: artifactdir
GOOS=darwin GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-darwin-${GOARCH} ./command
mv ${BINARY}-darwin-${GOARCH} ${ARTIFACT_DIR}/
windows: artifactdir
GOOS=windows GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-windows-${GOARCH}.exe ./command
mv ${BINARY}-windows-${GOARCH}.exe ${ARTIFACT_DIR}/
elbzip: linux
# Make elasticbeanstalk artifact
# https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html
rm -f ${ARTIFACT_DIR}/elb.zip
cp ${ARTIFACT_DIR}/${BINARY}-linux-${GOARCH} .
zip -r ${ARTIFACT_DIR}/elb.zip ${BINARY}-linux-${GOARCH} verses.bleve Dockerfile
# Check contents
unzip -l ${ARTIFACT_DIR}/elb.zip
test: artifactdir
if ! hash go2xunit 2>/dev/null; then go install github.com/tebeka/go2xunit; fi
go test -v ./... 2>&1 | go2xunit -output ${TEST_REPORT}
mv ${TEST_REPORT} ${ARTIFACT_DIR}/
vet: artifactdir
go vet ./... > ${VET_REPORT} 2>&1
mv ${VET_REPORT} ${ARTIFACT_DIR}/
fmt:
go fmt $$(go list ./...)
clean:
-rm -rf ${ARTIFACT_DIR}
.PHONY: linux darwin windows test vet fmt clean elbzip