-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
67 lines (59 loc) · 2.01 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
64
65
66
67
.DEFAULT_GOAL := build
CMD := movearr
TARGET := $(shell go env GOOS)_$(shell go env GOARCH)
DIST_PATH := dist
BUILD_PATH := ${DIST_PATH}/${CMD}_${TARGET}
GO_FILES := $(shell find . -path ./vendor -prune -or -type f -name '*.go' -print)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
TIMESTAMP := $(shell date +%s)
VERSION ?= 0.0.0-dev
CGO := 1
# Deps
.PHONY: check_golangci
check_golangci:
@command -v golangci-lint >/dev/null || (echo "golangci-lint is required."; exit 1)
.PHONY: lint
lint: check_golangci ## Run linting
@echo "*** golangci-lint ***"
golangci-lint run
.PHONY: vendor
vendor: ## Vendor files and tidy go.mod
go mod vendor
go mod tidy
.PHONY: vendor_update
vendor_update: ## Update vendor dependencies
go get -u ./...
${MAKE} vendor
.PHONY: build
build: vendor ${BUILD_PATH}/${CMD} ## Build application
# Binary
${BUILD_PATH}/${CMD}: ${GO_FILES} go.sum
@echo "Building for ${TARGET}..." && \
mkdir -p ${BUILD_PATH} && \
CGO_ENABLED=${CGO} go build \
-mod vendor \
-trimpath \
-ldflags "-s -w -X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.Timestamp=${TIMESTAMP}" \
-o ${BUILD_PATH}/${CMD} \
./cmd/movearr
.PHONY: publish
publish: ## Generate a release, and publish
docker run --rm --privileged \
-e GITHUB_TOKEN="${TOKEN}" \
-e VERSION="${GIT_TAG_NAME}" \
-e GIT_COMMIT="${GIT_COMMIT}" \
-e TIMESTAMP="${TIMESTAMP}" \
-v `pwd`:/go/src/github.com/l3uddz/movearr \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/l3uddz/movearr \
neilotoole/xcgo:latest goreleaser --rm-dist
.PHONY: snapshot
snapshot: ## Generate a snapshot release
docker run --rm --privileged \
-e VERSION="${VERSION}" \
-e GIT_COMMIT="${GIT_COMMIT}" \
-e TIMESTAMP="${TIMESTAMP}" \
-v `pwd`:/go/src/github.com/l3uddz/movearr \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/l3uddz/movearr \
neilotoole/xcgo:latest goreleaser --snapshot --skip-validate --skip-publish --rm-dist