Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
99 lines (82 loc) · 4 KB
/
Copy pathMakefile
File metadata and controls
99 lines (82 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# FlashDuty MCP Server Makefile
.DEFAULT_GOAL := help
PACKAGE = $(shell go list -m)
GIT_COMMIT_HASH = $(shell git rev-parse HEAD)
GIT_VERSION = $(shell git describe --tags --always --dirty)
BUILD_TIME = $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
BINARY_NAME = flashduty-mcp-server
LD_FLAGS = -s -w \
-X '$(PACKAGE)/pkg/core/version.Version=$(GIT_VERSION)' \
-X '$(PACKAGE)/pkg/core/version.GitCommit=$(GIT_COMMIT_HASH)' \
-X '$(PACKAGE)/pkg/core/version.BuildDate=$(BUILD_TIME)'
COMMON_BUILD_ARGS = -ldflags "$(LD_FLAGS)"
GOLANGCI_LINT = $(shell pwd)/_output/tools/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v2.2.2
# NPM version should not append the -dirty flag
NPM_VERSION ?= $(shell echo $(shell git describe --tags --always) | sed 's/^v//')
OSES = darwin linux windows
ARCHS = amd64 arm64
CLEAN_TARGETS :=
CLEAN_TARGETS += '$(BINARY_NAME)'
CLEAN_TARGETS += $(foreach os,$(OSES),$(foreach arch,$(ARCHS),$(BINARY_NAME)-$(os)-$(arch)$(if $(findstring windows,$(os)),.exe,)))
CLEAN_TARGETS += $(foreach os,$(OSES),$(foreach arch,$(ARCHS),./npm/$(BINARY_NAME)-$(os)-$(arch)/bin/))
CLEAN_TARGETS += ./npm/flashduty-mcp-server/.npmrc ./npm/flashduty-mcp-server/LICENSE ./npm/flashduty-mcp-server/README.md
CLEAN_TARGETS += $(foreach os,$(OSES),$(foreach arch,$(ARCHS),./npm/$(BINARY_NAME)-$(os)-$(arch)/.npmrc))
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9\/\.-]+:.*?##/ { printf " \033[36m%-21s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: clean
clean: ## Clean up all build artifacts
rm -rf $(CLEAN_TARGETS)
.PHONY: build
build: tidy ## Build the project
CGO_ENABLED=0 go build $(COMMON_BUILD_ARGS) -o $(BINARY_NAME) ./cmd/flashduty-mcp-server
.PHONY: build-all-platforms
build-all-platforms: tidy ## Build the project for all platforms
$(foreach os,$(OSES),$(foreach arch,$(ARCHS), \
GOOS=$(os) GOARCH=$(arch) go build $(COMMON_BUILD_ARGS) -o $(BINARY_NAME)-$(os)-$(arch)$(if $(findstring windows,$(os)),.exe,) ./cmd/flashduty-mcp-server; \
))
.PHONY: npm-copy-binaries
npm-copy-binaries: build-all-platforms ## Copy the binaries to each npm package
$(foreach os,$(OSES),$(foreach arch,$(ARCHS), \
EXECUTABLE=./$(BINARY_NAME)-$(os)-$(arch)$(if $(findstring windows,$(os)),.exe,); \
DIRNAME=$(BINARY_NAME)-$(os)-$(arch); \
mkdir -p ./npm/$$DIRNAME/bin; \
cp $$EXECUTABLE ./npm/$$DIRNAME/bin/; \
))
.PHONY: npm-publish
npm-publish: npm-copy-binaries ## Publish the npm packages
$(foreach os,$(OSES),$(foreach arch,$(ARCHS), \
DIRNAME="$(BINARY_NAME)-$(os)-$(arch)"; \
cd npm/$$DIRNAME; \
echo '//registry.npmjs.org/:_authToken=$(NPM_TOKEN)' >> .npmrc; \
jq '.version = "$(NPM_VERSION)"' package.json > tmp.json && mv tmp.json package.json; \
npm publish --access=public; \
cd ../..; \
))
cp README.md LICENSE ./npm/flashduty-mcp-server/
echo '//registry.npmjs.org/:_authToken=$(NPM_TOKEN)' >> ./npm/flashduty-mcp-server/.npmrc
jq '.version = "$(NPM_VERSION)"' ./npm/flashduty-mcp-server/package.json > tmp.json && mv tmp.json ./npm/flashduty-mcp-server/package.json; \
jq '.optionalDependencies |= with_entries(.value = "$(NPM_VERSION)")' ./npm/flashduty-mcp-server/package.json > tmp.json && mv tmp.json ./npm/flashduty-mcp-server/package.json; \
cd npm/flashduty-mcp-server && npm publish --access=public
.PHONY: test
test: ## Run the tests
go test -count=1 -v ./...
.PHONY: format
format: ## Format the code
go fmt ./...
.PHONY: tidy
tidy: ## Tidy up the go modules
go mod tidy
.PHONY: golangci-lint
golangci-lint: ## Download and install golangci-lint if not already installed
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\
}
.PHONY: lint
lint: golangci-lint ## Lint the code
$(GOLANGCI_LINT) run --verbose --print-resources-usage
.PHONY: version
version: ## Show version information
./$(BINARY_NAME) version