Makefile 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. .SILENT :
  2. # App name
  3. APPNAME=webhookd
  4. # Go configuration
  5. GOOS?=$(shell go env GOHOSTOS)
  6. GOARCH?=$(shell go env GOHOSTARCH)
  7. # Add exe extension if windows target
  8. is_windows:=$(filter windows,$(GOOS))
  9. EXT:=$(if $(is_windows),".exe","")
  10. # Archive name
  11. ARCHIVE=$(APPNAME)-$(GOOS)-$(GOARCH).tgz
  12. # Executable name
  13. EXECUTABLE=$(APPNAME)$(EXT)
  14. # Extract version infos
  15. PKG_VERSION:=github.com/ncarlier/$(APPNAME)/pkg/version
  16. VERSION:=`git describe --always --tags --dirty`
  17. GIT_COMMIT:=`git rev-list -1 HEAD --abbrev-commit`
  18. BUILT:=`date`
  19. define LDFLAGS
  20. -X '$(PKG_VERSION).Version=$(VERSION)' \
  21. -X '$(PKG_VERSION).GitCommit=$(GIT_COMMIT)' \
  22. -X '$(PKG_VERSION).Built=$(BUILT)' \
  23. -s -w -buildid=
  24. endef
  25. all: build
  26. # Include common Make tasks
  27. root_dir:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
  28. makefiles:=$(root_dir)/makefiles
  29. include $(makefiles)/help.Makefile
  30. ## Clean built files
  31. clean:
  32. -rm -rf release
  33. .PHONY: clean
  34. ## Build executable
  35. build:
  36. -mkdir -p release
  37. echo ">>> Building: $(EXECUTABLE) $(VERSION) for $(GOOS)-$(GOARCH) ..."
  38. GOOS=$(GOOS) GOARCH=$(GOARCH) go build -tags osusergo,netgo -ldflags "$(LDFLAGS)" -o release/$(EXECUTABLE)
  39. .PHONY: build
  40. release/$(EXECUTABLE): build
  41. # Check code style
  42. check-style:
  43. echo ">>> Checking code style..."
  44. go vet ./...
  45. go run honnef.co/go/tools/cmd/staticcheck@latest ./...
  46. .PHONY: check-style
  47. # Check code criticity
  48. check-criticity:
  49. echo ">>> Checking code criticity..."
  50. go run github.com/go-critic/go-critic/cmd/gocritic@latest check -enableAll ./...
  51. .PHONY: check-criticity
  52. # Check code security
  53. check-security:
  54. echo ">>> Checking code security..."
  55. go run github.com/securego/gosec/v2/cmd/gosec@latest -quiet ./...
  56. .PHONY: check-security
  57. ## Code quality checks
  58. checks: check-style check-criticity
  59. .PHONY: checks
  60. ## Run tests
  61. test:
  62. go test ./...
  63. .PHONY: test
  64. ## Install executable
  65. install: release/$(EXECUTABLE)
  66. echo "Installing $(EXECUTABLE) to ${HOME}/.local/bin/$(EXECUTABLE) ..."
  67. cp release/$(EXECUTABLE) ${HOME}/.local/bin/$(EXECUTABLE)
  68. .PHONY: install
  69. ## Create Docker image
  70. image:
  71. echo "Building Docker image ..."
  72. docker build --rm --target slim -t ncarlier/$(APPNAME) .
  73. .PHONY: image
  74. # Generate changelog
  75. CHANGELOG.md:
  76. standard-changelog --first-release
  77. ## Create archive
  78. archive: release/$(EXECUTABLE) CHANGELOG.md
  79. echo "Creating release/$(ARCHIVE) archive..."
  80. tar czf release/$(ARCHIVE) README.md LICENSE CHANGELOG.md -C release/ $(EXECUTABLE)
  81. rm release/$(EXECUTABLE)
  82. .PHONY: archive
  83. ## Create distribution binaries
  84. distribution:
  85. GOARCH=amd64 make build archive
  86. GOARCH=arm64 make build archive
  87. GOARCH=arm make build archive
  88. GOOS=darwin make build archive
  89. .PHONY: distribution