100 lines
2.7 KiB
Makefile
100 lines
2.7 KiB
Makefile
# Ignore built-in rules, these do not apply for Go builds
|
|
MAKEFLAGS += --no-builtin-rules
|
|
|
|
# Ignore the default suffixes, in this automation script all names refer to actual tasks and files
|
|
.SUFFIXES:
|
|
|
|
.PHONY: all
|
|
all: check test build
|
|
|
|
###
|
|
### Pick the right Go SDK if several are available
|
|
###
|
|
|
|
GO_SDK_VERSION ?= $(shell \awk '/^golang [0-9]/ { print $$2 }' .tool-versions)
|
|
ifneq (,$(shell command -v go$(GO_SDK_VERSION)))
|
|
# Use the selected SDK
|
|
GOVERSION ?= go$(GO_SDK_VERSION)
|
|
else
|
|
# No SDK in the PATH, fall back on whatever version is available
|
|
GOVERSION := go
|
|
endif
|
|
|
|
ifeq ($(OS),Darwin)
|
|
# Use the selected SDK
|
|
LINTOS ?= darwin
|
|
else
|
|
# No SDK in the PATH, fall back on whatever version is available
|
|
LINTOS := linux
|
|
endif
|
|
|
|
ifeq ($(shell uname -p),aarch64)
|
|
COERCED_ARCH = arm64
|
|
else
|
|
COERCED_ARCH = amd64
|
|
endif
|
|
|
|
export BUILD_DATE ?= $(shell \date -u '+%FT%TZ')
|
|
export GIT_COMMIT ?= $(shell git describe --match=NeVeRmAtCh --always --abbrev=7 --dirty='*')
|
|
export APP_MAJOR_MINOR_VERSION ?= $(shell \grep -m1 -o -E '^[0-9]+\.[0-9]+' VERSION)
|
|
export APP_PATCH_VERSION ?= dev
|
|
export APP_VERSION ?= $(APP_MAJOR_MINOR_VERSION).$(APP_PATCH_VERSION)
|
|
|
|
CONFIG_PACKAGE := clintonambulance.com/calculate_negative_points/internal/config
|
|
LDFLAGS_VERSION := -X $(CONFIG_PACKAGE).release=$(APP_VERSION) -X $(CONFIG_PACKAGE).date=$(BUILD_DATE) -X $(CONFIG_PACKAGE).commit=$(GIT_COMMIT)
|
|
LDFLAGS := -ldflags "$(LDFLAGS_VERSION) $(LDFLAGS_EXTRA)"
|
|
|
|
###
|
|
### Output directory
|
|
###
|
|
|
|
BINDIR ?= $(shell pwd)/bin
|
|
$(BINDIR):
|
|
install -d $(BINDIR)
|
|
|
|
.PHONY: mod
|
|
mod:
|
|
@printf "\nRunning go mod...\n"
|
|
$(GOVERSION) mod verify
|
|
$(GOVERSION) mod download
|
|
@printf "Complete.\n"
|
|
|
|
.PHONY: check
|
|
check: GOFMTCHECK := $(shell gofmt -s -d .)
|
|
check:
|
|
@printf "\nRunning checks...\n"
|
|
@echo - gofmt
|
|
@[[ "$(GOFMTCHECK)" == "" ]] || (echo "FAILED: gofmt failed" ; exit 1)
|
|
@echo - golangci-lint
|
|
@golangci-lint run
|
|
@printf "All checks PASSED.\n"
|
|
|
|
.PHONY: test
|
|
test:
|
|
@printf "\nRunning tests...\n"
|
|
ginkgo -r
|
|
@printf "Tests PASSED.\n"
|
|
|
|
test-until-fail:
|
|
@printf "\nRunning tests until something fails...\n"
|
|
ginkgo -r --until-it-fails
|
|
|
|
.PHONY: clean
|
|
clean: $(BINDIR)
|
|
@printf "\nCleaning output files...\n"
|
|
rm -f $(BINDIR)/calculate_negative_points $(BINDIR)/sync_from_samsara
|
|
|
|
.PHONY: buildbins
|
|
buildbins: $(BINDIR)
|
|
@printf "\nRunning build...\n"
|
|
$(GOVERSION) build $(LDFLAGS) -trimpath -o $(BINDIR)/calculate_negative_points
|
|
@printf "Build complete.\n"
|
|
|
|
.PHONY: build
|
|
build: clean buildbins
|
|
|
|
docs/openapi/api.yaml: $(shell find . -name '*.go')
|
|
@printf "\nBuilding OpenAPI document...\n"
|
|
$(GOVERSION) run $(LDFLAGS) cmd/generate-api-docs/main.go -e testEnvironment -c internal/config/testdata/settings.test.yml
|
|
@printf "\nGenerating API types...\n"
|
|
cd frontend && bun run generate-api-types
|