Parcourir la source

Merge pull request #3 from langgenius/fix/homebrew

Fix/homebrew
crazywoola il y a 8 mois
Parent
commit
1173628ad3
3 fichiers modifiés avec 51 ajouts et 28 suppressions
  1. 12 15
      Makefile
  2. 13 13
      dify.rb
  3. 26 0
      dify.rb.template

+ 12 - 15
Makefile

@@ -50,25 +50,22 @@ sha256: tarball
 			hash_file=$(BIN_DIR)/sha256_$$platform\_$$arch; \
 			echo "Computing SHA256 for $$archive"; \
 			shasum -a 256 $$archive | awk '{ print $$1 }' > $$hash_file; \
+			echo "SHA256: $$(cat $$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: update-brewfile
+update-brewfile: sha256
+	@echo "Updating dify.rb"
+	@amd64_checksum=$$(cat $(BIN_DIR)/sha256_darwin_amd64); \
+	arm64_checksum=$$(cat $(BIN_DIR)/sha256_darwin_arm64); \
+	sed -e "s/PLACEHOLDER_FOR_AMD64_CHECKSUM/$$amd64_checksum/" \
+		-e "s/PLACEHOLDER_FOR_ARM64_CHECKSUM/$$arm64_checksum/" \
+		dify.rb.template > dify.rb
 
 .PHONY: clean
 clean:
+	brew cleanup --prune=all
 	rm -rf $(BIN_DIR)/*
-
+	
 .PHONY: all
-all: update_formula
+all: clean update-brewfile

+ 13 - 13
dify.rb

@@ -4,23 +4,23 @@ class Dify < Formula
   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 OS.mac?
     if Hardware::CPU.intel?
-      bin.install "dify-plugin-darwin-amd64" => "dify"
+      url "file://#{__dir__}/bin/dify-plugin-darwin-amd64.tar.gz"
+      sha256 "39ab1029634acf1caa8e68efcc393162a0fc760170472071b5fc02d06b084993"
     else
-      bin.install "dify-plugin-darwin-arm64" => "dify"
+      url "file://#{__dir__}/bin/dify-plugin-darwin-arm64.tar.gz"
+      sha256 "467cd4d13a7be4d1583589da4cf6b39e3b72b2fe4a02b6bc59c2c36309459a4b"
     end
+  else
+    odie "This formula only supports macOS."
+  end
+
+  def install
+    bin.install "dify-plugin-darwin-#{Hardware::CPU.arch}" => "dify"
   end
 
   test do
-    system "#{bin}/dify", "--version"
+    assert_match version.to_s, shell_output("#{bin}/dify --version")
   end
-end
+end

+ 26 - 0
dify.rb.template

@@ -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?
+    if Hardware::CPU.intel?
+      url "file://#{__dir__}/bin/dify-plugin-darwin-amd64.tar.gz"
+      sha256 "PLACEHOLDER_FOR_AMD64_CHECKSUM"
+    else
+      url "file://#{__dir__}/bin/dify-plugin-darwin-arm64.tar.gz"
+      sha256 "PLACEHOLDER_FOR_ARM64_CHECKSUM"
+    end
+  else
+    odie "This formula only supports macOS."
+  end
+
+  def install
+    bin.install "dify-plugin-darwin-#{Hardware::CPU.arch}" => "dify"
+  end
+
+  test do
+    assert_match version.to_s, shell_output("#{bin}/dify --version")
+  end
+end