-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
50 lines (38 loc) · 1.95 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
BUILD_DIR = builds
BINARY_NAME = device-stalker
MODULE = github.com/soerenschneider/$(BINARY_NAME)
CHECKSUM_FILE = checksum.sha256
SIGNATURE_KEYFILE = ~/.signify/github.sec
DOCKER_PREFIX = ghcr.io/soerenschneider
tests:
go test ./... -race -covermode=atomic -coverprofile=coverage.out
go tool cover -html=coverage.out -o=coverage.html
go tool cover -func=coverage.out -o=coverage.out
clean:
git diff --quiet || { echo 'Dirty work tree' ; false; }
rm -rf ./$(BUILD_DIR)
build: version-info
CGO_ENABLED=0 go build -ldflags="-w -X '$(MODULE)/main.BuildVersion=${VERSION}' -X '$(MODULE)/main.CommitHash=${COMMIT_HASH}'" -o $(BINARY_NAME) ./cmd
release: clean version-info cross-build
cd $(BUILD_DIR) && sha256sum * > $(CHECKSUM_FILE) && cd -
signed-release: release
pass keys/signify/github | signify -S -s $(SIGNATURE_KEYFILE) -m $(BUILD_DIR)/$(CHECKSUM_FILE)
gh-upload-assets -o soerenschneider -r $(BINARY_NAME) -f ~/.gh-token builds
cross-build:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -X '$(MODULE)/main.BuildVersion=${VERSION}' -X '$(MODULE)/main.CommitHash=${COMMIT_HASH}'" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd
GOOS=linux GOARCH=arm GOARM=6 CGO_ENABLED=0 go build -ldflags="-w -X '$(MODULE)/main.BuildVersion=${VERSION}' -X '$(MODULE)/main.CommitHash=${COMMIT_HASH}'" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-armv6 ./cmd
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-w -X '$(MODULE)/main.BuildVersion=${VERSION}' -X '$(MODULE)/main.CommitHash=${COMMIT_HASH}'" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-aarch64 ./cmd
docker-build:
docker build -t "$(DOCKER_PREFIX)/$(BINARY_NAME)" .
version-info:
$(eval VERSION := $(shell git describe --tags --abbrev=0 || echo "dev"))
$(eval COMMIT_HASH := $(shell git rev-parse HEAD))
fmt:
find . -iname "*.go" -exec go fmt {} \;
lint:
golangci-lint run
pre-commit-init:
pre-commit install
pre-commit install --hook-type commit-msg
pre-commit-update:
pre-commit autoupdate