Skip to content

Commit

Permalink
Merge pull request #2 from langgenius/feat/homebrew
Browse files Browse the repository at this point in the history
feat: homebrew
  • Loading branch information
Yeuoly authored Nov 29, 2024
2 parents 70d0860 + 8f76287 commit 2a66494
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ __pycache__
media-cache
subprocesses
working
cwd/
cwd/
bin/
74 changes: 74 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
PLATFORMS = darwin linux windows
ARCHS = amd64 arm64
BIN_DIR = bin
CMD_DIR = ./cmd/commandline

.PHONY: build
build:
@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
@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
@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
@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_DIR)/*

.PHONY: all
all: update_formula
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Dify Plugin Daemon

## Description

## Installation

```bash
brew install --build-from-source ./dify.rb
```
26 changes: 26 additions & 0 deletions dify.rb
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions docs/build_homebrew.md
Original file line number Diff line number Diff line change
@@ -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 -v
```

### 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
```

0 comments on commit 2a66494

Please sign in to comment.