Skip to content

Commit a526058

Browse files
committed
feat(npm): npm packages
1 parent ea31c04 commit a526058

File tree

13 files changed

+193
-9
lines changed

13 files changed

+193
-9
lines changed

.github/workflows/release.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ concurrency:
1212

1313
env:
1414
GO_VERSION: 1.23
15+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1516

1617
permissions:
1718
contents: write
@@ -39,3 +40,6 @@ jobs:
3940
files: |
4041
LICENSE
4142
kubernetes-mcp-server-*
43+
- name: Publish npm
44+
run:
45+
make npm-publish

.gitignore

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
.idea/
22

3-
/kubernetes-mcp-server
4-
/kubernetes-mcp-server-darwin-amd64
5-
/kubernetes-mcp-server-darwin-arm64
6-
/kubernetes-mcp-server-linux-amd64
7-
/kubernetes-mcp-server-linux-arm64
8-
/kubernetes-mcp-server-windows-amd64.exe
9-
/kubernetes-mcp-server-windows-arm64.exe
3+
.npmrc
4+
kubernetes-mcp-server
5+
kubernetes-mcp-server-darwin-amd64
6+
!npm/kubernetes-mcp-server-darwin-amd64/
7+
kubernetes-mcp-server-darwin-arm64
8+
!npm/kubernetes-mcp-server-darwin-arm64
9+
kubernetes-mcp-server-linux-amd64
10+
!npm/kubernetes-mcp-server-linux-amd64
11+
kubernetes-mcp-server-linux-arm64
12+
!npm/kubernetes-mcp-server-linux-arm64
13+
kubernetes-mcp-server-windows-amd64.exe
14+
kubernetes-mcp-server-windows-arm64.exe

Makefile

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ LD_FLAGS = -s -w \
1919
-X '$(PACKAGE)/pkg/version.BinaryName=$(BINARY_NAME)'
2020
COMMON_BUILD_ARGS = -ldflags "$(LD_FLAGS)"
2121

22+
NPM_VERSION ?= $(shell echo $(GIT_VERSION) | sed 's/^v//')
2223
OSES = darwin linux windows
2324
ARCHS = amd64 arm64
2425

2526
CLEAN_TARGETS :=
2627
CLEAN_TARGETS += '$(BINARY_NAME)'
27-
CLEAN_TARGETS += $(foreach os,$(OSES),$(foreach arch,$(ARCHS),$(BINARY_NAME)-$(os)-$(arch)))
28+
CLEAN_TARGETS += $(foreach os,$(OSES),$(foreach arch,$(ARCHS),$(BINARY_NAME)-$(os)-$(arch)$(if $(findstring windows,$(os)),.exe,)))
29+
CLEAN_TARGETS += $(foreach os,$(OSES),$(foreach arch,$(ARCHS),./npm/$(BINARY_NAME)-$(os)-$(arch)/bin/))
30+
CLEAN_TARGETS += ./npm/.npmrc
31+
CLEAN_TARGETS += $(foreach os,$(OSES),$(foreach arch,$(ARCHS),./npm/$(BINARY_NAME)-$(os)-$(arch)/.npmrc))
2832

2933
# The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
3034
# The awk commands is responsible to read the entire set of makefiles included in this invocation, looking for lines of the file as xyz: ## something, and then pretty-format the target and help. Then, if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -53,6 +57,30 @@ build-all-platforms: clean tidy format ## Build the project for all platforms
5357
GOOS=$(os) GOARCH=$(arch) go build $(COMMON_BUILD_ARGS) -o $(BINARY_NAME)-$(os)-$(arch)$(if $(findstring windows,$(os)),.exe,) ./cmd/kubernetes-mcp-server; \
5458
))
5559

60+
.PHONY: npm
61+
npm: build-all-platforms ## Create the npm packages
62+
$(foreach os,$(OSES),$(foreach arch,$(ARCHS), \
63+
EXECUTABLE=./$(BINARY_NAME)-$(os)-$(arch)$(if $(findstring windows,$(os)),.exe,); \
64+
DIRNAME=$(BINARY_NAME)-$(os)-$(arch); \
65+
mkdir -p ./npm/$$DIRNAME/bin; \
66+
cp $$EXECUTABLE ./npm/$$DIRNAME/bin/; \
67+
))
68+
69+
.PHONY: npm-publish
70+
npm-publish: npm ## Publish the npm packages
71+
$(foreach os,$(OSES),$(foreach arch,$(ARCHS), \
72+
DIRNAME="$(BINARY_NAME)-$(os)-$(arch)"; \
73+
cd npm/$$DIRNAME; \
74+
echo '//registry.npmjs.org/:_authToken=\$(NPM_TOKEN)' >> .npmrc; \
75+
jq '.version = "$(NPM_VERSION)"' package.json > tmp.json && mv tmp.json package.json; \
76+
echo npm publish; \
77+
cd ../..; \
78+
))
79+
echo '//registry.npmjs.org/:_authToken=\$(NPM_TOKEN)' >> ./npm/.npmrc
80+
jq '.version = "$(NPM_VERSION)"' ./npm/package.json > tmp.json && mv tmp.json ./npm/package.json; \
81+
jq '.optionalDependencies |= with_entries(.value = "$(NPM_VERSION)")' ./npm/package.json > tmp.json && mv tmp.json ./npm/package.json; \
82+
cd npm && echo npm publish
83+
5684
.PHONY: test
5785
test: ## Run the tests
5886
go test -count=1 -v ./...

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/spf13/afero v1.12.0
88
github.com/spf13/cobra v1.8.1
99
github.com/spf13/viper v1.19.0
10+
golang.org/x/net v0.33.0
1011
k8s.io/api v0.32.1
1112
k8s.io/apimachinery v0.32.1
1213
k8s.io/cli-runtime v0.32.1
@@ -77,7 +78,6 @@ require (
7778
github.com/xlab/treeprint v1.2.0 // indirect
7879
go.uber.org/multierr v1.11.0 // indirect
7980
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
80-
golang.org/x/net v0.33.0 // indirect
8181
golang.org/x/oauth2 v0.25.0 // indirect
8282
golang.org/x/sync v0.10.0 // indirect
8383
golang.org/x/sys v0.29.0 // indirect

npm/bin/kubernetes-mcp-server.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const childProcess = require("child_process");
2+
3+
const BINARY_MAP = {
4+
darwin_x86: {name: "kubernetes-mcp-server-darwin-amd64", suffix: ''},
5+
darwin_arm64: {name: "kubernetes-mcp-server-darwin-arm64", suffix: ''},
6+
linux_x86: {name: "kubernetes-mcp-server-linux-amd64", suffix: ''},
7+
linux_arm64: {name: "kubernetes-mcp-server-linux-arm64", suffix: ''},
8+
win32_x86: {name: "kubernetes-mcp-server-windows-amd64", suffix: '.exe'},
9+
win32_arm64: {name: "kubernetes-mcp-server-windows-arm64", suffix: '.exe'},
10+
};
11+
12+
const binary = BINARY_MAP[`${process.platform}_${process.arch}`];
13+
14+
module.exports.runBinary = function (...args) {
15+
// Resolving will fail if the optionalDependency was not installed
16+
childProcess.execFileSync(require.resolve(`${binary.name}/bin/${binary.name}+${binary.suffix}`), args, {
17+
stdio: "inherit",
18+
});
19+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "kubernetes-mcp-server-darwin-amd64",
3+
"version": "0.0.0",
4+
"description": "Model Context Protocol (MCP) server for Kubernetes and OpenShift",
5+
"os": [
6+
"darwin"
7+
],
8+
"cpu": [
9+
"x64"
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "kubernetes-mcp-server-darwin-arm64",
3+
"version": "0.0.0",
4+
"description": "Model Context Protocol (MCP) server for Kubernetes and OpenShift",
5+
"os": [
6+
"darwin"
7+
],
8+
"cpu": [
9+
"arm64"
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "kubernetes-mcp-server-linux-amd64",
3+
"version": "0.0.0",
4+
"description": "Model Context Protocol (MCP) server for Kubernetes and OpenShift",
5+
"os": [
6+
"linux"
7+
],
8+
"cpu": [
9+
"x64"
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "kubernetes-mcp-server-linux-arm64",
3+
"version": "0.0.0",
4+
"description": "Model Context Protocol (MCP) server for Kubernetes and OpenShift",
5+
"os": [
6+
"linux"
7+
],
8+
"cpu": [
9+
"arm64"
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "kubernetes-mcp-server-windows-amd64",
3+
"version": "0.0.0",
4+
"description": "Model Context Protocol (MCP) server for Kubernetes and OpenShift",
5+
"os": [
6+
"win32"
7+
],
8+
"cpu": [
9+
"x64"
10+
]
11+
}

0 commit comments

Comments
 (0)