super-graph/Makefile

108 lines
3.2 KiB
Makefile
Raw Permalink Normal View History

BUILD ?= $(shell git rev-parse --short HEAD)
BUILD_DATE ?= $(shell git log -1 --format=%ci)
BUILD_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILD_VERSION ?= $(shell git describe --always --tags)
GOPATH ?= $(shell go env GOPATH)
ifndef GOPATH
override GOPATH = $(HOME)/go
endif
export GO111MODULE := on
# Build-time Go variables
2020-04-16 06:26:32 +02:00
version = github.com/dosco/super-graph/internal/serv.version
gitBranch = github.com/dosco/super-graph/internal/serv.gitBranch
lastCommitSHA = github.com/dosco/super-graph/internal/serv.lastCommitSHA
lastCommitTime = github.com/dosco/super-graph/internal/serv.lastCommitTime
BUILD_FLAGS ?= -ldflags '-s -w -X ${lastCommitSHA}=${BUILD} -X "${lastCommitTime}=${BUILD_DATE}" -X "${version}=${BUILD_VERSION}" -X ${gitBranch}=${BUILD_BRANCH}'
2019-11-28 21:27:20 +01:00
.PHONY: all build gen clean test run lint changlog release version help $(PLATFORMS)
test:
@go test -v -short -race ./...
BIN_DIR := $(GOPATH)/bin
2020-01-11 23:15:39 +01:00
GORICE := $(BIN_DIR)/rice
GOLANGCILINT := $(BIN_DIR)/golangci-lint
2019-11-28 21:27:20 +01:00
GITCHGLOG := $(BIN_DIR)/git-chglog
2020-04-16 06:26:32 +02:00
WEB_BUILD_DIR := ./internal/serv/web/build/manifest.json
2019-11-28 21:27:20 +01:00
$(GORICE):
@GO111MODULE=off go get -u github.com/GeertJohan/go.rice/rice
2020-01-11 23:15:39 +01:00
$(WEB_BUILD_DIR):
@echo "First install Yarn and create a build of the web UI then re-run make install"
2020-04-16 06:26:32 +02:00
@echo "Run this command: yarn --cwd internal/serv/web/ build"
2020-01-11 23:15:39 +01:00
@exit 1
2019-11-28 21:27:20 +01:00
$(GITCHGLOG):
2020-05-04 03:01:16 +02:00
@GO111MODULE=off go get -u github.com/git-chglog/git-chglog/cmd/git-chglog
2019-11-28 21:27:20 +01:00
changelog: $(GITCHGLOG)
@git-chglog $(ARGS)
$(GOLANGCILINT):
@GO111MODULE=off curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.25.1
lint: $(GOLANGCILINT)
@golangci-lint run ./... --skip-dirs-use-default
BINARY := super-graph
LDFLAGS := -s -w
PLATFORMS := windows linux darwin
os = $(word 1, $@)
2020-01-11 23:15:39 +01:00
$(PLATFORMS): lint test
@mkdir -p release
2020-04-16 06:26:32 +02:00
@GOOS=$(os) GOARCH=amd64 go build $(BUILD_FLAGS) -o release/$(BINARY)-$(BUILD_VERSION)-$(os)-amd64 main.go
release: windows linux darwin
all: lint test $(BINARY)
build: $(BINARY)
2020-01-11 23:15:39 +01:00
gen: $(GORICE) $(WEB_BUILD_DIR)
@go generate ./...
2020-01-11 23:15:39 +01:00
$(BINARY): clean
2020-04-16 06:26:32 +02:00
@go build $(BUILD_FLAGS) -o $(BINARY) main.go
clean:
@rm -f $(BINARY)
run: clean
@go run $(BUILD_FLAGS) main.go $(ARGS)
2020-04-13 06:50:54 +02:00
install: clean build
@echo "Commit Hash: `git rev-parse HEAD`"
@echo "Old Hash: `shasum $(GOPATH)/bin/$(BINARY) 2>/dev/null | cut -c -32`"
2020-04-13 06:50:54 +02:00
@mv $(BINARY) $(GOPATH)/bin/$(BINARY)
@echo "New Hash:" `shasum $(GOPATH)/bin/$(BINARY) 2>/dev/null | cut -c -32`
uninstall: clean
@go clean -i -x
version:
@echo Super Graph ${BUILD_VERSION}
@echo Build: ${BUILD}
@echo Build date: ${BUILD_DATE}
@echo Branch: ${BUILD_BRANCH}
@echo Go version: $(shell go version)
help:
@echo
@echo Build commands:
@echo " make build - Build supergraph binary"
@echo " make install - Install supergraph binary"
@echo " make uninstall - Uninstall supergraph binary"
@echo " make [platform] - Build for platform [linux|darwin|windows]"
@echo " make release - Build all platforms"
2019-11-28 21:27:20 +01:00
@echo " make run - Run supergraph (eg. make run ARGS=\"help\")"
@echo " make test - Run all tests"
@echo " make changelog - Generate changelog (eg. make changelog ARGS=\"help\")"
@echo " make help - This help"
@echo