webhookd/Makefile

112 lines
2.6 KiB
Makefile
Raw Normal View History

2014-09-19 18:46:04 +00:00
.SILENT :
export GO111MODULE=on
# App name
APPNAME=webhookd
# Go configuration
2021-12-30 11:22:51 +00:00
GOOS?=$(shell go env GOHOSTOS)
GOARCH?=$(shell go env GOHOSTARCH)
# Add exe extension if windows target
is_windows:=$(filter windows,$(GOOS))
EXT:=$(if $(is_windows),".exe","")
2014-09-19 18:46:04 +00:00
# Archive name
ARCHIVE=$(APPNAME)-$(GOOS)-$(GOARCH).tgz
# Executable name
EXECUTABLE=$(APPNAME)$(EXT)
# Extract version infos
2020-03-15 20:45:27 +00:00
PKG_VERSION:=github.com/ncarlier/$(APPNAME)/pkg/version
VERSION:=`git describe --always --dirty`
GIT_COMMIT:=`git rev-list -1 HEAD --abbrev-commit`
BUILT:=`date`
define LDFLAGS
-X '$(PKG_VERSION).Version=$(VERSION)' \
-X '$(PKG_VERSION).GitCommit=$(GIT_COMMIT)' \
-X '$(PKG_VERSION).Built=$(BUILT)'
endef
2014-10-31 23:18:38 +00:00
all: build
2014-09-19 18:46:04 +00:00
# Include common Make tasks
root_dir:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
makefiles:=$(root_dir)/makefiles
include $(makefiles)/help.Makefile
2014-09-19 18:46:04 +00:00
## Clean built files
clean:
-rm -rf release
.PHONY: clean
2014-11-10 16:37:54 +00:00
## Build executable
2019-01-03 15:58:07 +00:00
build:
-mkdir -p release
2023-10-04 19:20:54 +00:00
echo ">>> Building: $(EXECUTABLE) $(VERSION) for $(GOOS)-$(GOARCH) ..."
2020-03-15 20:45:27 +00:00
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -o release/$(EXECUTABLE)
.PHONY: build
2014-11-10 16:37:54 +00:00
release/$(EXECUTABLE): build
2023-10-04 19:20:54 +00:00
# Check code style
check-style:
echo ">>> Checking code style..."
go vet ./...
go run honnef.co/go/tools/cmd/staticcheck@latest ./...
.PHONY: check-style
# Check code criticity
check-criticity:
echo ">>> Checking code criticity..."
go run github.com/go-critic/go-critic/cmd/gocritic@latest check -enableAll ./...
.PHONY: check-criticity
# Check code security
check-security:
echo ">>> Checking code security..."
go run github.com/securego/gosec/v2/cmd/gosec@latest -quiet ./...
.PHONY: check-security
## Code quality checks
checks: check-style check-criticity
.PHONY: checks
## Run tests
2023-10-04 19:20:54 +00:00
test:
2019-01-07 07:39:26 +00:00
go test ./...
.PHONY: test
## Install executable
install: release/$(EXECUTABLE)
echo "Installing $(EXECUTABLE) to ${HOME}/.local/bin/$(EXECUTABLE) ..."
cp release/$(EXECUTABLE) ${HOME}/.local/bin/$(EXECUTABLE)
.PHONY: install
## Create Docker image
image:
echo "Building Docker image ..."
docker build --rm --target slim -t ncarlier/$(APPNAME) .
.PHONY: image
2023-10-04 19:20:54 +00:00
# Generate changelog
CHANGELOG.md:
2018-02-12 20:18:33 +00:00
standard-changelog --first-release
## Create archive
2023-10-04 19:20:54 +00:00
archive: release/$(EXECUTABLE) CHANGELOG.md
echo "Creating release/$(ARCHIVE) archive..."
tar czf release/$(ARCHIVE) README.md LICENSE CHANGELOG.md -C release/ $(EXECUTABLE)
rm release/$(EXECUTABLE)
.PHONY: archive
2018-02-12 20:18:33 +00:00
## Create distribution binaries
distribution:
GOARCH=amd64 make build archive
GOARCH=arm64 make build archive
GOARCH=arm make build archive
GOOS=darwin make build archive
2018-02-12 20:18:33 +00:00
.PHONY: distribution