Skip to content

Instantly share code, notes, and snippets.

@kostaspt
Created May 18, 2024 11:36
Show Gist options
  • Save kostaspt/ba7ee77385d4dc457f4cafee373663d8 to your computer and use it in GitHub Desktop.
Save kostaspt/ba7ee77385d4dc457f4cafee373663d8 to your computer and use it in GitHub Desktop.
Makefile for Go
DIRECTORIES=go list -f '{{.Dir}}' ./... | grep -v /vendor/
PACKAGES=go list ./... | grep -v /vendor/
.PHONY: build
build: clean
mkdir -p bin/ && go build -o ./bin/ `$(call DIRECTORIES)`
.PHONY: clean
clean:
go clean
rm -rf ./bin
.PHONY: deps
deps:
go mod tidy
go mod verify
.PHONY: format
format:
gofmt -w `$(call DIRECTORIES)`
.PHONY: gitignore
gitignore:
@wget https://www.toptal.com/developers/gitignore/api/go,goland+all,visualstudiocode,dotenv -q -O .gitignore
echo "/bin" >> .gitignore
.PHONY: test
test:
go test -v -mod=vendor `$(call PACKAGES)`
.PHONY: test-ci
test-ci:
go test -v -race -mod=vendor `$(call PACKAGES)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment