From f2c2ede2adc6451ec58891d32729e8b22840c649 Mon Sep 17 00:00:00 2001 From: crazywoola Date: Fri, 29 Nov 2024 13:53:51 +0800 Subject: [PATCH 1/4] feat: homebrew --- .gitignore | 3 ++- Makefile | 41 +++++++++++++++++++++++++++++++++++++++++ README.md | 9 +++++++++ dify.rb | 26 ++++++++++++++++++++++++++ docs/build_homebrew.md | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 README.md create mode 100644 dify.rb create mode 100644 docs/build_homebrew.md diff --git a/.gitignore b/.gitignore index 23ffb2e..843e259 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ __pycache__ media-cache subprocesses working -cwd/ \ No newline at end of file +cwd/ +bin/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2e46d32 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +# Makefile for building dify-plugin +OS := darwin +ARCHS := amd64 arm64 +BIN_DIR := bin +CMD_DIR := ./cmd/commandline +TAR_EXT := tar.gz + +.PHONY: build +build: + @for arch in $(ARCHS); do \ + GOOS=$(OS) GOARCH=$$arch go build -o $(BIN_DIR)/dify-plugin-$(OS)-$$arch $(CMD_DIR); \ + chmod +x $(BIN_DIR)/dify-plugin-$(OS)-$$arch; \ + done + +.PHONY: tarball +tarball: build + @for arch in $(ARCHS); do \ + tar -czvf $(BIN_DIR)/dify-plugin-$(OS)-$$arch.$(TAR_EXT) -C $(BIN_DIR) dify-plugin-$(OS)-$$arch; \ + done + +.PHONY: sha256 +sha256: tarball + @for arch in $(ARCHS); do \ + shasum -a 256 $(BIN_DIR)/dify-plugin-$(OS)-$$arch.$(TAR_EXT) | awk '{ print $$1 }' > $(BIN_DIR)/sha256_$(OS)_$$arch; \ + done + +.PHONY: update_formula +update_formula: sha256 + @for arch in $(ARCHS); do \ + sed -i.bak \ + -e "s/sha256 \"SHA256_$(OS)_$${arch^^}\"/sha256 \"$(shell cat $(BIN_DIR)/sha256_$(OS)_$$arch)\"/g" \ + dify.rb; \ + done + rm -f dify.rb.bak + +.PHONY: clean +clean: + rm -rf $(BIN_DIR)/* $(BIN_DIR)/sha256_* + +.PHONY: all +all: update_formula \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc905c4 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Dify Plugin Daemon + +## Description + +## Installation + +```bash +brew install --build-from-source ./dify.rb +``` \ No newline at end of file diff --git a/dify.rb b/dify.rb new file mode 100644 index 0000000..b220674 --- /dev/null +++ b/dify.rb @@ -0,0 +1,26 @@ +class Dify < Formula + desc "Dify Plugin Command Line Tool" + homepage "https://github.com/langgenius/dify-plugin-daemon" + version "0.1.0" + license "MIT" + + if OS.mac? && Hardware::CPU.intel? + url "file://#{__dir__}/bin/dify-plugin-darwin-amd64.tar.gz" + sha256 "3b0172bfdaf19396a855974b6f83e03a86ce2a073615cd7d6fbbb104c3d96946" + elsif OS.mac? && Hardware::CPU.arm? + url "file://#{__dir__}/bin/dify-plugin-darwin-arm64.tar.gz" + sha256 "8a527f7bc61046aa11992d76cc2e3fe2a2c38cf3434d882273fcba30dd3a2e00" + end + + def install + if Hardware::CPU.intel? + bin.install "dify-plugin-darwin-amd64" => "dify" + else + bin.install "dify-plugin-darwin-arm64" => "dify" + end + end + + test do + system "#{bin}/dify", "--version" + end +end \ No newline at end of file diff --git a/docs/build_homebrew.md b/docs/build_homebrew.md new file mode 100644 index 0000000..0468d71 --- /dev/null +++ b/docs/build_homebrew.md @@ -0,0 +1,32 @@ +# Build homebrew + +## Intallation + +### Install homebrew + +```bash +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + +brew version +``` + +### Build CLI tool + +```bash +# Build the CLI tool from source +make build +# Generate the sha256 checksum +make sha256 +# Update the formula with the new sha256 checksum +make update_formula +# Clean the build +make clean +# Execute all the above commands +make all +``` + +### Install CLI tool + +```bash +brew install --build-from-source ./dify.rb +``` \ No newline at end of file From 28880e1fb36b513ca196d5dc003f6fd3c1e646e4 Mon Sep 17 00:00:00 2001 From: crazywoola Date: Fri, 29 Nov 2024 13:58:31 +0800 Subject: [PATCH 2/4] fix: makefile --- Makefile | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 2e46d32..ca6868f 100644 --- a/Makefile +++ b/Makefile @@ -1,41 +1,31 @@ -# Makefile for building dify-plugin -OS := darwin -ARCHS := amd64 arm64 -BIN_DIR := bin -CMD_DIR := ./cmd/commandline -TAR_EXT := tar.gz - .PHONY: build build: - @for arch in $(ARCHS); do \ - GOOS=$(OS) GOARCH=$$arch go build -o $(BIN_DIR)/dify-plugin-$(OS)-$$arch $(CMD_DIR); \ - chmod +x $(BIN_DIR)/dify-plugin-$(OS)-$$arch; \ - done + GOOS=darwin GOARCH=amd64 go build -o bin/dify-plugin-darwin-amd64 ./cmd/commandline + GOOS=darwin GOARCH=arm64 go build -o bin/dify-plugin-darwin-arm64 ./cmd/commandline + chmod +x bin/dify-plugin-darwin-amd64 + chmod +x bin/dify-plugin-darwin-arm64 .PHONY: tarball tarball: build - @for arch in $(ARCHS); do \ - tar -czvf $(BIN_DIR)/dify-plugin-$(OS)-$$arch.$(TAR_EXT) -C $(BIN_DIR) dify-plugin-$(OS)-$$arch; \ - done + tar -czvf bin/dify-plugin-darwin-amd64.tar.gz -C bin dify-plugin-darwin-amd64 + tar -czvf bin/dify-plugin-darwin-arm64.tar.gz -C bin dify-plugin-darwin-arm64 .PHONY: sha256 sha256: tarball - @for arch in $(ARCHS); do \ - shasum -a 256 $(BIN_DIR)/dify-plugin-$(OS)-$$arch.$(TAR_EXT) | awk '{ print $$1 }' > $(BIN_DIR)/sha256_$(OS)_$$arch; \ - done + shasum -a 256 bin/dify-plugin-darwin-amd64.tar.gz | awk '{ print $$1 }' > bin/sha256_darwin_amd64 + shasum -a 256 bin/dify-plugin-darwin-arm64.tar.gz | awk '{ print $$1 }' > bin/sha256_darwin_arm64 .PHONY: update_formula update_formula: sha256 - @for arch in $(ARCHS); do \ - sed -i.bak \ - -e "s/sha256 \"SHA256_$(OS)_$${arch^^}\"/sha256 \"$(shell cat $(BIN_DIR)/sha256_$(OS)_$$arch)\"/g" \ - dify.rb; \ - done + sed -i.bak \ + -e "s/sha256 \"SHA256_DARWIN_AMD64\"/sha256 \"$(shell cat bin/sha256_darwin_amd64)\"/g" \ + -e "s/sha256 \"SHA256_DARWIN_ARM64\"/sha256 \"$(shell cat bin/sha256_darwin_arm64)\"/g" \ + dify.rb rm -f dify.rb.bak .PHONY: clean clean: - rm -rf $(BIN_DIR)/* $(BIN_DIR)/sha256_* + rm -rf bin/* bin/sha256_* .PHONY: all all: update_formula \ No newline at end of file From d2516794e78a303149cd51c9de6b22a0372c9297 Mon Sep 17 00:00:00 2001 From: crazywoola <427733928@qq.com> Date: Fri, 29 Nov 2024 14:19:30 +0800 Subject: [PATCH 3/4] feat: add linux & windows --- Makefile | 73 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index ca6868f..d895149 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,74 @@ +PLATFORMS = darwin linux windows +ARCHS = amd64 arm64 +BIN_DIR = bin +CMD_DIR = ./cmd/commandline + .PHONY: build build: - GOOS=darwin GOARCH=amd64 go build -o bin/dify-plugin-darwin-amd64 ./cmd/commandline - GOOS=darwin GOARCH=arm64 go build -o bin/dify-plugin-darwin-arm64 ./cmd/commandline - chmod +x bin/dify-plugin-darwin-amd64 - chmod +x bin/dify-plugin-darwin-arm64 + @mkdir -p $(BIN_DIR) + @for platform in $(PLATFORMS); do \ + for arch in $(ARCHS); do \ + if [ "$$platform" = "windows" ]; then \ + ext=".exe"; \ + else \ + ext=""; \ + fi; \ + bin_name=dify-plugin-$$platform-$$arch$$ext; \ + echo "Building $$bin_name"; \ + GOOS=$$platform GOARCH=$$arch go build -o $(BIN_DIR)/$$bin_name $(CMD_DIR); \ + if [ "$$platform" != "windows" ]; then chmod +x $(BIN_DIR)/$$bin_name; fi; \ + done; \ + done .PHONY: tarball tarball: build - tar -czvf bin/dify-plugin-darwin-amd64.tar.gz -C bin dify-plugin-darwin-amd64 - tar -czvf bin/dify-plugin-darwin-arm64.tar.gz -C bin dify-plugin-darwin-arm64 + @for platform in $(PLATFORMS); do \ + for arch in $(ARCHS); do \ + if [ "$$platform" = "windows" ]; then \ + ext=".exe"; \ + archive=$(BIN_DIR)/dify-plugin-$$platform-$$arch.zip; \ + echo "Creating $$archive"; \ + zip -j $$archive $(BIN_DIR)/dify-plugin-$$platform-$$arch$$ext; \ + else \ + ext=""; \ + archive=$(BIN_DIR)/dify-plugin-$$platform-$$arch.tar.gz; \ + echo "Creating $$archive"; \ + tar -czvf $$archive -C $(BIN_DIR) dify-plugin-$$platform-$$arch$$ext; \ + fi; \ + done; \ + done .PHONY: sha256 sha256: tarball - shasum -a 256 bin/dify-plugin-darwin-amd64.tar.gz | awk '{ print $$1 }' > bin/sha256_darwin_amd64 - shasum -a 256 bin/dify-plugin-darwin-arm64.tar.gz | awk '{ print $$1 }' > bin/sha256_darwin_arm64 + @for platform in $(PLATFORMS); do \ + for arch in $(ARCHS); do \ + if [ "$$platform" = "windows" ]; then \ + archive=$(BIN_DIR)/dify-plugin-$$platform-$$arch.zip; \ + else \ + archive=$(BIN_DIR)/dify-plugin-$$platform-$$arch.tar.gz; \ + fi; \ + hash_file=$(BIN_DIR)/sha256_$$platform\_$$arch; \ + echo "Computing SHA256 for $$archive"; \ + shasum -a 256 $$archive | awk '{ print $$1 }' > $$hash_file; \ + done; \ + done .PHONY: update_formula update_formula: sha256 - sed -i.bak \ - -e "s/sha256 \"SHA256_DARWIN_AMD64\"/sha256 \"$(shell cat bin/sha256_darwin_amd64)\"/g" \ - -e "s/sha256 \"SHA256_DARWIN_ARM64\"/sha256 \"$(shell cat bin/sha256_darwin_arm64)\"/g" \ - dify.rb - rm -f dify.rb.bak + @cp dify.rb dify.rb.bak + @for platform in $(PLATFORMS); do \ + for arch in $(ARCHS); do \ + placeholder="SHA256_$$(echo $$platform | tr a-z A-Z)_$$(echo $$arch | tr a-z A-Z)"; \ + hash=$$(cat $(BIN_DIR)/sha256_$$platform\_$$arch); \ + echo "Updating formula for $$placeholder"; \ + sed -i '' "s/sha256 \"$$placeholder\"/sha256 \"$$hash\"/" dify.rb; \ + done; \ + done + @rm -f dify.rb.bak .PHONY: clean clean: - rm -rf bin/* bin/sha256_* + rm -rf $(BIN_DIR)/* .PHONY: all -all: update_formula \ No newline at end of file +all: update_formula From 8f76287202721254d06b7b81b14ff7a2a114ff47 Mon Sep 17 00:00:00 2001 From: crazywoola <427733928@qq.com> Date: Fri, 29 Nov 2024 14:22:27 +0800 Subject: [PATCH 4/4] feat: add linux & windows --- docs/build_homebrew.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build_homebrew.md b/docs/build_homebrew.md index 0468d71..df329b5 100644 --- a/docs/build_homebrew.md +++ b/docs/build_homebrew.md @@ -7,7 +7,7 @@ ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -brew version +brew -v ``` ### Build CLI tool