mirror of
https://github.com/appleboy/drone-discord.git
synced 2026-06-04 18:33:47 +08:00
9f96bb575e
- Remove `DIST` variable definition - Update the `GOFMT` definition by removing the `-s` flag - Install `gofumpt` latest version instead of an unspecified version Signed-off-by: appleboy <appleboy.tw@gmail.com>
87 lines
2.1 KiB
Makefile
87 lines
2.1 KiB
Makefile
EXECUTABLE := drone-discord
|
|
GOFMT ?= gofumpt -l -w
|
|
GO ?= go
|
|
GOFILES := $(shell find . -name "*.go" -type f)
|
|
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
|
|
|
ifneq ($(shell uname), Darwin)
|
|
EXTLDFLAGS = -extldflags "-static" $(null)
|
|
else
|
|
EXTLDFLAGS =
|
|
endif
|
|
|
|
ifeq ($(HAS_GO), GO)
|
|
GOPATH ?= $(shell $(GO) env GOPATH)
|
|
export PATH := $(GOPATH)/bin:$(PATH)
|
|
|
|
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
|
|
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
|
|
endif
|
|
|
|
ifeq ($(OS), Windows_NT)
|
|
GOFLAGS := -v -buildmode=exe
|
|
EXECUTABLE ?= $(EXECUTABLE).exe
|
|
else ifeq ($(OS), Windows)
|
|
GOFLAGS := -v -buildmode=exe
|
|
EXECUTABLE ?= $(EXECUTABLE).exe
|
|
else
|
|
GOFLAGS := -v
|
|
EXECUTABLE ?= $(EXECUTABLE)
|
|
endif
|
|
|
|
ifneq ($(DRONE_TAG),)
|
|
VERSION ?= $(DRONE_TAG)
|
|
else
|
|
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
|
endif
|
|
|
|
TAGS ?=
|
|
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
|
|
|
all: build
|
|
|
|
fmt:
|
|
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
$(GO) install mvdan.cc/gofumpt@latest; \
|
|
fi
|
|
$(GOFMT) -w $(GOFILES)
|
|
|
|
vet:
|
|
$(GO) vet ./...
|
|
|
|
.PHONY: fmt-check
|
|
fmt-check:
|
|
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
$(GO) install mvdan.cc/gofumpt; \
|
|
fi
|
|
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
|
if [ -n "$$diff" ]; then \
|
|
echo "Please run 'make fmt' and commit the result:"; \
|
|
echo "$${diff}"; \
|
|
exit 1; \
|
|
fi;
|
|
|
|
test:
|
|
@$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
|
|
|
install: $(GOFILES)
|
|
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
|
|
|
build: $(EXECUTABLE)
|
|
|
|
$(EXECUTABLE): $(GOFILES)
|
|
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
|
|
|
|
build_linux_amd64:
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
|
|
|
build_linux_arm64:
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE)
|
|
|
|
clean:
|
|
$(GO) clean -x -i ./...
|
|
rm -rf coverage.txt $(EXECUTABLE)
|
|
|
|
version:
|
|
@echo $(VERSION)
|