Skip to content

Commit

Permalink
feat: add linux & windows
Browse files Browse the repository at this point in the history
  • Loading branch information
crazywoola committed Nov 29, 2024
1 parent 28880e1 commit d251679
Showing 1 changed file with 58 additions and 15 deletions.
73 changes: 58 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
all: update_formula

0 comments on commit d251679

Please sign in to comment.