Skip to content

Commit 5368750

Browse files
Merge pull request #23 from nitishfy/makefile
chore: add the `Makefile` for mta
2 parents ba50da4 + 7ffc59e commit 5368750

File tree

5 files changed

+87
-2
lines changed

5 files changed

+87
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
22
.vscode
3+
dist/*

Makefile

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
CURRENT_DIR := $(shell pwd)
2+
DIST_DIR := $(CURRENT_DIR)/dist
3+
CLI_NAME := mta
4+
BIN_NAME := mta
5+
CGO_FLAG := 0
6+
7+
HOST_OS := $(shell go env GOOS)
8+
HOST_ARCH := $(shell go env GOARCH)
9+
10+
TARGET_ARCH ?= linux/amd64
11+
TARGET_OS := $(shell echo $(TARGET_ARCH) | cut -d'/' -f1)
12+
TARGET_ARCH_SHORT := $(shell echo $(TARGET_ARCH) | cut -d'/' -f2)
13+
14+
VERSION := $(shell cat ${CURRENT_DIR}/VERSION)
15+
16+
GOPATH ?= $(shell if test -x `which go`; then go env GOPATH; else echo "$(HOME)/go"; fi)
17+
GOCACHE ?= $(HOME)/.cache/go-build
18+
ARGOCD_LINT_GOGC ?= 20
19+
20+
default: build
21+
22+
$(DIST_DIR):
23+
mkdir -p $(DIST_DIR)
24+
25+
.PHONY: cli
26+
cli-local:
27+
GOOS=$(HOST_OS) GOARCH=$(HOST_ARCH) CGO_ENABLED=$(CGO_FLAG) go build -o $(DIST_DIR)/$(CLI_NAME) .
28+
29+
.PHONY: build
30+
build: $(DIST_DIR)
31+
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH_SHORT) CGO_ENABLED=$(CGO_FLAG) go build -o $(DIST_DIR)/$(CLI_NAME) .
32+
33+
.PHONY: run
34+
run:
35+
go run main.go
36+
37+
.PHONY: lint
38+
lint:
39+
golangci-lint --version
40+
# NOTE: If you get an "Out of Memory" error, try reducing GOGC value
41+
GOGC=$(ARGOCD_LINT_GOGC) GOMAXPROCS=2 golangci-lint run --fix --verbose
42+
43+
.PHONY: test
44+
test:
45+
go test -v ./...
46+
47+
.PHONY: fmt
48+
fmt:
49+
go fmt ./...
50+
51+
.PHONY: tidy
52+
tidy:
53+
go mod tidy
54+
55+
.PHONY: deps
56+
deps:
57+
go list -m -u all
58+
59+
.PHONY: clean
60+
clean:
61+
rm -rf $(DIST_DIR)
62+
63+
.PHONY: release
64+
release:
65+
@echo "Building release version $(VERSION)"
66+
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH_SHORT) CGO_ENABLED=$(CGO_FLAG) go build -o $(DIST_DIR)/$(CLI_NAME)-$(VERSION) .
67+
68+
.PHONY: help
69+
help:
70+
@echo "Usage: make [target]"
71+
@echo ""
72+
@echo "Targets:"
73+
@echo " build Compile the project"
74+
@echo " cli-local Build for local system"
75+
@echo " run Run the Go application"
76+
@echo " lint Run golangci-lint"
77+
@echo " test Run unit tests"
78+
@echo " fmt Format the code"
79+
@echo " tidy Clean up go.mod dependencies"
80+
@echo " deps Check for outdated dependencies"
81+
@echo " clean Remove build files"
82+
@echo " release Build a release version"
83+
@echo " help Show this help message"

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.9

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ require (
132132
github.com/kevinburke/ssh_config v1.2.0 // indirect
133133
github.com/klauspost/compress v1.15.11 // indirect
134134
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
135-
github.com/magiconair/properties v1.8.6 // indirect
135+
github.com/magiconair/properties v1.8.6
136136
github.com/mailru/easyjson v0.7.7 // indirect
137137
github.com/mattn/go-runewidth v0.0.14 // indirect
138138
github.com/mitchellh/go-wordwrap v1.0.1 // indirect

0 commit comments

Comments
 (0)