datarhei-dragonfork-core/Makefile

103 lines
3 KiB
Makefile
Raw Normal View History

2022-05-13 13:26:45 -04:00
COMMIT := $(shell if [ -d .git ]; then git rev-parse HEAD; else echo "unknown"; fi)
SHORTCOMMIT := $(shell echo $(COMMIT) | head -c 7)
BRANCH := $(shell if [ -d .git ]; then git rev-parse --abbrev-ref HEAD; else echo "master"; fi)
BUILD := $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
2022-06-24 05:38:52 -04:00
BINSUFFIX := $(shell if [ "${GOOS}" -a "${GOARCH}" ]; then echo "-${GOOS}-${GOARCH}"; else echo ""; fi)
2022-05-13 13:26:45 -04:00
all: build
2022-09-09 09:10:29 -04:00
## init: Install required apps
init:
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/swaggo/swag/cmd/swag@latest
go install github.com/99designs/gqlgen@latest
2022-05-13 13:26:45 -04:00
## build: Build core (default)
build:
2022-06-24 05:38:52 -04:00
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o core${BINSUFFIX}
2022-05-13 13:26:45 -04:00
2022-07-21 14:55:31 -04:00
# github workflow workaround
build_linux:
CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o core
2022-05-13 13:26:45 -04:00
## swagger: Update swagger API documentation (requires github.com/swaggo/swag)
swagger:
swag init -g http/server.go
## gqlgen: Regenerate GraphQL server from schema
gqlgen:
go run github.com/99designs/gqlgen generate --config http/graph/gqlgen.yml
## test: Run all tests
test:
2022-06-24 05:38:52 -04:00
go test -race -coverprofile=/dev/null -v ./...
2022-05-13 13:26:45 -04:00
## vet: Analyze code for potential errors
vet:
go vet ./...
## fmt: Format code
fmt:
go fmt ./...
## update: Update dependencies
update:
go get -u
@-$(MAKE) tidy
2022-06-03 11:21:52 -04:00
@-$(MAKE) vendor
2022-05-13 13:26:45 -04:00
## tidy: Tidy up go.mod
tidy:
go mod tidy
## vendor: Update vendored packages
vendor:
go mod vendor
## run: Build and run core
run: build
./core
## lint: Static analysis with staticcheck
lint:
staticcheck ./...
## import: Build import binary
import:
2022-06-24 05:38:52 -04:00
cd app/import && CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o ../../import -ldflags="-s -w"
2022-05-13 13:26:45 -04:00
2022-07-21 14:55:31 -04:00
# github workflow workaround
import_linux:
cd app/import && CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o ../../import -ldflags="-s -w"
2022-05-13 13:26:45 -04:00
## coverage: Generate code coverage analysis
coverage:
2022-06-24 05:38:52 -04:00
go test -race -coverprofile test/cover.out ./...
2022-05-13 13:26:45 -04:00
go tool cover -html=test/cover.out -o test/cover.html
## commit: Prepare code for commit (vet, fmt, test)
commit: vet fmt lint test build
@echo "No errors found. Ready for a commit."
## release: Build a release binary of core
release:
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o core -ldflags="-s -w -X github.com/datarhei/core/v16/app.Commit=$(COMMIT) -X github.com/datarhei/core/v16/app.Branch=$(BRANCH) -X github.com/datarhei/core/v16/app.Build=$(BUILD)"
2022-05-13 13:26:45 -04:00
2022-07-21 14:55:31 -04:00
# github workflow workaround
release_linux:
CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o core -ldflags="-s -w -X github.com/datarhei/core/v16/app.Commit=$(COMMIT) -X github.com/datarhei/core/v16/app.Branch=$(BRANCH) -X github.com/datarhei/core/v16/app.Build=$(BUILD)"
2022-07-21 14:55:31 -04:00
2022-05-13 13:26:45 -04:00
## docker: Build standard Docker image
docker:
docker build -t core:$(SHORTCOMMIT) .
2022-09-09 09:10:29 -04:00
.PHONY: help init build swagger test vet fmt vendor commit coverage lint release import update
2022-05-13 13:26:45 -04:00
## help: Show all commands
help: Makefile
@echo
@echo " Choose a command:"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo