-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
129 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
dist/ | ||
build/ | ||
cover.out | ||
coverage.out | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,32 @@ | ||
# Default variable | ||
APP_NAME ?= go-web-prototype | ||
GOFORMATER ?= gofumpt | ||
GOFORMATER_VERSION ?= v0.2.0 | ||
GOLINTER ?= golangci-lint | ||
GOLINTER_VERSION ?= v1.41.0 | ||
COVER_FILE ?= cover.out | ||
SOURCE_PATHS ?= ./cmd/... | ||
GOSOURCE_PATHS ?= ./cmd/... | ||
|
||
.DEFAULT_GOAL := help | ||
include go.makefile | ||
|
||
help: ## This help message :) | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
# If you encounter an error like "panic: permission denied" on MacOS, | ||
# please visit https://github.com/eisenxp/macos-golink-wrapper to find the solution. | ||
test: ## Run the tests | ||
go test -gcflags=all=-l -timeout=10m `go list $(SOURCE_PATHS)` ${TEST_FLAGS} | ||
|
||
cover: ## Generates coverage report | ||
go test -gcflags=all=-l -timeout=10m `go list $(SOURCE_PATHS)` -coverprofile $(COVER_FILE) ${TEST_FLAGS} | ||
|
||
cover-html: ## Generates coverage report and displays it in the browser | ||
go tool cover -html=$(COVER_FILE) | ||
|
||
format: ## Format source code | ||
@which $(GOFORMATER) > /dev/null || (echo "Installing $(GOFORMATER)@$(GOFORMATER_VERSION) ..."; go install mvdan.cc/gofumpt@$(GOFORMATER_VERSION) && echo -e "Installation complete!\n") | ||
@for path in $(SOURCE_PATHS); do ${GOFORMATER} -l -w -e `echo $${path} | cut -b 3- | rev | cut -b 5- | rev`; done; | ||
|
||
lint: ## Lint, will not fix but sets exit code on error | ||
@which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") | ||
$(GOLINTER) run --deadline=10m $(SOURCE_PATHS) | ||
|
||
lint-fix: ## Lint, will try to fix errors and modify code | ||
@which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") | ||
$(GOLINTER) run --deadline=10m $(SOURCE_PATHS) --fix | ||
|
||
doc: ## Start the documentation server with godoc | ||
@which godoc > /dev/null || (echo "Installing godoc@latest ..."; go install golang.org/x/tools/cmd/godoc@latest && echo -e "Installation complete!\n") | ||
godoc -http=:6060 | ||
|
||
build-changelog: ## Build the changelog with git-chglog | ||
@which git-chglog > /dev/null || (echo "Installing git-chglog@v0.15.1 ..."; go install github.com/git-chglog/git-chglog/cmd/git-chglog@v0.15.1 && echo -e "Installation complete!\n") | ||
mkdir -p ./build | ||
git-chglog -o ./build/CHANGELOG.md | ||
|
||
.PHONY: clean | ||
clean: ## Clean build bundles | ||
-rm -rf ./build | ||
|
||
gen-version: ## Update version | ||
cd pkg/version/scripts && go run gen.go | ||
.PHONY: build-all | ||
build-all: build-darwin build-linux build-windows ## Build for all platforms | ||
|
||
build-all: build-darwin build-linux build-windows ## Build all platforms | ||
|
||
build-darwin: gen-version ## Build for MacOS | ||
-rm -rf ./build/darwin/bin | ||
# Build kusion | ||
.PHONY: build-darwin | ||
build-darwin: ## Build for MacOS | ||
-rm -rf ./build/darwin | ||
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 \ | ||
go build -o ./build/darwin/bin/$(APP_NAME) \ | ||
go build -o ./build/darwin/$(APPROOT) \ | ||
./cmd/main.go | ||
|
||
build-linux: gen-version ## Build for Linux | ||
-rm -rf ./build/linux/bin | ||
# Build kusion | ||
.PHONY: build-linux | ||
build-linux: ## Build for Linux | ||
-rm -rf ./build/linux | ||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \ | ||
go build -o ./build/linux/bin/$(APP_NAME) \ | ||
go build -o ./build/linux/$(APPROOT) \ | ||
./cmd/main.go | ||
|
||
build-windows: gen-version ## Build for Windows | ||
-rm -rf ./build/windows/bin | ||
# Build kusion | ||
.PHONY: build-windows | ||
build-windows: ## Build for Windows | ||
-rm -rf ./build/windows | ||
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 \ | ||
go build -o ./build/windows/bin/$(APP_NAME).exe \ | ||
go build -o ./build/windows/$(APPROOT).exe \ | ||
./cmd/main.go | ||
|
||
.PHONY: test cover cover-html format lint lint-fix doc build-changelog clean gen-version build-all build-darwin build-linux build-windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
APPROOT ?= $(shell basename $(PWD)) | ||
GOPKG ?= $(shell go list 2>/dev/null) | ||
GOPKGS ?= $(shell go list ./... 2>/dev/null) | ||
GOSOURCES ?= $(shell find . -type f -name '*.go' ! -path '*Godeps/_workspace*') | ||
# You can also customize GOSOURCE_PATHS, e.g. ./pkg/... ./cmd/... | ||
GOSOURCE_PATHS ?= ././... | ||
COVERAGEOUT ?= coverage.out | ||
COVERAGETMP ?= coverage.tmp | ||
|
||
|
||
# Go tools | ||
GOFORMATER ?= gofumpt | ||
GOFORMATER_VERSION ?= v0.2.0 | ||
GOLINTER ?= golangci-lint | ||
GOLINTER_VERSION ?= v1.41.0 | ||
|
||
|
||
# To generate help information | ||
.DEFAULT_GOAL := help | ||
.PHONY: help | ||
help: ## This help message :) | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' go.makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
|
||
# If you encounter an error like "panic: permission denied" on MacOS, | ||
# please visit https://github.com/eisenxp/macos-golink-wrapper to find the solution. | ||
.PHONY: test | ||
test: ## Run the tests | ||
go test -gcflags=all=-l -timeout=10m `go list $(GOSOURCE_PATHS)` ${TEST_FLAGS} | ||
|
||
.PHONY: cover | ||
cover: ## Generates coverage report | ||
go test -gcflags=all=-l -timeout=10m `go list $(GOSOURCE_PATHS)` -coverprofile $(COVERAGEOUT) ${TEST_FLAGS} | ||
|
||
.PHONY: cover-html | ||
cover-html: ## Generates coverage report and displays it in the browser | ||
go tool cover -html=$(COVERAGEOUT) | ||
|
||
.PHONY: format | ||
format: ## Format source code | ||
@which $(GOFORMATER) > /dev/null || (echo "Installing $(GOFORMATER)@$(GOFORMATER_VERSION) ..."; go install mvdan.cc/gofumpt@$(GOFORMATER_VERSION) && echo -e "Installation complete!\n") | ||
@for path in $(GOSOURCE_PATHS); do ${GOFORMATER} -l -w -e `echo $${path} | cut -b 3- | rev | cut -b 5- | rev`; done; | ||
|
||
.PHONY: lint | ||
lint: ## Lint, will not fix but sets exit code on error | ||
@which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") | ||
$(GOLINTER) run --deadline=10m $(GOSOURCE_PATHS) | ||
|
||
.PHONY: lint-fix | ||
lint-fix: ## Lint, will try to fix errors and modify code | ||
@which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n") | ||
$(GOLINTER) run --deadline=10m $(GOSOURCE_PATHS) --fix | ||
|
||
.PHONY: doc | ||
doc: ## Start the documentation server with godoc | ||
@which godoc > /dev/null || (echo "Installing godoc@latest ..."; go install golang.org/x/tools/cmd/godoc@latest && echo -e "Installation complete!\n") | ||
godoc -http=:6060 |